From c98dd2908227304bf5bc68848be806a775cc00c3 Mon Sep 17 00:00:00 2001 From: Integralist Date: Wed, 15 Nov 2023 15:33:25 +0000 Subject: [PATCH] fix(app): allow config override for account endpoint --- pkg/app/run.go | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/pkg/app/run.go b/pkg/app/run.go index 16dda60e2..8a0b1df4d 100644 --- a/pkg/app/run.go +++ b/pkg/app/run.go @@ -107,7 +107,7 @@ var Init = func(args []string, stdin io.Reader) (*global.Data, error) { _ = md.File.Read(manifest.Filename) // Configure authentication inputs. - metadataEndpoint := fmt.Sprintf(auth.OIDCMetadata, accountEndpoint(args, e)) + metadataEndpoint := fmt.Sprintf(auth.OIDCMetadata, accountEndpoint(args, e, cfg)) req, err := http.NewRequest(http.MethodGet, metadataEndpoint, nil) if err != nil { return nil, fmt.Errorf("failed to construct request object for OpenID Connect .well-known metadata: %w", err) @@ -195,17 +195,23 @@ var Init = func(args []string, stdin io.Reader) (*global.Data, error) { }, nil } -// accountEndpoint parses the account endpoint from either the environment or -// the input arguments otherwise returns the default. -func accountEndpoint(args []string, e config.Environment) string { - if e.AccountEndpoint != "" { - return e.AccountEndpoint - } +// accountEndpoint parses the account endpoint from multiple locations. +func accountEndpoint(args []string, e config.Environment, cfg config.File) string { + // Check for flag override. for i, a := range args { if a == "--account" && i+1 < len(args) { return args[i+1] } } + // Check for environment override. + if e.AccountEndpoint != "" { + return e.AccountEndpoint + } + // Check for internal config override. + if cfg.Fastly.AccountEndpoint != global.DefaultAccountEndpoint && cfg.Fastly.AccountEndpoint != "" { + return cfg.Fastly.AccountEndpoint + } + // Otherwise return the default account endpoint. return global.DefaultAccountEndpoint }