Skip to content

Support processing env vars into Secret via libraries like envconfig #10

@andremarianiello

Description

@andremarianiello

I have a config struct with some regular fields and some secret fields, currently represented with string. I parse environment variables into this struct using https://github.com/kelseyhightower/envconfig. If I replace the secret string field with a logfusc.Secret[string], the parsing process no longer populates the field, presumably because it does not know how to decode strings from the environment into logfusc.Secret[string] structs. However, it would be very convenient if this worked like it does when unmarshalling JSON. Could this behavior be added? Ideally it would work for all generic logfusc.Secret[T], but simply supporting logfusc.Secret[string] first would be a big improvement.

This is what I am currently using to work around it

type SecretStringDecoder struct {                              
  logfusc.Secret[string]                                       
}                                                              
                                                               
func NewSecretStringDecoder(value string) SecretStringDecoder {
  return SecretStringDecoder{logfusc.NewSecret(value)}         
}                                                              
                                                               
func (d *SecretStringDecoder) Decode(value string) error {     
  *d = NewSecretStringDecoder(value)                           
  return nil                                                   
}                                                              

but this feels to me like it shouldn't be necessary. What do you think?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions