Skip to content

Commit

Permalink
Check that environment variables are provided (#24)
Browse files Browse the repository at this point in the history
If configuration settings aren't provided via the Corefile, raise an error if they also aren't provided via environment variables.
  • Loading branch information
DXTimer committed Jan 18, 2024
1 parent 05f82b5 commit b1e67bd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
8 changes: 8 additions & 0 deletions setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,18 @@ func setup(c *caddy.Controller) error {
// Keep this environment variable name consistent across all our integrations (e.g. SDKs, Terraform provider).
accessToken = os.Getenv("DNSIMPLE_TOKEN")
}
// Still blank, return error
if accessToken == "" {
return plugin.Error("dnsimple", c.Err("access token must be provided via the Corefile or DNSIMPLE_TOKEN environment variable"))
}

if opts.accountId == "" {
opts.accountId = os.Getenv("DNSIMPLE_ACCOUNT_ID")
}
// Still blank, return error
if opts.accountId == "" {
return plugin.Error("dnsimple", c.Err("account ID must be provided via the Corefile or DNSIMPLE_TOKEN environment variable"))
}

if baseUrl == "" {
// Default to production
Expand Down
3 changes: 3 additions & 0 deletions setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import (
)

func TestSetupDNSimple(t *testing.T) {
t.Setenv("DNSIMPLE_TOKEN", "token")
t.Setenv("DNSIMPLE_ACCOUNT_ID", "12345")

fakeClient := new(fakeDNSimpleClient)
newDnsimpleService = func(ctx context.Context, options Options, accessToken, baseUrl string) (dnsimpleService, error) {
return fakeClient, nil
Expand Down

0 comments on commit b1e67bd

Please sign in to comment.