Skip to content

Commit 631079e

Browse files
Add --base-url flag for connector testability (#9)
* Add --base-url flag for connector testability This change adds a --base-url CLI flag to allow overriding the default API endpoint for testing purposes. When provided, the connector will use this URL instead of the hardcoded production API URL. This is part of the Connector Testability initiative to enable mock server testing without modifying connector code. Files changed: cmd/baton-fastly/main.go,pkg/config/conf.gen.go,pkg/config/config.go,pkg/connector/connector.go * Hide base-url field from hosted UI base-url is a dev/testing concern, not user-facing configuration. Mark it WithHidden(true) so it doesn't appear in the hosted UI. Good feedback from Geoff: ConductorOne/baton-trayai#63 (comment) * Add ExportTargetCLIOnly to base-url field Ref: ConductorOne/baton-prismhr#13 (comment)
1 parent 1048c99 commit 631079e

File tree

4 files changed

+18
-3
lines changed

4 files changed

+18
-3
lines changed

cmd/baton-fastly/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func getConnector(ctx context.Context, cc *cfg.Fastly) (types.ConnectorServer, e
4747
return nil, err
4848
}
4949

50-
cb, err := connector.New(ctx, cc.AccessToken)
50+
cb, err := connector.New(ctx, cc.AccessToken, cc.BaseUrl)
5151
if err != nil {
5252
l.Error("error creating connector", zap.Error(err))
5353
return nil, err

pkg/config/conf.gen.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/config/config.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ var (
1212
field.WithIsSecret(true),
1313
field.WithDisplayName("Access Token"),
1414
)
15+
BaseURLField = field.StringField(
16+
"base-url",
17+
field.WithDescription("Override the Fastly API URL (for testing)"),
18+
field.WithHidden(true),
19+
field.WithExportTarget(field.ExportTargetCLIOnly),
20+
)
1521

1622
// FieldRelationships defines relationships between the fields listed in
1723
// Config that can be automatically validated.
@@ -21,6 +27,7 @@ var (
2127
//go:generate go run ./gen
2228
var Config = field.NewConfiguration([]field.SchemaField{
2329
AccessToken,
30+
BaseURLField,
2431
})
2532

2633
// ValidateConfig is run after the configuration is loaded, and should return an

pkg/connector/connector.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,15 @@ func (d *Fastly) Validate(ctx context.Context) (annotations.Annotations, error)
4646
}
4747

4848
// New returns a new instance of the connector.
49-
func New(ctx context.Context, accessToken string) (*Fastly, error) {
50-
client, err := fastly.NewClient(accessToken)
49+
func New(ctx context.Context, accessToken, baseURL string) (*Fastly, error) {
50+
var client *fastly.Client
51+
var err error
52+
53+
if baseURL != "" {
54+
client, err = fastly.NewClientForEndpoint(accessToken, baseURL)
55+
} else {
56+
client, err = fastly.NewClient(accessToken)
57+
}
5158
if err != nil {
5259
return nil, err
5360
}

0 commit comments

Comments
 (0)