feat(cli): expose handler hook for injecting SDK options#3755
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces a hook-based extension point to the handler initialization flow. By allowing downstream consumers to inject SDK options after profile resolution, it eliminates the need for redundant code in secondary CLI tools while maintaining centralized control over authentication and profile management. Highlights
New Features🧠 You can now enable Memory (public preview) to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Hooks are set in order true, / To help the SDK get through. / Profile resolved and context clear, / The extra options now appear. Footnotes
|
|
Warning Review limit reached
Next review available in: 27 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Repository UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughChangesHandler Hook Extension
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant NewHandler
participant handlers.New
participant applyHooks
participant PreSDKHook
participant SDK
NewHandler->>handlers.New: pass profile and hooks
handlers.New->>applyHooks: apply registered hooks
applyHooks->>PreSDKHook: pass resolved context
PreSDKHook-->>applyHooks: return SDK options
applyHooks-->>handlers.New: append options
handlers.New->>SDK: construct SDK
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Code Review
This pull request introduces a hook mechanism during handler construction, allowing downstream CLI extensions to inject SDK options after profile resolution. It renames handlerOptsFunc to HandlerOption, adds the Hook and HookContext types, and implements the WithHook option along with comprehensive unit tests. The review feedback suggests adding defensive nil checks in WithProfile and WithHook to prevent potential nil pointer dereference panics.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
Benchmark results, click to expandBenchmark authorization.GetDecisions Results:
Benchmark authorization.v2.GetMultiResourceDecision Results:
Benchmark Statistics
Bulk Benchmark Results
TDF3 Benchmark Results:
|
|
Caution Review failedAn error occurred during the review process. Please try again later. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Caution Failed to replace (edit) comment. This is likely due to insufficient permissions or the comment being deleted. Error details |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@otdfctl/pkg/handlers/sdk.go`:
- Around line 92-97: Update WithHook to ignore a nil hook before appending it to
c.hooks. Preserve the existing append-and-return behavior for non-nil hooks so
applyHooks only receives executable hooks.
- Around line 81-86: Update WithSDKOpts to append the supplied opts to the
existing c.sdkOpts slice rather than replacing it, preserving previously
configured SDK options when HandlerOption values are composed or applied
repeatedly.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 85584680-95b7-43aa-aabf-93718b89ac6b
📒 Files selected for processing (3)
otdfctl/cmd/common/common.gootdfctl/pkg/handlers/sdk.gootdfctl/pkg/handlers/sdk_test.go
a9bda63 to
19c6378
Compare
Benchmark results, click to expandBenchmark authorization.GetDecisions Results:
Benchmark authorization.v2.GetMultiResourceDecision Results:
Benchmark Statistics
Bulk Benchmark Results
TDF3 Benchmark Results:
|
19c6378 to
9dcafcc
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@otdfctl/pkg/handlers/sdk.go`:
- Around line 106-116: Update WithHook to detect and skip typed-nil Hook values,
including a nil PreSDKHook stored in the Hook interface, before appending to
c.hooks. Preserve registration of non-nil hooks and ensure the typed-nil case
does not reach later invocation.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 2a25b30b-b907-48b2-8ba0-aaa8e82052c1
📒 Files selected for processing (3)
otdfctl/cmd/common/common.gootdfctl/pkg/handlers/sdk.gootdfctl/pkg/handlers/sdk_test.go
Benchmark results, click to expandBenchmark authorization.GetDecisions Results:
Benchmark authorization.v2.GetMultiResourceDecision Results:
Benchmark Statistics
Bulk Benchmark Results
TDF3 Benchmark Results:
|
Adds a Hook extension point so downstream CLIs built on otdfctl's common.NewHandler can inject SDK options that depend on the resolved profile (for example, a client-side connect interceptor) without having to replicate the profile resolution, flag validation, and credential error handling that lives inside NewHandler today. Changes: - pkg/handlers: rename handlerOptsFunc to exported HandlerOption so downstream packages can name the option type when composing calls to handlers.New. Introduce Hook as a marker interface and PreSDKHook as the first concrete variant; PreSDKHook runs after every HandlerOption has been applied and before sdk.New so it observes the fully resolved endpoint, TLS flag, and profile via PreSDKHookContext. Future point-specific hooks (post-build, auth-error, etc.) land as sibling named types with an isHandlerHook receiver and a new case in the applyHooks dispatch switch, so no new exported registration function is needed. WithHook is variadic and skips nil entries, and WithProfile skips nil profiles so it cannot deref GetEndpoint. applyHooks drops unknown Hook variants rather than panicking, so future variants can land ahead of the corresponding dispatch update. - cmd/common: NewHandler accepts an optional variadic list of handlers.Hook values and forwards them into handlers.New via WithHook. Zero-hook callers are unchanged, so every existing common.NewHandler(c) call site continues to compile and behave the same way. Motivation: a Virtru CLI that wraps otdfctl currently duplicates common.NewHandler wholesale (~130 lines of profile resolution, flag validation, and credential error handling) purely to attach a license-status capture interceptor to the SDK. With this hook the downstream call collapses to a single common.NewHandler(c, handlers.PreSDKHook(fn)) and otdfctl remains the single owner of profile and auth flow logic. Test plan: - pkg/handlers/sdk_test.go covers hook registration order (including the variadic form), PreSDKHookContext content, option append behavior, the no-hooks no-op path, the nil-input guards on WithHook (single and variadic) and WithProfile, and the unknown-variant drop path. - otdfctl `go test ./... -race` passes. Signed-off-by: Ron Elliott <ron.elliott@virtru.com>
9dcafcc to
6f5db67
Compare
Benchmark results, click to expandBenchmark authorization.GetDecisions Results:
Benchmark authorization.v2.GetMultiResourceDecision Results:
Benchmark Statistics
Bulk Benchmark Results
TDF3 Benchmark Results:
|
|
Proposed Changes
Hookextension point topkg/handlersso callers can inject SDK options that depend on the resolved profile without replicating any of the profile resolution or credential validation flow.handlerOptsFuncto the exportedHandlerOptionso downstream packages can name the option type when composing calls tohandlers.New.cmd/common.NewHandlerwith an optional variadic...handlers.Hook. Every existing zero-hook call site keeps working unchanged.The hook runs after every
HandlerOptionhas been applied and beforesdk.Newis called. Hooks compose in registration order and receive aHookContextwith the fully resolved endpoint, TLS flag, and profile.Motivation
A Virtru CLI built on top of otdfctl (
tructl) currently duplicatescommon.NewHandlerwholesale, about 130 lines of profile resolution, flag validation, and credential error handling, purely so it can attach a client-side connect interceptor to the SDK for license status header capture. With this hook that downstream call collapses to:and otdfctl stays the single owner of the profile and auth flow.
Checklist
Testing Instructions
cd otdfctl && go test ./... -racepkg/handlers/sdk_test.goand cover:HookContextcontent matches the resolved handler configsdkOptsapplyHooksis a no-op when no hooks are registeredSummary by CodeRabbit
New Features
Tests