-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Problem Statement
I load some configs from json/yaml files while secrets are loaded with secretfetch. The issue is I can't do this as secretfetch expects every field in the destination struct to have a valid tag, it returns the error "invalid tag for field Env: no secret tag found for field NonSecretValue"
This won't work
type Config struct {
NonSecretValue string `yaml:"noSecretValue"`
SecretValue string `secret:"aws=prefix/my-secret,env=SECRET_VALUE"`
}
The same happens with nested structs:
type Config struct {
// This won't load as `API` struct does not have the `secret` tag
API struct {
AdminUser string `secret:"aws=prefix/user,env=API_ADMIN_USER"`
AdminPassword string `secret:"aws=prefix/pass,env=API_ADMIN_PASS"`
}
}
Proposed Solution
It would be nice if I could just tell secretfetch to ignore fields without the secret tag (or make it the default behavior).
Alternative Solutions
To make this work right now I need to create another struct that has all the secrets and then assign them to my Config struct.
Example Usage
type Config struct {
SecretValue string `secret:"aws=prefix/my-secret,env=SECRET_VALUE"`
NonSecretValue string `yaml:"noSecretValue"`
API struct {
AdminUser string `secret:"aws=prefix/user,env=API_ADMIN_USER"`
AdminPassword string `secret:"aws=prefix/pass,env=API_ADMIN_PASS"`
}
}
var cfg Config
// Read yaml config file
yaml.Unmarshal([]byte(data), &cfg)
// Read secrets, this will only load fields with the "secret" tag even if inside
// a nested struct without a tag. Other fields won't be changed.
secretfetch.Fetch(context.Background(), cfg, nil)Benefits
A single and easy-to-use struct can be used to load non-secret values and secrets with secretfetch
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request