-
Notifications
You must be signed in to change notification settings - Fork 636
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SDK DefaultsMode Configuration Implementation (#1553)
* SDK Default Configuration Implementation * Regeneration
- Loading branch information
Showing
1,005 changed files
with
30,195 additions
and
3,684 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package defaults | ||
|
||
import ( | ||
"github.com/aws/aws-sdk-go-v2/aws" | ||
"runtime" | ||
"strings" | ||
) | ||
|
||
var getGOOS = func() string { | ||
return runtime.GOOS | ||
} | ||
|
||
// ResolveDefaultsModeAuto is used to determine the effective aws.DefaultsMode when the mode | ||
// is set to aws.AutoDefaultsMode. | ||
func ResolveDefaultsModeAuto(region string, environment aws.RuntimeEnvironment) aws.DefaultsMode { | ||
goos := getGOOS() | ||
if goos == "android" || goos == "ios" { | ||
return aws.DefaultsModeMobile | ||
} | ||
|
||
var currentRegion string | ||
if len(environment.EnvironmentIdentifier) > 0 { | ||
currentRegion = environment.Region | ||
} | ||
|
||
if len(currentRegion) == 0 && len(environment.EC2InstanceMetadataRegion) > 0 { | ||
currentRegion = environment.EC2InstanceMetadataRegion | ||
} | ||
|
||
if len(region) > 0 && len(currentRegion) > 0 { | ||
if strings.EqualFold(region, currentRegion) { | ||
return aws.DefaultsModeInRegion | ||
} | ||
return aws.DefaultsModeCrossRegion | ||
} | ||
|
||
return aws.DefaultsModeStandard | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package defaults | ||
|
||
import ( | ||
"github.com/aws/aws-sdk-go-v2/aws" | ||
"strconv" | ||
"testing" | ||
) | ||
|
||
func TestDetermineDefaultsMode(t *testing.T) { | ||
cases := []struct { | ||
Region string | ||
GOOS string | ||
Environment aws.RuntimeEnvironment | ||
Expected aws.DefaultsMode | ||
}{ | ||
{ | ||
Region: "us-east-1", | ||
GOOS: "ios", | ||
Environment: aws.RuntimeEnvironment{ | ||
EnvironmentIdentifier: aws.ExecutionEnvironmentID("AWS_Lambda_java8"), | ||
Region: "us-east-1", | ||
}, | ||
Expected: aws.DefaultsModeMobile, | ||
}, | ||
{ | ||
Region: "us-east-1", | ||
GOOS: "android", | ||
Environment: aws.RuntimeEnvironment{ | ||
EnvironmentIdentifier: aws.ExecutionEnvironmentID("AWS_Lambda_java8"), | ||
Region: "us-east-1", | ||
}, | ||
Expected: aws.DefaultsModeMobile, | ||
}, | ||
{ | ||
Region: "us-east-1", | ||
Environment: aws.RuntimeEnvironment{ | ||
EnvironmentIdentifier: aws.ExecutionEnvironmentID("AWS_Lambda_java8"), | ||
Region: "us-east-1", | ||
}, | ||
Expected: aws.DefaultsModeInRegion, | ||
}, | ||
{ | ||
Region: "us-east-1", | ||
Environment: aws.RuntimeEnvironment{ | ||
EnvironmentIdentifier: aws.ExecutionEnvironmentID("AWS_Lambda_java8"), | ||
Region: "us-west-2", | ||
}, | ||
Expected: aws.DefaultsModeCrossRegion, | ||
}, | ||
{ | ||
Region: "us-east-1", | ||
Environment: aws.RuntimeEnvironment{ | ||
Region: "us-east-1", | ||
EC2InstanceMetadataRegion: "us-east-1", | ||
}, | ||
Expected: aws.DefaultsModeInRegion, | ||
}, | ||
{ | ||
Region: "us-east-1", | ||
Environment: aws.RuntimeEnvironment{ | ||
EC2InstanceMetadataRegion: "us-west-2", | ||
}, | ||
Expected: aws.DefaultsModeCrossRegion, | ||
}, | ||
{ | ||
Region: "us-west-2", | ||
Environment: aws.RuntimeEnvironment{}, | ||
Expected: aws.DefaultsModeStandard, | ||
}, | ||
} | ||
|
||
for i, tt := range cases { | ||
t.Run(strconv.Itoa(i), func(t *testing.T) { | ||
if len(tt.GOOS) > 0 { | ||
orig := getGOOS | ||
getGOOS = func() string { | ||
return tt.GOOS | ||
} | ||
defer func() { | ||
getGOOS = orig | ||
}() | ||
} | ||
got := ResolveDefaultsModeAuto(tt.Region, tt.Environment) | ||
if got != tt.Expected { | ||
t.Errorf("expect %v, got %v", tt.Expected, got) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package defaults | ||
|
||
import "time" | ||
|
||
// Configuration is the set of SDK configuration options that are determined based | ||
// on the configured DefaultsMode. | ||
type Configuration struct { | ||
// ConnectTimeout is the maximum amount of time a dial will wait for | ||
// a connect to complete. | ||
// | ||
// See https://pkg.go.dev/net#Dialer.Timeout | ||
ConnectTimeout *time.Duration | ||
|
||
// TLSNegotiationTimeout specifies the maximum amount of time waiting to | ||
// wait for a TLS handshake. | ||
// | ||
// See https://pkg.go.dev/net/http#Transport.TLSHandshakeTimeout | ||
TLSNegotiationTimeout *time.Duration | ||
} | ||
|
||
// GetConnectTimeout returns the ConnectTimeout value, returns false if the value is not set. | ||
func (c *Configuration) GetConnectTimeout() (time.Duration, bool) { | ||
if c.ConnectTimeout == nil { | ||
return 0, false | ||
} | ||
return *c.ConnectTimeout, true | ||
} | ||
|
||
// GetTLSNegotiationTimeout returns the TLSNegotiationTimeout value, returns false if the value is not set. | ||
func (c *Configuration) GetTLSNegotiationTimeout() (time.Duration, bool) { | ||
if c.TLSNegotiationTimeout == nil { | ||
return 0, false | ||
} | ||
return *c.TLSNegotiationTimeout, true | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package defaults | ||
|
||
import ( | ||
"github.com/aws/aws-sdk-go-v2/aws" | ||
"strconv" | ||
"testing" | ||
"time" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
) | ||
|
||
func TestConfigV1(t *testing.T) { | ||
cases := []struct { | ||
Mode aws.DefaultsMode | ||
Expected Configuration | ||
}{ | ||
{ | ||
Mode: aws.DefaultsModeStandard, | ||
Expected: Configuration{ | ||
ConnectTimeout: aws.Duration(2000 * time.Millisecond), | ||
TLSNegotiationTimeout: aws.Duration(2000 * time.Millisecond), | ||
}, | ||
}, | ||
{ | ||
Mode: aws.DefaultsModeInRegion, | ||
Expected: Configuration{ | ||
ConnectTimeout: aws.Duration(1000 * time.Millisecond), | ||
TLSNegotiationTimeout: aws.Duration(1000 * time.Millisecond), | ||
}, | ||
}, | ||
{ | ||
Mode: aws.DefaultsModeCrossRegion, | ||
Expected: Configuration{ | ||
ConnectTimeout: aws.Duration(2800 * time.Millisecond), | ||
TLSNegotiationTimeout: aws.Duration(2800 * time.Millisecond), | ||
}, | ||
}, | ||
{ | ||
Mode: aws.DefaultsModeMobile, | ||
Expected: Configuration{ | ||
ConnectTimeout: aws.Duration(10000 * time.Millisecond), | ||
TLSNegotiationTimeout: aws.Duration(11000 * time.Millisecond), | ||
}, | ||
}, | ||
} | ||
|
||
for i, tt := range cases { | ||
t.Run(strconv.Itoa(i), func(t *testing.T) { | ||
got, err := v1TestResolver(tt.Mode) | ||
if err != nil { | ||
t.Fatalf("expect no error, got %v", err) | ||
} | ||
if diff := cmp.Diff(tt.Expected, got); len(diff) > 0 { | ||
t.Error(diff) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// Package defaults provides recommended configuration values for AWS SDKs and CLIs. | ||
package defaults |
Oops, something went wrong.