getvaultpw/internal/config/configFile.go
2022-11-16 17:50:30 -06:00

44 lines
1.0 KiB
Go

package config
import (
"log"
"os"
"gopkg.in/yaml.v2"
)
type ConfigFileStruct struct {
Salt string `yaml:"salt"`
VaultEnvironment map[string]*VaultEnvStruct `yaml:"vaultEnvironment"`
Credential map[string]*CredentialStruct `yaml:"credentials"`
}
type VaultEnvStruct struct {
Host string `yaml:"host"`
User string `yaml:"user"`
EPass string `yaml:"encryptedPassword"`
}
type CredentialStruct struct {
Path string `yaml:"vaultPath"`
ID string `yaml:"vaultID"`
TimeStamp int64 `yaml:"timestamp"`
Cache string `yaml:"cachedValue"`
VaultEnv string `yaml:"vaultInstance"`
}
func (cfg *Config) WriteConfig(dest string) error {
file, err := os.OpenFile(dest, os.O_WRONLY, 0600)
if err != nil {
log.Fatalf("[ERROR] Unable to open the config file %s: %v", dest, err)
}
defer file.Close()
data, _ := yaml.Marshal(cfg.ConfigFileData)
if _, err = file.Write(data); err != nil {
log.Fatalf("[ERROR] Unable to update config file %s: %v", cfg.ConfigFile, err)
}
return nil
}