Add --base-url flag for connector testability#11
Add --base-url flag for connector testability#11robert-chiniquy wants to merge 3 commits intomainfrom
Conversation
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
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the 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. WalkthroughThis change introduces a configurable Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
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 | 🟡 MinorNormalize
baseURLto 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/orhttp://localhost:8080/2.0, concatenation will produce malformed URLs such ashttp://localhost:8080//oauth2/tokenorhttp://localhost:8080/2.0/2.0/users. Add normalization toNewClientandRequestAccessTokento trim trailing slashes and the/2.0suffix 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")
russellhaering
left a comment
There was a problem hiding this comment.
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)
Summary
Adds the
--base-urlCLI flag to enable overriding the default API endpoint for testing purposes.Changes
BaseURLFieldto configuration--base-urlis provided, it takes precedence over the default API URLFiles Modified
Testing
The connector can now be tested against mock servers:
Related
Part of the Connector Testability initiative.
Summary by CodeRabbit