Skip to content

Commit

Permalink
Merge pull request #31 in FEE/akamaiopen-edgegrid-golang from TFP-168…
Browse files Browse the repository at this point in the history
…-add-env-fallback to v2

* commit 'ed89b39bf9779c795b4e90e96e18aa02534682e2':
  make edgerc.WithEnv explicit fallback to files so existing provider use does not break
  make edgerc.WithEnv fallback to files so existing provider use does not break
  make edgerc.WithEnv fallback to files so existing provider use does not break
  • Loading branch information
piotrpio committed Sep 24, 2020
2 parents 133826b + ed89b39 commit 8dc2c05
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions pkg/edgegrid/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ type (
// New returns new configuration with the specified options
func New(opts ...Option) (*Config, error) {
c := &Config{
file: DefaultConfigFile,
section: DefaultSection,
env: false,
}
Expand All @@ -69,14 +68,17 @@ func New(opts ...Option) (*Config, error) {
}

if c.env {
if err := c.FromEnv(c.section); err != nil {
return c, err
if err := c.FromEnv(c.section); err == nil {
return c, nil
} else if !errors.Is(err, ErrRequiredOptionEnv) {
return nil, err
}
return c, nil
}

if err := c.FromFile(c.file, c.section); err != nil {
return c, fmt.Errorf("unable to load config from environment or .edgerc file: %w", err)
if c.file != "" {
if err := c.FromFile(c.file, c.section); err != nil {
return c, fmt.Errorf("unable to load config from environment or .edgerc file: %w", err)
}
}

return c, nil
Expand Down

0 comments on commit 8dc2c05

Please sign in to comment.