Skip to content

Commit

Permalink
bypass name resolution (#477)
Browse files Browse the repository at this point in the history
Signed-off-by: Kartikay <[email protected]>
  • Loading branch information
kartikaysaxena authored Mar 7, 2025
1 parent 1467df1 commit 2146357
Showing 1 changed file with 17 additions and 0 deletions.
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
}

0 comments on commit 2146357

Please sign in to comment.