Skip to content

Commit 2e08461

Browse files
authored
support configurable auth scheme preference (#3153)
1 parent 5462033 commit 2e08461

File tree

1,296 files changed

+17601
-4162
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,296 files changed

+17601
-4162
lines changed

.changelog/d034a8bd3da745909458e9d2eb054695.json

Lines changed: 434 additions & 0 deletions
Large diffs are not rendered by default.

SMITHY_GO_CODEGEN_VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
a22818fe19b9bc7d4926501907b154d813b309a5
1+
8ff86680d1bfd5b4cc19329702bd64458ac7f1b6

aws/config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,9 @@ type Config struct {
196196

197197
// Registry of HTTP interceptors.
198198
Interceptors smithyhttp.InterceptorRegistry
199+
200+
// Priority list of preferred auth scheme IDs.
201+
AuthSchemePreference []string
199202
}
200203

201204
// NewConfig returns a new Config pointer that can be chained with builder

codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/AddAwsConfigFields.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import software.amazon.smithy.codegen.core.SymbolProvider;
3131
import software.amazon.smithy.go.codegen.GoDelegator;
3232
import software.amazon.smithy.go.codegen.GoSettings;
33+
import software.amazon.smithy.go.codegen.GoUniverseTypes;
3334
import software.amazon.smithy.go.codegen.GoWriter;
3435
import software.amazon.smithy.go.codegen.SmithyGoDependency;
3536
import software.amazon.smithy.go.codegen.SmithyGoTypes;
@@ -45,6 +46,7 @@
4546
import software.amazon.smithy.utils.ListUtils;
4647

4748
import static software.amazon.smithy.go.codegen.SymbolUtils.buildPackageSymbol;
49+
import static software.amazon.smithy.go.codegen.SymbolUtils.sliceOf;
4850

4951
/**
5052
* Registers additional AWS specific client configuration fields
@@ -266,6 +268,11 @@ public class AddAwsConfigFields implements GoIntegration {
266268
.type(SmithyGoDependency.SMITHY_HTTP_TRANSPORT.struct("InterceptorRegistry"))
267269
.generatedOnClient(false)
268270
.awsResolveFunction(buildPackageSymbol("resolveInterceptors"))
271+
.build(),
272+
AwsConfigField.builder()
273+
.name("AuthSchemePreference")
274+
.type(sliceOf(GoUniverseTypes.String))
275+
.generatedOnClient(false)
269276
.build()
270277
);
271278

config/auth_scheme_preference.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package config
2+
3+
import "strings"
4+
5+
func toAuthSchemePreferenceList(cfg string) []string {
6+
if len(cfg) == 0 {
7+
return nil
8+
}
9+
parts := strings.Split(cfg, ",")
10+
ids := make([]string, 0, len(parts))
11+
12+
for _, p := range parts {
13+
if id := strings.TrimSpace(p); len(id) > 0 {
14+
ids = append(ids, id)
15+
}
16+
}
17+
18+
return ids
19+
}

config/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ var defaultAWSConfigResolvers = []awsConfigResolver{
9191
resolveResponseChecksumValidation,
9292

9393
resolveInterceptors,
94+
95+
resolveAuthSchemePreference,
9496
}
9597

9698
// A Config represents a generic configuration value or set of values. This type

config/env_config.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ const (
8585

8686
awsRequestChecksumCalculation = "AWS_REQUEST_CHECKSUM_CALCULATION"
8787
awsResponseChecksumValidation = "AWS_RESPONSE_CHECKSUM_VALIDATION"
88+
89+
awsAuthSchemePreferenceEnv = "AWS_AUTH_SCHEME_PREFERENCE"
8890
)
8991

9092
var (
@@ -304,6 +306,9 @@ type EnvConfig struct {
304306

305307
// Indicates whether response checksum should be validated
306308
ResponseChecksumValidation aws.ResponseChecksumValidation
309+
310+
// Priority list of preferred auth scheme names (e.g. sigv4a).
311+
AuthSchemePreference []string
307312
}
308313

309314
// loadEnvConfig reads configuration values from the OS's environment variables.
@@ -415,6 +420,8 @@ func NewEnvConfig() (EnvConfig, error) {
415420
return cfg, err
416421
}
417422

423+
cfg.AuthSchemePreference = toAuthSchemePreferenceList(os.Getenv(awsAuthSchemePreferenceEnv))
424+
418425
return cfg, nil
419426
}
420427

@@ -916,3 +923,10 @@ func (c EnvConfig) GetS3DisableExpressAuth() (value, ok bool) {
916923

917924
return *c.S3DisableExpressAuth, true
918925
}
926+
927+
func (c EnvConfig) getAuthSchemePreference() ([]string, bool) {
928+
if len(c.AuthSchemePreference) > 0 {
929+
return c.AuthSchemePreference, true
930+
}
931+
return nil, false
932+
}

config/env_config_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,14 @@ func TestNewEnvConfig(t *testing.T) {
568568
Config: EnvConfig{},
569569
WantErr: true,
570570
},
571+
54: {
572+
Env: map[string]string{
573+
"AWS_AUTH_SCHEME_PREFERENCE": " \tsigv4a\t ,sigv4 ",
574+
},
575+
Config: EnvConfig{
576+
AuthSchemePreference: []string{"sigv4a", "sigv4"},
577+
},
578+
},
571579
}
572580

573581
for i, c := range cases {

config/load_options.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,9 @@ type LoadOptions struct {
232232

233233
// Registry of operation interceptors.
234234
Interceptors smithyhttp.InterceptorRegistry
235+
236+
// Priority list of preferred auth scheme names (e.g. sigv4a).
237+
AuthSchemePreference []string
235238
}
236239

237240
func (o LoadOptions) getDefaultsMode(ctx context.Context) (aws.DefaultsMode, bool, error) {
@@ -1315,3 +1318,20 @@ func WithAfterExecution(i smithyhttp.AfterExecutionInterceptor) LoadOptionsFunc
13151318
return nil
13161319
}
13171320
}
1321+
1322+
// WithAuthSchemePreference sets the priority order of auth schemes on config.
1323+
//
1324+
// Schemes are expressed as names e.g. sigv4a or sigv4.
1325+
func WithAuthSchemePreference(schemeIDs ...string) LoadOptionsFunc {
1326+
return func(o *LoadOptions) error {
1327+
o.AuthSchemePreference = schemeIDs
1328+
return nil
1329+
}
1330+
}
1331+
1332+
func (o LoadOptions) getAuthSchemePreference() ([]string, bool) {
1333+
if len(o.AuthSchemePreference) > 0 {
1334+
return o.AuthSchemePreference, true
1335+
}
1336+
return nil, false
1337+
}

config/provider.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -753,3 +753,18 @@ func getRetryMode(ctx context.Context, configs configs) (v aws.RetryMode, found
753753
}
754754
return v, found, err
755755
}
756+
757+
func getAuthSchemePreference(ctx context.Context, configs configs) ([]string, bool) {
758+
type provider interface {
759+
getAuthSchemePreference() ([]string, bool)
760+
}
761+
762+
for _, cfg := range configs {
763+
if p, ok := cfg.(provider); ok {
764+
if v, ok := p.getAuthSchemePreference(); ok {
765+
return v, true
766+
}
767+
}
768+
}
769+
return nil, false
770+
}

0 commit comments

Comments
 (0)