44 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			44 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| package config
 | |
| 
 | |
| import (
 | |
| 	"os"
 | |
| 
 | |
| 	"io/ioutil"
 | |
| 
 | |
| 	"gopkg.in/yaml.v3"
 | |
| )
 | |
| 
 | |
| type configFileStruct struct {
 | |
| 	AllowAdminNoMutate       bool       `yaml:"allow-admin-nomutate"`
 | |
| 	AllowAdminNoMutateToggle string     `yaml:"allow-admin-nomutate-toggle"`
 | |
| 	DockerhubRegistry        string     `yaml:"dockerhub-registry"`
 | |
| 	MutateIgnoredImages      []string   `yaml:"mutate-ignored-images"`
 | |
| 	CertificateAuthority     CertStruct `yaml:"certificate-authority"`
 | |
| 	Certificate              CertStruct `yaml:"certificate"`
 | |
| }
 | |
| 
 | |
| type CertStruct struct {
 | |
| 	Certificate string `yaml:"certificate"`
 | |
| 	PrivateKey  string `yaml:"private-key"`
 | |
| 	PublicKey   string `yaml:"public-key"`
 | |
| }
 | |
| 
 | |
| func getConfigFileData(fileLocation string) (configFileStruct, error) {
 | |
| 	// does file exist
 | |
| 	if _, err := os.Stat(fileLocation); os.IsNotExist(err) {
 | |
| 		return configFileStruct{}, err
 | |
| 	}
 | |
| 	// read file
 | |
| 	rd, err := ioutil.ReadFile(fileLocation)
 | |
| 	if err != nil {
 | |
| 		return configFileStruct{}, err
 | |
| 	}
 | |
| 	// convert config file data to struct
 | |
| 	var output configFileStruct
 | |
| 	if err := yaml.Unmarshal(rd, &output); err != nil {
 | |
| 		return output, err
 | |
| 	}
 | |
| 
 | |
| 	return output, nil
 | |
| }
 |