@@ -12,6 +12,7 @@ import (
12
12
13
13
"github.com/aws/aws-sdk-go-v2/aws"
14
14
"github.com/aws/aws-sdk-go-v2/feature/ec2/imds"
15
+ smithyrequestcompression "github.com/aws/smithy-go/private/requestcompression"
15
16
)
16
17
17
18
// CredentialsSourceName provides a name of the provider when config is
@@ -334,7 +335,7 @@ func NewEnvConfig() (EnvConfig, error) {
334
335
if err := setBoolPtrFromEnvVal (& cfg .DisableRequestCompression , []string {awsDisableRequestCompression }); err != nil {
335
336
return cfg , err
336
337
}
337
- if err := setRequestMinCompressSizeBytes (& cfg .RequestMinCompressSizeBytes ); err != nil {
338
+ if err := setInt64PtrFromEnvVal (& cfg .RequestMinCompressSizeBytes , [] string { awsRequestMinCompressionSizeBytes }, smithyrequestcompression . MaxRequestMinCompressSizeBytes ); err != nil {
338
339
return cfg , err
339
340
}
340
341
@@ -402,27 +403,6 @@ func (c EnvConfig) getAppID(context.Context) (string, bool, error) {
402
403
return c .AppID , len (c .AppID ) > 0 , nil
403
404
}
404
405
405
- func setRequestMinCompressSizeBytes (bytes * * int64 ) error {
406
- b := os .Getenv (awsRequestMinCompressionSizeBytes )
407
- if b == "" {
408
- return nil
409
- }
410
-
411
- byte , err := strconv .ParseInt (b , 10 , 64 )
412
- if err != nil {
413
- return fmt .Errorf ("invalid value for env var, %s=%s, need int64" ,
414
- awsRequestMinCompressionSizeBytes , b )
415
- } else if byte < 0 || byte > 10485760 {
416
- return fmt .Errorf ("invalid range for env var min request compression size bytes %q, must be within 0 and 10485760 inclusively" , byte )
417
- }
418
- if * bytes == nil {
419
- * bytes = new (int64 )
420
- }
421
- * * bytes = byte
422
-
423
- return nil
424
- }
425
-
426
406
func (c EnvConfig ) getDisableRequestCompression (context.Context ) (bool , bool , error ) {
427
407
if c .DisableRequestCompression == nil {
428
408
return false , false , nil
@@ -693,6 +673,30 @@ func setBoolPtrFromEnvVal(dst **bool, keys []string) error {
693
673
return nil
694
674
}
695
675
676
+ func setInt64PtrFromEnvVal (dst * * int64 , keys []string , max int64 ) error {
677
+ for _ , k := range keys {
678
+ value := os .Getenv (k )
679
+ if len (value ) == 0 {
680
+ continue
681
+ }
682
+
683
+ v , err := strconv .ParseInt (value , 10 , 64 )
684
+ if err != nil {
685
+ return fmt .Errorf ("invalid value for env var, %s=%s, need int64" , k , value )
686
+ } else if v < 0 || v > max {
687
+ return fmt .Errorf ("invalid range for env var min request compression size bytes %q, must be within 0 and 10485760 inclusively" , v )
688
+ }
689
+ if * dst == nil {
690
+ * dst = new (int64 )
691
+ }
692
+
693
+ * * dst = v
694
+ break
695
+ }
696
+
697
+ return nil
698
+ }
699
+
696
700
func setEndpointDiscoveryTypeFromEnvVal (dst * aws.EndpointDiscoveryEnableState , keys []string ) error {
697
701
for _ , k := range keys {
698
702
value := os .Getenv (k )
0 commit comments