Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix: fixed cloudflare token not working with services #581

Merged
merged 1 commit into from
Oct 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
bugfix: fixed cloudflare token not working with services
  • Loading branch information
Ice3man543 committed Oct 7, 2024
commit 5d072681e929882fdf7f5bd5339f9c8476ec8ed7
41 changes: 21 additions & 20 deletions pkg/providers/cloudflare/cloudflare.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,34 @@ type Provider struct {
// Here api_token overrides api_key
func New(options schema.OptionBlock) (*Provider, error) {
id, _ := options.GetMetadata("id")

supportedServicesMap := make(map[string]struct{})
for _, s := range Services {
supportedServicesMap[s] = struct{}{}
}

services := make(schema.ServiceMap)
if ss, ok := options.GetMetadata("services"); ok {
for _, s := range strings.Split(ss, ",") {
if _, ok := supportedServicesMap[s]; ok {
services[s] = struct{}{}
}
}
}
if len(services) == 0 {
for _, s := range Services {
services[s] = struct{}{}
}
}

apiToken, ok := options.GetMetadata(apiToken)
if ok {
// Construct a new API object with scoped api token
api, err := cloudflare.NewWithAPIToken(apiToken)
if err != nil {
return nil, err
}
return &Provider{id: id, client: api}, nil
return &Provider{id: id, client: api, services: services}, nil
}

accessKey, ok := options.GetMetadata(apiAccessKey)
Expand All @@ -46,25 +66,6 @@ func New(options schema.OptionBlock) (*Provider, error) {
return nil, err
}

supportedServicesMap := make(map[string]struct{})
for _, s := range Services {
supportedServicesMap[s] = struct{}{}
}

services := make(schema.ServiceMap)
if ss, ok := options.GetMetadata("services"); ok {
for _, s := range strings.Split(ss, ",") {
if _, ok := supportedServicesMap[s]; ok {
services[s] = struct{}{}
}
}
}
if len(services) == 0 {
for _, s := range Services {
services[s] = struct{}{}
}
}

return &Provider{id: id, client: api, services: services}, nil
}

Expand Down
Loading