Skip to content

Commit

Permalink
Make flag more optional-looking
Browse files Browse the repository at this point in the history
  • Loading branch information
tstirrat15 committed Aug 28, 2024
1 parent 1dc9136 commit 1616f73
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
22 changes: 12 additions & 10 deletions internal/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,19 +91,9 @@ func DialOptsFromFlags(cmd *cobra.Command, token storage.Token) ([]grpc.DialOpti
interceptors = append(interceptors, zgrpcutil.CheckServerVersion)
}

maxMessageSize := cobrautil.MustGetInt(cmd, "max-message-size")

opts := []grpc.DialOption{
grpc.WithChainUnaryInterceptor(interceptors...),
grpc.WithChainStreamInterceptor(zgrpcutil.StreamLogDispatchTrailers),
grpc.WithDefaultCallOptions(
// The default max client message size is 4mb.
// It's conceivable that a sufficiently complex
// schema will easily surpass this, so we set the
// limit higher here.
grpc.MaxCallRecvMsgSize(maxMessageSize),
grpc.MaxCallSendMsgSize(maxMessageSize),
),
}

if cobrautil.MustGetBool(cmd, "insecure") || (token.IsInsecure()) {
Expand All @@ -123,5 +113,17 @@ func DialOptsFromFlags(cmd *cobra.Command, token storage.Token) ([]grpc.DialOpti
opts = append(opts, grpc.WithAuthority(hostnameOverride))
}

maxMessageSize := cobrautil.MustGetInt(cmd, "max-message-size")
if maxMessageSize != 0 {
opts = append(opts, grpc.WithDefaultCallOptions(
// The default max client message size is 4mb.
// It's conceivable that a sufficiently complex
// schema will easily surpass this, so we set the
// limit higher here.
grpc.MaxCallRecvMsgSize(maxMessageSize),
grpc.MaxCallSendMsgSize(maxMessageSize),
))
}

return opts, nil
}
2 changes: 1 addition & 1 deletion internal/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func Run() {
rootCmd.PersistentFlags().Bool("no-verify-ca", false, "do not attempt to verify the server's certificate chain and host name")
rootCmd.PersistentFlags().Bool("debug", false, "enable debug logging")
rootCmd.PersistentFlags().String("request-id", "", "optional id to send along with SpiceDB requests for tracing")
rootCmd.PersistentFlags().Int("max-message-size", 4*1024*1024, "maximum size (bytes) of a gRPC message sent or received by zed")
rootCmd.PersistentFlags().Int("max-message-size", 0, "maximum size (bytes) of a gRPC message that can be sent or received by zed")
_ = rootCmd.PersistentFlags().MarkHidden("debug") // This cannot return its error.

versionCmd := &cobra.Command{
Expand Down

0 comments on commit 1616f73

Please sign in to comment.