Skip to content

Commit

Permalink
internal: handle explicitly provided credentials
Browse files Browse the repository at this point in the history
Closes #790

Signed-off-by: Jacob Bednarz <[email protected]>
  • Loading branch information
jacobbednarz committed Feb 3, 2025
1 parent 37e5f39 commit 69ac24f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions internal/app/cf-terraforming/cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

cfv0 "github.com/cloudflare/cloudflare-go"
"github.com/cloudflare/cloudflare-go/v4"
"github.com/cloudflare/cloudflare-go/v4/option"
"github.com/hashicorp/go-version"
"github.com/hashicorp/hc-install/product"
"github.com/hashicorp/hc-install/releases"
Expand Down Expand Up @@ -149,6 +150,11 @@ func generateResources() func(cmd *cobra.Command, args []string) {
endpoint = placeholderReplacer.Replace(endpoint)

client := cloudflare.NewClient()
if apiToken != "" {
client.Options = append(client.Options, option.WithAPIToken(apiToken))
} else {
client.Options = append(client.Options, option.WithAPIKey(apiKey), option.WithAPIEmail(apiEmail))
}

err := client.Get(context.Background(), endpoint, nil, &result)
if err != nil {
Expand Down
6 changes: 6 additions & 0 deletions internal/app/cf-terraforming/cmd/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (

cfv0 "github.com/cloudflare/cloudflare-go"
"github.com/cloudflare/cloudflare-go/v4"
"github.com/cloudflare/cloudflare-go/v4/option"
"github.com/hashicorp/go-version"
"github.com/hashicorp/hc-install/product"
"github.com/hashicorp/hc-install/releases"
Expand Down Expand Up @@ -169,6 +170,11 @@ func runImport() func(cmd *cobra.Command, args []string) {
}

client := cloudflare.NewClient()
if apiToken != "" {
client.Options = append(client.Options, option.WithAPIToken(apiToken))
} else {
client.Options = append(client.Options, option.WithAPIKey(apiKey), option.WithAPIEmail(apiEmail))
}

err := client.Get(context.Background(), endpoint, nil, &result)
if err != nil {
Expand Down

0 comments on commit 69ac24f

Please sign in to comment.