Skip to content

Commit 9bcb019

Browse files
authored
feat(cli): configurable gRPC max receive message size (#3141)
Signed-off-by: lemonprogis <edward.briggler@gmail.com>
1 parent d8ac229 commit 9bcb019

5 files changed

Lines changed: 165 additions & 7 deletions

File tree

app/cli/cmd/artifact.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ func wrappedArtifactConn(cpConn *grpc.ClientConn, role pb.CASCredentialsServiceG
5656
grpcconn.WithCLIVersion(fullVersion()),
5757
}
5858

59+
if maxRecv := apiMaxRecvMsgSize(); maxRecv > 0 {
60+
opts = append(opts, grpcconn.WithMaxRecvMsgSize(maxRecv))
61+
}
62+
5963
if caValue := viper.GetString(confOptions.CASCA.viperKey); caValue != "" {
6064
if _, err := os.Stat(caValue); err == nil {
6165
opts = append(opts, grpcconn.WithCAFile(caValue))

app/cli/cmd/config.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// Copyright 2024 The Chainloop Authors.
2+
// Copyright 2024-2026 The Chainloop Authors.
33
//
44
// Licensed under the Apache License, Version 2.0 (the "License");
55
// you may not use this file except in compliance with the License.
@@ -26,7 +26,7 @@ import (
2626

2727
// Map of all the possible configuration options that we expect viper to handle
2828
var confOptions = struct {
29-
authToken, controlplaneAPI, CASAPI, controlplaneCA, CASCA, insecure, organization, platformAPI *confOpt
29+
authToken, controlplaneAPI, CASAPI, controlplaneCA, CASCA, insecure, organization, platformAPI, maxRecvMsgSize *confOpt
3030
}{
3131
insecure: &confOpt{
3232
viperKey: "api-insecure",
@@ -54,6 +54,10 @@ var confOptions = struct {
5454
viperKey: "organization",
5555
flagName: "org",
5656
},
57+
maxRecvMsgSize: &confOpt{
58+
viperKey: "api-max-recv-msg-size",
59+
flagName: "max-recv-msg-size",
60+
},
5761
}
5862

5963
type confOpt struct {

app/cli/cmd/root.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@ func NewRootCmd(l zerolog.Logger) *cobra.Command {
138138
grpcconn.WithCLIVersion(fullVersion()),
139139
}
140140

141+
if maxRecv := apiMaxRecvMsgSize(); maxRecv > 0 {
142+
opts = append(opts, grpcconn.WithMaxRecvMsgSize(maxRecv))
143+
}
144+
141145
if caValue := viper.GetString(confOptions.controlplaneCA.viperKey); caValue != "" {
142146
// Check if the value is a file path, if it is we read the content and encode it to base64, if not we assume it's the content already
143147
if _, err := os.Stat(caValue); err == nil {
@@ -265,6 +269,11 @@ func NewRootCmd(l zerolog.Logger) *cobra.Command {
265269
cobra.CheckErr(viper.BindPFlag(confOptions.insecure.viperKey, rootCmd.PersistentFlags().Lookup("insecure")))
266270
cobra.CheckErr(viper.BindEnv(confOptions.insecure.viperKey, CalculateEnvVarName(confOptions.insecure.viperKey)))
267271

272+
// Override the gRPC client-side max receive message size in bytes (0 = use default)
273+
rootCmd.PersistentFlags().Int(confOptions.maxRecvMsgSize.flagName, 0, fmt.Sprintf("Max size in bytes for incoming gRPC messages (0 = default %d) ($%s)", grpcconn.DefaultMaxRecvMsgSize, CalculateEnvVarName(confOptions.maxRecvMsgSize.viperKey)))
274+
cobra.CheckErr(viper.BindPFlag(confOptions.maxRecvMsgSize.viperKey, rootCmd.PersistentFlags().Lookup(confOptions.maxRecvMsgSize.flagName)))
275+
cobra.CheckErr(viper.BindEnv(confOptions.maxRecvMsgSize.viperKey, CalculateEnvVarName(confOptions.maxRecvMsgSize.viperKey)))
276+
268277
rootCmd.PersistentFlags().BoolVar(&flagDebug, "debug", false, "Enable debug/verbose logging mode")
269278
rootCmd.PersistentFlags().StringVarP(&flagOutputFormat, "output", "o", "table", "Output format, valid options are json and table")
270279

@@ -499,6 +508,12 @@ func apiInsecure() bool {
499508
return viper.GetBool(confOptions.insecure.viperKey)
500509
}
501510

511+
// apiMaxRecvMsgSize returns the configured gRPC max receive message size for
512+
// the CLI's outbound connections, in bytes. 0 means "use grpcconn's default".
513+
func apiMaxRecvMsgSize() int {
514+
return viper.GetInt(confOptions.maxRecvMsgSize.viperKey)
515+
}
516+
502517
// setLocalOrganization updates the local organization configuration
503518
func setLocalOrganization(orgName string) error {
504519
viper.Set(confOptions.organization.viperKey, orgName)

0 commit comments

Comments
 (0)