Skip to content

Commit

Permalink
Allow for DNSimple User API tokens to be used by implementing the DNS…
Browse files Browse the repository at this point in the history
…IMPLE_ACCOUNT_ID and DNSIMPLE_ZONES environment variables

Small refactoring to NewDnsimpleProvider function to improve its testability
  • Loading branch information
IntegralProgrammer committed Feb 26, 2024
1 parent d0c121b commit d475eb6
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions provider/dnsimple/dnsimple.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ const (

// NewDnsimpleProvider initializes a new Dnsimple based provider
func NewDnsimpleProvider(domainFilter endpoint.DomainFilter, zoneIDFilter provider.ZoneIDFilter, dryRun bool) (provider.Provider, error) {
return BuildDnsimpleProvider(domainFilter, zoneIDFilter, dryRun, false)
}

// Create a new Dnsimple based provider but return a *dnsimpleProvider and allow for the call to provider.identity.Whoami to be bypassed - both for testing purposes
func BuildDnsimpleProvider(domainFilter endpoint.DomainFilter, zoneIDFilter provider.ZoneIDFilter, dryRun bool, skipWhoami bool) (*dnsimpleProvider, error) {
oauthToken := os.Getenv("DNSIMPLE_OAUTH")
dnsimpleAccountId := os.Getenv("DNSIMPLE_ACCOUNT_ID")
if len(oauthToken) == 0 {
Expand All @@ -119,10 +124,15 @@ func NewDnsimpleProvider(domainFilter endpoint.DomainFilter, zoneIDFilter provid
dryRun: dryRun,
}

whoamiResponse, err := provider.identity.Whoami(context.Background())
if err != nil {
return nil, err
whoamiResponse := &dnsimple.WhoamiResponse{}
if skipWhoami == false {
var err error
whoamiResponse, err = provider.identity.Whoami(context.Background())
if err != nil {
return nil, err
}
}

if dnsimpleAccountId == "" {
provider.accountID = int64ToString(whoamiResponse.Data.Account.ID)
} else {
Expand Down

0 comments on commit d475eb6

Please sign in to comment.