Skip to content

Commit 8dc2c05

Browse files
committed
Merge pull request #31 in FEE/akamaiopen-edgegrid-golang from TFP-168-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
2 parents 133826b + ed89b39 commit 8dc2c05

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

pkg/edgegrid/config.go

+8-6
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ type (
5959
// New returns new configuration with the specified options
6060
func New(opts ...Option) (*Config, error) {
6161
c := &Config{
62-
file: DefaultConfigFile,
6362
section: DefaultSection,
6463
env: false,
6564
}
@@ -69,14 +68,17 @@ func New(opts ...Option) (*Config, error) {
6968
}
7069

7170
if c.env {
72-
if err := c.FromEnv(c.section); err != nil {
73-
return c, err
71+
if err := c.FromEnv(c.section); err == nil {
72+
return c, nil
73+
} else if !errors.Is(err, ErrRequiredOptionEnv) {
74+
return nil, err
7475
}
75-
return c, nil
7676
}
7777

78-
if err := c.FromFile(c.file, c.section); err != nil {
79-
return c, fmt.Errorf("unable to load config from environment or .edgerc file: %w", err)
78+
if c.file != "" {
79+
if err := c.FromFile(c.file, c.section); err != nil {
80+
return c, fmt.Errorf("unable to load config from environment or .edgerc file: %w", err)
81+
}
8082
}
8183

8284
return c, nil

0 commit comments

Comments
 (0)