1
0
Fork 0
mirror of https://github.com/Luzifer/vault2env.git synced 2024-12-20 20:21:20 +00:00

Add predefined transform sets

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2018-01-18 21:17:19 +01:00
parent feef6dc09d
commit 5df6933f3e
Signed by: luzifer
GPG key ID: DC2729FDD34BE99E
2 changed files with 19 additions and 1 deletions

11
main.go
View file

@ -26,6 +26,7 @@ var (
Token string `flag:"vault-token" env:"VAULT_TOKEN" vardefault:"vault-token" description:"Specify a token to use instead of app-id auth"` Token string `flag:"vault-token" env:"VAULT_TOKEN" vardefault:"vault-token" description:"Specify a token to use instead of app-id auth"`
} }
Transform []string `flag:"transform,t" default:"" description:"Translates keys to different names (oldkey=newkey)"` Transform []string `flag:"transform,t" default:"" description:"Translates keys to different names (oldkey=newkey)"`
TransformSet []string `flag:"transform-set" default:"" description:"Apply predefined transform sets (Available: STS)"`
VaultAddress string `flag:"vault-addr" env:"VAULT_ADDR" default:"https://127.0.0.1:8200" description:"Vault API address"` VaultAddress string `flag:"vault-addr" env:"VAULT_ADDR" default:"https://127.0.0.1:8200" description:"Vault API address"`
VaultKeys []string `flag:"key,k" default:"" description:"Keys to read and use for environment variables"` VaultKeys []string `flag:"key,k" default:"" description:"Keys to read and use for environment variables"`
VersionAndExit bool `flag:"version" default:"false" description:"Print program version and exit"` VersionAndExit bool `flag:"version" default:"false" description:"Print program version and exit"`
@ -109,6 +110,14 @@ func main() {
} }
envData := map[string]string{} envData := map[string]string{}
for _, setName := range cfg.TransformSet {
if set, ok := transformSets[setName]; ok {
cfg.Transform = append(cfg.Transform, set...)
} else {
log.Warnf("Transform set %q was not found, ignoring", setName)
}
}
transformMap := env.ListToMap(cfg.Transform) transformMap := env.ListToMap(cfg.Transform)
for _, vaultKey := range cfg.VaultKeys { for _, vaultKey := range cfg.VaultKeys {
@ -143,7 +152,7 @@ func main() {
if cfg.Export { if cfg.Export {
for k, v := range envData { for k, v := range envData {
fmt.Printf("export %s=\"%s\"\n", k, v) fmt.Printf("export %s=%q\n", k, v)
} }
return return
} }

9
transform_sets.go Normal file
View file

@ -0,0 +1,9 @@
package main
var transformSets = map[string][]string{
"STS": []string{
"access_key=AWS_ACCESS_KEY_ID",
"secret_key=AWS_SECRET_ACCESS_KEY",
"security_token=AWS_SECURITY_TOKEN",
},
}