Skip to content
Open
Show file tree
Hide file tree
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
7 changes: 7 additions & 0 deletions cmd/baton-cloudflare-zero-trust/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,18 @@ var (
"email",
field.WithDescription("Cloudflare account email"),
)
baseURLField = field.StringField(
"base-url",
field.WithDescription("Override the Cloudflare API URL (for testing)"),
field.WithHidden(true),
field.WithExportTarget(field.ExportTargetCLIOnly),
)
configurationFields = []field.SchemaField{
accountIdField,
apiKeyField,
apiTokenField,
emailField,
baseURLField,
}
fieldRelationships = []field.SchemaFieldRelationship{
field.FieldsAtLeastOneUsed(apiTokenField, apiKeyField),
Expand Down
1 change: 1 addition & 0 deletions cmd/baton-cloudflare-zero-trust/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func getConnector(ctx context.Context, cfg *viper.Viper) (types.ConnectorServer,
cfg.GetString(apiTokenField.FieldName),
cfg.GetString(apiKeyField.FieldName),
cfg.GetString(emailField.FieldName),
cfg.GetString(baseURLField.FieldName),
)
if err != nil {
l.Error("error creating connector", zap.Error(err))
Expand Down
12 changes: 9 additions & 3 deletions pkg/connector/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,23 @@ func (d *Connector) Validate(ctx context.Context) (annotations.Annotations, erro
}

// New returns a new instance of the connector.
func New(ctx context.Context, accountId, apiToken, apiKey, email string) (*Connector, error) {
func New(ctx context.Context, accountId, apiToken, apiKey, email, baseURL string) (*Connector, error) {
var (
client *cloudflare.API
err error
)

var opts []cloudflare.Option
if baseURL != "" {
opts = append(opts, cloudflare.BaseURL(baseURL))
}

if apiKey != "" && email != "" {
client, err = cloudflare.New(apiKey, email)
client, err = cloudflare.New(apiKey, email, opts...)
}

if apiToken != "" {
client, err = cloudflare.NewWithAPIToken(apiToken)
client, err = cloudflare.NewWithAPIToken(apiToken, opts...)
}

if err != nil {
Expand Down
Loading