Compare commits
2 Commits
ff75f4bbcd
...
02bc040e2a
Author | SHA1 | Date | |
---|---|---|---|
02bc040e2a | |||
9f1f36215a |
145
pkg/backy/allowedexternaldirectives_enumer.go
Normal file
145
pkg/backy/allowedexternaldirectives_enumer.go
Normal file
@ -0,0 +1,145 @@
|
||||
// Code generated by "enumer -linecomment -yaml -text -json -type=AllowedExternalDirectives"; DO NOT EDIT.
|
||||
|
||||
package backy
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const _AllowedExternalDirectivesName = "DefaultExternalDirvaultvault-filevault-file-envfile-envfileenv"
|
||||
|
||||
var _AllowedExternalDirectivesIndex = [...]uint8{0, 18, 23, 33, 47, 55, 59, 62}
|
||||
|
||||
const _AllowedExternalDirectivesLowerName = "defaultexternaldirvaultvault-filevault-file-envfile-envfileenv"
|
||||
|
||||
func (i AllowedExternalDirectives) String() string {
|
||||
if i < 0 || i >= AllowedExternalDirectives(len(_AllowedExternalDirectivesIndex)-1) {
|
||||
return fmt.Sprintf("AllowedExternalDirectives(%d)", i)
|
||||
}
|
||||
return _AllowedExternalDirectivesName[_AllowedExternalDirectivesIndex[i]:_AllowedExternalDirectivesIndex[i+1]]
|
||||
}
|
||||
|
||||
// An "invalid array index" compiler error signifies that the constant values have changed.
|
||||
// Re-run the stringer command to generate them again.
|
||||
func _AllowedExternalDirectivesNoOp() {
|
||||
var x [1]struct{}
|
||||
_ = x[DefaultExternalDir-(0)]
|
||||
_ = x[AllowedExternalDirectiveVault-(1)]
|
||||
_ = x[AllowedExternalDirectiveVaultFile-(2)]
|
||||
_ = x[AllowedExternalDirectiveAll-(3)]
|
||||
_ = x[AllowedExternalDirectiveFileEnv-(4)]
|
||||
_ = x[AllowedExternalDirectiveFile-(5)]
|
||||
_ = x[AllowedExternalDirectiveEnv-(6)]
|
||||
}
|
||||
|
||||
var _AllowedExternalDirectivesValues = []AllowedExternalDirectives{DefaultExternalDir, AllowedExternalDirectiveVault, AllowedExternalDirectiveVaultFile, AllowedExternalDirectiveAll, AllowedExternalDirectiveFileEnv, AllowedExternalDirectiveFile, AllowedExternalDirectiveEnv}
|
||||
|
||||
var _AllowedExternalDirectivesNameToValueMap = map[string]AllowedExternalDirectives{
|
||||
_AllowedExternalDirectivesName[0:18]: DefaultExternalDir,
|
||||
_AllowedExternalDirectivesLowerName[0:18]: DefaultExternalDir,
|
||||
_AllowedExternalDirectivesName[18:23]: AllowedExternalDirectiveVault,
|
||||
_AllowedExternalDirectivesLowerName[18:23]: AllowedExternalDirectiveVault,
|
||||
_AllowedExternalDirectivesName[23:33]: AllowedExternalDirectiveVaultFile,
|
||||
_AllowedExternalDirectivesLowerName[23:33]: AllowedExternalDirectiveVaultFile,
|
||||
_AllowedExternalDirectivesName[33:47]: AllowedExternalDirectiveAll,
|
||||
_AllowedExternalDirectivesLowerName[33:47]: AllowedExternalDirectiveAll,
|
||||
_AllowedExternalDirectivesName[47:55]: AllowedExternalDirectiveFileEnv,
|
||||
_AllowedExternalDirectivesLowerName[47:55]: AllowedExternalDirectiveFileEnv,
|
||||
_AllowedExternalDirectivesName[55:59]: AllowedExternalDirectiveFile,
|
||||
_AllowedExternalDirectivesLowerName[55:59]: AllowedExternalDirectiveFile,
|
||||
_AllowedExternalDirectivesName[59:62]: AllowedExternalDirectiveEnv,
|
||||
_AllowedExternalDirectivesLowerName[59:62]: AllowedExternalDirectiveEnv,
|
||||
}
|
||||
|
||||
var _AllowedExternalDirectivesNames = []string{
|
||||
_AllowedExternalDirectivesName[0:18],
|
||||
_AllowedExternalDirectivesName[18:23],
|
||||
_AllowedExternalDirectivesName[23:33],
|
||||
_AllowedExternalDirectivesName[33:47],
|
||||
_AllowedExternalDirectivesName[47:55],
|
||||
_AllowedExternalDirectivesName[55:59],
|
||||
_AllowedExternalDirectivesName[59:62],
|
||||
}
|
||||
|
||||
// AllowedExternalDirectivesString retrieves an enum value from the enum constants string name.
|
||||
// Throws an error if the param is not part of the enum.
|
||||
func AllowedExternalDirectivesString(s string) (AllowedExternalDirectives, error) {
|
||||
if val, ok := _AllowedExternalDirectivesNameToValueMap[s]; ok {
|
||||
return val, nil
|
||||
}
|
||||
|
||||
if val, ok := _AllowedExternalDirectivesNameToValueMap[strings.ToLower(s)]; ok {
|
||||
return val, nil
|
||||
}
|
||||
return 0, fmt.Errorf("%s does not belong to AllowedExternalDirectives values", s)
|
||||
}
|
||||
|
||||
// AllowedExternalDirectivesValues returns all values of the enum
|
||||
func AllowedExternalDirectivesValues() []AllowedExternalDirectives {
|
||||
return _AllowedExternalDirectivesValues
|
||||
}
|
||||
|
||||
// AllowedExternalDirectivesStrings returns a slice of all String values of the enum
|
||||
func AllowedExternalDirectivesStrings() []string {
|
||||
strs := make([]string, len(_AllowedExternalDirectivesNames))
|
||||
copy(strs, _AllowedExternalDirectivesNames)
|
||||
return strs
|
||||
}
|
||||
|
||||
// IsAAllowedExternalDirectives returns "true" if the value is listed in the enum definition. "false" otherwise
|
||||
func (i AllowedExternalDirectives) IsAAllowedExternalDirectives() bool {
|
||||
for _, v := range _AllowedExternalDirectivesValues {
|
||||
if i == v {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// MarshalJSON implements the json.Marshaler interface for AllowedExternalDirectives
|
||||
func (i AllowedExternalDirectives) MarshalJSON() ([]byte, error) {
|
||||
return json.Marshal(i.String())
|
||||
}
|
||||
|
||||
// UnmarshalJSON implements the json.Unmarshaler interface for AllowedExternalDirectives
|
||||
func (i *AllowedExternalDirectives) UnmarshalJSON(data []byte) error {
|
||||
var s string
|
||||
if err := json.Unmarshal(data, &s); err != nil {
|
||||
return fmt.Errorf("AllowedExternalDirectives should be a string, got %s", data)
|
||||
}
|
||||
|
||||
var err error
|
||||
*i, err = AllowedExternalDirectivesString(s)
|
||||
return err
|
||||
}
|
||||
|
||||
// MarshalText implements the encoding.TextMarshaler interface for AllowedExternalDirectives
|
||||
func (i AllowedExternalDirectives) MarshalText() ([]byte, error) {
|
||||
return []byte(i.String()), nil
|
||||
}
|
||||
|
||||
// UnmarshalText implements the encoding.TextUnmarshaler interface for AllowedExternalDirectives
|
||||
func (i *AllowedExternalDirectives) UnmarshalText(text []byte) error {
|
||||
var err error
|
||||
*i, err = AllowedExternalDirectivesString(string(text))
|
||||
return err
|
||||
}
|
||||
|
||||
// MarshalYAML implements a YAML Marshaler for AllowedExternalDirectives
|
||||
func (i AllowedExternalDirectives) MarshalYAML() (interface{}, error) {
|
||||
return i.String(), nil
|
||||
}
|
||||
|
||||
// UnmarshalYAML implements a YAML Unmarshaler for AllowedExternalDirectives
|
||||
func (i *AllowedExternalDirectives) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
||||
var s string
|
||||
if err := unmarshal(&s); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var err error
|
||||
*i, err = AllowedExternalDirectivesString(s)
|
||||
return err
|
||||
}
|
@ -537,6 +537,12 @@ func logCommandOutput(command *Command, cmdOutBuf bytes.Buffer, cmdCtxLogger zer
|
||||
return outputArr
|
||||
}
|
||||
|
||||
func (c *Command) GetVariablesFromConf(opts *ConfigOpts) {
|
||||
c.ScriptEnvFile = replaceVarInString(opts.Vars, c.ScriptEnvFile, opts.Logger)
|
||||
c.Name = replaceVarInString(opts.Vars, c.Name, opts.Logger)
|
||||
c.OutputFile = replaceVarInString(opts.Vars, c.OutputFile, opts.Logger)
|
||||
}
|
||||
|
||||
// func executeUserCommands() []string {
|
||||
|
||||
// }
|
||||
|
@ -104,7 +104,7 @@ func (opts *ConfigOpts) ReadConfig() *ConfigOpts {
|
||||
backyKoanf := opts.koanf
|
||||
|
||||
if backyKoanf.Exists("variables") {
|
||||
unmarshalConfig(backyKoanf, "variables", &opts.Vars, opts.Logger)
|
||||
unmarshalConfigIntoStruct(backyKoanf, "variables", &opts.Vars, opts.Logger)
|
||||
}
|
||||
|
||||
getConfigDir(opts)
|
||||
@ -131,15 +131,15 @@ func (opts *ConfigOpts) ReadConfig() *ConfigOpts {
|
||||
|
||||
log.Info().Str("config file", opts.ConfigFilePath).Send()
|
||||
|
||||
if err := opts.setupVault(); err != nil {
|
||||
if err := opts.initVault(); err != nil {
|
||||
log.Err(err).Send()
|
||||
}
|
||||
|
||||
unmarshalConfig(backyKoanf, "commands", &opts.Cmds, opts.Logger)
|
||||
unmarshalConfigIntoStruct(backyKoanf, "commands", &opts.Cmds, opts.Logger)
|
||||
|
||||
getCommandEnvironments(opts)
|
||||
|
||||
unmarshalConfig(backyKoanf, "hosts", &opts.Hosts, opts.Logger)
|
||||
unmarshalConfigIntoStruct(backyKoanf, "hosts", &opts.Hosts, opts.Logger)
|
||||
|
||||
resolveHostConfigs(opts)
|
||||
|
||||
@ -163,7 +163,7 @@ func (opts *ConfigOpts) ReadConfig() *ConfigOpts {
|
||||
filterExecuteLists(opts)
|
||||
|
||||
if backyKoanf.Exists("notifications") {
|
||||
unmarshalConfig(backyKoanf, "notifications", &opts.NotificationConf, opts.Logger)
|
||||
unmarshalConfigIntoStruct(backyKoanf, "notifications", &opts.NotificationConf, opts.Logger)
|
||||
}
|
||||
|
||||
opts.SetupNotify()
|
||||
@ -251,7 +251,7 @@ func setupLogger(opts *ConfigOpts) zerolog.Logger {
|
||||
return zerolog.New(writers).With().Timestamp().Logger()
|
||||
}
|
||||
|
||||
func unmarshalConfig(k *koanf.Koanf, key string, target interface{}, log zerolog.Logger) {
|
||||
func unmarshalConfigIntoStruct(k *koanf.Koanf, key string, target interface{}, log zerolog.Logger) {
|
||||
if err := k.UnmarshalWithConf(key, target, koanf.UnmarshalConf{Tag: "yaml"}); err != nil {
|
||||
logging.ExitWithMSG(fmt.Sprintf("error unmarshaling key %s into struct: %v", key, err), 1, &log)
|
||||
}
|
||||
@ -331,7 +331,7 @@ func loadCommandLists(opts *ConfigOpts, backyKoanf *koanf.Koanf) {
|
||||
if backyKoanf.Exists("cmdLists.file") {
|
||||
loadCmdListsFile(backyKoanf, listsConfig, opts)
|
||||
} else {
|
||||
unmarshalConfig(backyKoanf, "cmdLists", &opts.CmdConfigLists, opts.Logger)
|
||||
unmarshalConfigIntoStruct(backyKoanf, "cmdLists", &opts.CmdConfigLists, opts.Logger)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -371,7 +371,7 @@ func loadListConfigFile(filePath string, k *koanf.Koanf, opts *ConfigOpts) bool
|
||||
return false
|
||||
}
|
||||
|
||||
unmarshalConfig(k, "cmdLists", &opts.CmdConfigLists, opts.Logger)
|
||||
unmarshalConfigIntoStruct(k, "cmdLists", &opts.CmdConfigLists, opts.Logger)
|
||||
keyNotSupported("cmd-lists", "cmdLists", k, opts, true)
|
||||
opts.CmdListFile = filePath
|
||||
return true
|
||||
@ -399,7 +399,7 @@ func loadCmdListsFile(backyKoanf *koanf.Koanf, listsConfig *koanf.Koanf, opts *C
|
||||
}
|
||||
|
||||
keyNotSupported("cmd-lists", "cmdLists", listsConfig, opts, true)
|
||||
unmarshalConfig(listsConfig, "cmdLists", &opts.CmdConfigLists, opts.Logger)
|
||||
unmarshalConfigIntoStruct(listsConfig, "cmdLists", &opts.CmdConfigLists, opts.Logger)
|
||||
opts.Logger.Info().Str("using lists config file", opts.CmdListFile).Send()
|
||||
}
|
||||
|
||||
@ -456,7 +456,7 @@ func getLoggingKeyFromConfig(key string) string {
|
||||
// return fmt.Sprintf("cmdLists.%s", list)
|
||||
// }
|
||||
|
||||
func (opts *ConfigOpts) setupVault() error {
|
||||
func (opts *ConfigOpts) initVault() error {
|
||||
if !opts.koanf.Bool("vault.enabled") {
|
||||
return nil
|
||||
}
|
||||
@ -477,7 +477,7 @@ func (opts *ConfigOpts) setupVault() error {
|
||||
token = os.Getenv("VAULT_TOKEN")
|
||||
}
|
||||
if strings.TrimSpace(token) == "" {
|
||||
return fmt.Errorf("no token found, but one was required. \n\nSet the config key vault.token or the environment variable VAULT_TOKEN")
|
||||
return fmt.Errorf("no token found. One is required. \n\nSet the config key vault.token or the environment variable VAULT_TOKEN")
|
||||
}
|
||||
|
||||
client.SetToken(token)
|
||||
@ -489,6 +489,11 @@ func (opts *ConfigOpts) setupVault() error {
|
||||
|
||||
opts.vaultClient = client
|
||||
|
||||
for _, v := range opts.VaultKeys {
|
||||
v.Name = replaceVarInString(opts.Vars, v.Key, opts.Logger)
|
||||
v.MountPath = replaceVarInString(opts.Vars, v.MountPath, opts.Logger)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -728,3 +733,9 @@ func replaceVarInString(vars map[string]string, str string, logger zerolog.Logge
|
||||
}
|
||||
return str
|
||||
}
|
||||
|
||||
func VariadicFunctionParameterTest(allowedKeys ...string) {
|
||||
if contains(allowedKeys, "file") {
|
||||
println("file param included")
|
||||
}
|
||||
}
|
||||
|
@ -278,8 +278,9 @@ type (
|
||||
}
|
||||
|
||||
// use ints so we can use enums
|
||||
CommandType int
|
||||
PackageOperation int
|
||||
CommandType int
|
||||
PackageOperation int
|
||||
AllowedExternalDirectives int
|
||||
)
|
||||
|
||||
//go:generate go run github.com/dmarkham/enumer -linecomment -yaml -text -json -type=CommandType
|
||||
@ -302,3 +303,14 @@ const (
|
||||
PackOpCheckVersion // checkVersion
|
||||
PackOpIsInstalled // isInstalled
|
||||
)
|
||||
|
||||
//go:generate go run github.com/dmarkham/enumer -linecomment -yaml -text -json -type=AllowedExternalDirectives
|
||||
const (
|
||||
DefaultExternalDir AllowedExternalDirectives = iota
|
||||
AllowedExternalDirectiveVault // vault
|
||||
AllowedExternalDirectiveVaultFile // vault-file
|
||||
AllowedExternalDirectiveAll // vault-file-env
|
||||
AllowedExternalDirectiveFileEnv // file-env
|
||||
AllowedExternalDirectiveFile // file
|
||||
AllowedExternalDirectiveEnv // env
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user