cli: add custom chrome policy flags to browser and pool commands#180
Open
rgarcia wants to merge 1 commit into
Open
cli: add custom chrome policy flags to browser and pool commands#180rgarcia wants to merge 1 commit into
rgarcia wants to merge 1 commit into
Conversation
Add --chrome-policy / --chrome-policy-file to `browsers create`,
`browser-pools create`, and `browser-pools update`, wiring the API's
chrome_policy field (already supported by the Go SDK) through the CLI.
The two flags are mutually exclusive; --chrome-policy takes an inline
JSON object and --chrome-policy-file reads one from a path ("-" = stdin),
matching the existing --payload/--payload-file convention. A shared
parseChromePolicy helper validates the input is a JSON object. Blocked
kernel-managed policies are enforced server-side, so the CLI forwards
verbatim and surfaces the API error rather than duplicating the rules.
An explicit empty object is dropped from the request (chrome_policy uses
omitzero, which only drops a nil map, so assignment is guarded by len>0);
on pool update an empty object cannot clear an existing policy, which is
surfaced with a warning in human output.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds CLI support for setting a custom Chrome enterprise policy (the API's
chrome_policyfield, already supported by the Go SDK) on three commands:kernel browsers createkernel browser-pools createkernel browser-pools updateEach gains two mutually-exclusive flags:
--chrome-policy '<json>'— an inline JSON object--chrome-policy-file <path>— read the object from a file (-reads stdin)This mirrors the existing
--payload/--payload-fileand--data/--data-fileconventions.Design notes
parseChromePolicyhelper parses intomap[string]any, so non-object JSON (arrays, scalars,null) is rejected with a clear error before any request is sent.chrome_policyusesomitzero, which only drops a nil map — a non-nil empty{}would serialize as"chrome_policy":{}. Assignment is therefore guarded bylen > 0, so an empty object is treated as "unset".browser-pools update, an empty{}cannot clear an existing policy (omitzero strips it before it reaches the server). Rather than silently no-op, this surfaces a warning in human output (suppressed under-o jsonto keep stdout valid).Scope
browsers updateandinvokeare intentionally excluded: their SDK params structs (BrowserUpdateParams,InvocationNewParams) carry nochrome_policyfield, so there's nothing to wire until the SDK is regenerated.--output jsonwith no printer changes (response structs already carry the field).Test plan
{}omitted (asserted at both the Go field and the serialized JSON), invalid JSON /nullrejected, parser covers file + stdin + whitespace + missing-file, and the pool-lease conflict contract is locked (--chrome-policystays out of the allowed-flag set).make test(go vet + go test ./...) passes; gofmt clean.{}no-ops without clearing; invalid/null/mutual-exclusion exit non-zero before any API call; and the server correctly rejectsProxyMode/ExtensionInstallForcelistwith the CLI surfacing the error.Note (pre-existing, unrelated)
When a browser-config flag is combined with
--pool-id/--pool-name, the existing conflict-confirmation prompt (pterm.DefaultInteractiveConfirm) does not treat EOF / non-TTY stdin as "no", so it blocks in a non-interactive pipeline. This predates this change and affects all config flags equally; flagging it as a possible follow-up.🤖 Generated with Claude Code
Note
Low Risk
CLI-only wiring to an existing SDK/API field with client-side validation and tests; policy enforcement for kernel-managed keys remains server-side.
Overview
Adds
--chrome-policyand--chrome-policy-file(mutually exclusive,-for stdin) sokernel browsers createandkernel browser-pools create/updatecan send the API’schrome_policyfield. A sharedparseChromePolicyhelper validates a JSON object before any request; only non-empty policies are attached (len > 0), so{}is not sent on the wire.On
browser-pools update, passing an empty{}does not clear an existing pool policy—the CLI warns in human output and stays silent with-o json.poolLeaseAllowedFlagsis extracted so--chrome-policyis not treated as pool-lease-safe; combining it with--pool-id/--pool-namestill triggers the existing config conflict warning. README and unit tests cover parsing, omission, warnings, and serialized JSON.Reviewed by Cursor Bugbot for commit 0d964f8. Bugbot is set up for automated code reviews on this repo. Configure here.