Skip to content

Add --base-url flag for connector testability#11

Open
robert-chiniquy wants to merge 3 commits intomainfrom
rch/testability/fix-base-url
Open

Add --base-url flag for connector testability#11
robert-chiniquy wants to merge 3 commits intomainfrom
rch/testability/fix-base-url

Conversation

@robert-chiniquy
Copy link

@robert-chiniquy robert-chiniquy commented Feb 8, 2026

Summary

Adds the --base-url CLI flag to enable overriding the default API endpoint for testing purposes.

Changes

  • Added BaseURLField to configuration
  • Updated client/connector to accept and use the base URL override
  • When --base-url is provided, it takes precedence over the default API URL

Files Modified

cmd/baton-box/main.go,pkg/box/client.go,pkg/config/conf.gen.go,pkg/config/config.go,pkg/connector/connector.go

Testing

The connector can now be tested against mock servers:

baton-box --base-url http://localhost:8080 [other-flags]

Related

Part of the Connector Testability initiative.

Summary by CodeRabbit

  • New Features
    • Added support for configurable Box API base URL
    • Users can now override the default API endpoint through configuration settings
    • Default endpoint behavior is preserved when no custom URL is specified

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-box/main.go,pkg/box/client.go,pkg/config/conf.gen.go,pkg/config/config.go,pkg/connector/connector.go
@robert-chiniquy robert-chiniquy requested a review from a team February 8, 2026 07:42
@coderabbitai
Copy link

coderabbitai bot commented Feb 8, 2026

Warning

Rate limit exceeded

@robert-chiniquy has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 5 minutes and 57 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

Walkthrough

This change introduces a configurable baseURL parameter throughout the Box client stack, allowing callers to override the Box API endpoint. The parameter is plumbed from the configuration system through the connector to the client and token request functions.

Changes

Cohort / File(s) Summary
Box Client Core
pkg/box/client.go
Added baseURL field to Client struct. Updated NewClient to accept and initialize baseURL parameter with defaultBaseURL fallback. Modified RequestAccessToken to accept baseURL parameter and use it for token endpoint construction.
Configuration
pkg/config/conf.gen.go, pkg/config/config.go
Added BaseUrl field to generated Box configuration struct with mapstructure tag. Added BaseURLField configuration field definition with description for overriding Box API URL.
Connector Integration
pkg/connector/connector.go
Updated New function signature to accept baseURL parameter and propagate it to box.RequestAccessToken and box.NewClient calls.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 A URL, flexible and bright,
No longer locked in place so tight,
Through config flows it gently spreads,
To clients, connectors—all comrades,
Now Box bows to custom threads! 📦✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and specifically describes the primary change: adding a --base-url flag to improve connector testability.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch rch/testability/fix-base-url

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
pkg/box/client.go (1)

48-80: ⚠️ Potential issue | 🟡 Minor

Normalize baseURL to prevent malformed URL concatenation.

baseURL is concatenated directly with path segments in multiple locations (lines 79, 124, 160, 196, 227, 244). If a caller passes a value like http://localhost:8080/ or http://localhost:8080/2.0, concatenation will produce malformed URLs such as http://localhost:8080//oauth2/token or http://localhost:8080/2.0/2.0/users. Add normalization to NewClient and RequestAccessToken to trim trailing slashes and the /2.0 suffix once:

Suggested fix
 func NewClient(httpClient *http.Client, token string, baseURL string) *Client {
 	if baseURL == "" {
 		baseURL = defaultBaseURL
 	}
+	baseURL = strings.TrimRight(baseURL, "/")
+	baseURL = strings.TrimSuffix(baseURL, "/2.0")
 	return &Client{
 		httpClient: httpClient,
 		token:      token,
 		baseURL:    baseURL,
 	}
 }

 // RequestAccessToken creates bearer token needed to use the Box API.
 func RequestAccessToken(ctx context.Context, clientID string, clientSecret string, enterpriseId string, baseURL string) (string, error) {
 	if baseURL == "" {
 		baseURL = defaultBaseURL
 	}
+	baseURL = strings.TrimRight(baseURL, "/")
+	baseURL = strings.TrimSuffix(baseURL, "/2.0")
 	httpClient, err := uhttp.NewClient(ctx, uhttp.WithLogger(true, ctxzap.Extract(ctx)))
 	if err != nil {
 		return "", err
 	}
 	authUrl := fmt.Sprint(baseURL, "/oauth2/token")

Copy link

@russellhaering russellhaering left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM — both API and auth URLs use override.

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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants