Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

client: bypass endpoint name resolution #477

Merged
merged 1 commit into from
Mar 7, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions internal/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"net/url"
"os"
"path/filepath"
"strings"

"golang.org/x/net/proxy"

Expand Down Expand Up @@ -50,6 +51,10 @@ func newClientForCurrentContext(cmd *cobra.Command) (Client, error) {
return nil, err
}

if cobrautil.MustGetString(cmd, "proxy") != "" {
token.Endpoint = withPassthroughTarget(token.Endpoint)
}

client, err := authzed.NewClientWithExperimentalAPIs(token.Endpoint, dialOpts...)
if err != nil {
return nil, err
Expand All @@ -74,6 +79,10 @@ func newClientForContext(cmd *cobra.Command, contextName string, secretStore sto
return nil, err
}

if cobrautil.MustGetString(cmd, "proxy") != "" {
token.Endpoint = withPassthroughTarget(token.Endpoint)
}

return authzed.NewClient(token.Endpoint, dialOpts...)
}

Expand Down Expand Up @@ -242,3 +251,11 @@ func DialOptsFromFlags(cmd *cobra.Command, token storage.Token) ([]grpc.DialOpti

return opts, nil
}

func withPassthroughTarget(endpoint string) string {
// If it already has a scheme, return as-is
if strings.Contains(endpoint, "://") {
return endpoint
}
return "passthrough:///" + endpoint
}
Loading