Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Allowing comma-separated slices in ATHENS_GO_BINARY_ENV_VARS #1505

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,37 @@ func (el *EnvList) Add(key, value string) {
*el = append(*el, key+"="+value)
}

// Decode implements envconfig.Decoder. Please see the below link for more information on
// that interface:
//
// https://github.com/kelseyhightower/envconfig#custom-decoders
//
// We are doing this to allow for very long lists of assignments to be set inside of
// a single environment variable. For example:
//
// ATHENS_GO_BINARY_ENV_VARS="GOPRIVATE=*.corp.example.com,rsc.io/private;GOPROXY=direct"
//
// See the below link for more information:
// https://github.com/gomods/athens/issues/1404
func (el *EnvList) Decode(value string) error {
const op errors.Op = "envList.Decode"
assignments := strings.Split(value, ";")
fmt.Printf("%s assignments = %#v\n", op, assignments)
fmt.Printf("envlist: %#v\n", *el)
for _, assignment := range assignments {
kv := strings.Split(assignment, "=")
if len(kv) != 2 {
return errors.E(
op,
errors.KindBadRequest,
fmt.Errorf("environment variable assignment %s is invalid", assignment),
)
}
el.Add(kv[0], kv[1])
}
return nil
}

// Validate validates that all strings inside the
// list are of the key=value format
func (el EnvList) Validate() error {
Expand Down