Skip to content

feat(client): add WithHTTPClient option - #762

Merged
Benehiko merged 7 commits into
mainfrom
feat/pass-with-client
Dec 4, 2026
Merged

Benehiko merged 7 commits into
mainfrom
feat/pass-with-client

Conversation

@Benehiko

@Benehiko Benehiko commented Dec 4, 2026 •

Copy link
Copy Markdown
Member

Adds client.WithHTTPClient(*http.Client) so callers can give client.New their own HTTP client instead of the one it builds by default.

  • The given client must reach the engine on its own (e.g. a Transport that dials the socket), so combining it with WithSocketPath or WithDialContext returns cannot set http client and socket path or dial.
  • Request and response timeouts come from the given client; WithTimeout and WithResponseTimeout do not apply to it.
  • WithHTTPClient(nil) returns no http client provided.
  • Dial failures are still reported as ConnectError / ErrSecretsEngineNotRunning.

Tests in TestWithHTTPClient cover requests through the client, the error cases, and an unreachable engine.

Lets callers pass an existing client.Client to the pass commands instead of having one built from the socket path and timeout options.
@Benehiko
Benehiko requested a review from a team as a code owner December 4, 2026 08:50
Lets callers pass their own *http.Client to client.New. Drops the WithClient option from the pass commands.
@Benehiko Benehiko changed the title feat(pass): add WithClient option to commands feat(client): add WithClient option Dec 4, 2026
@Benehiko Benehiko changed the title feat(client): add WithClient option feat(client): add WithHTTPClient option Dec 4, 2026

@docker-agent docker-agent left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Assessment: 🟡 NEEDS ATTENTION

Comment thread plugins/pass/commands/client.go Outdated

func WithClient(c client.Client) ClientOption {
return func(o *clientOpts) error {
if c == nil {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[medium] WithClient nil check misses typed-nil interface values

client.Client is an interface. The guard if c == nil only catches a bare (untyped) nil — when both the type descriptor and the value pointer are nil. If a caller passes a typed nil, e.g.:

var c *myConcreteClient = nil
WithClient(c)  // passes the nil check, opts.client is now non-nil

…the interface value is not nil (its type descriptor is populated), so the check passes silently. newClient then returns this non-nil interface wrapping a nil pointer, and any method call on the returned client will panic at runtime.

Fix: use a reflection-based check (and add "reflect" to imports):

if c == nil || reflect.ValueOf(c).IsNil() {
    return errors.New("no client provided")
}

Alternatively, document clearly that WithClient does not support typed-nil values, so callers know they must guard before calling.

Confidence Score
🟢 strong 97/100

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

huh?

@Benehiko
Benehiko merged commit 1a33bbd into main Dec 4, 2026
18 of 19 checks passed
@Benehiko
Benehiko deleted the feat/pass-with-client branch December 4, 2026 09:01
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