From a9e797c6cacc56c651ffb47c2ac354956f8645cd Mon Sep 17 00:00:00 2001 From: Kamil Piotrowski Date: Sun, 21 Feb 2021 15:07:22 +0100 Subject: [PATCH] Add additional AWS v4 signature parameters to go client generator (#8706) --- .../src/main/resources/go/client.mustache | 15 +++++++++++++-- .../src/main/resources/go/configuration.mustache | 3 +++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/go/client.mustache b/modules/openapi-generator/src/main/resources/go/client.mustache index 0720041e12e..4649157dfd0 100644 --- a/modules/openapi-generator/src/main/resources/go/client.mustache +++ b/modules/openapi-generator/src/main/resources/go/client.mustache @@ -358,7 +358,7 @@ func (c *APIClient) prepareRequest( {{#withAWSV4Signature}} // AWS Signature v4 Authentication if auth, ok := ctx.Value(ContextAWSv4).(AWSv4); ok { - creds := awscredentials.NewStaticCredentials(auth.AccessKey, auth.SecretKey, "") + creds := awscredentials.NewStaticCredentials(auth.AccessKey, auth.SecretKey, auth.SessionToken) signer := awsv4.NewSigner(creds) var reader *strings.Reader if body == nil { @@ -366,8 +366,19 @@ func (c *APIClient) prepareRequest( } else { reader = strings.NewReader(body.String()) } + + // Define default values for region and service to maintain backward compatibility + region := auth.Region + if region == "" { + region = "eu-west-2" + } + service := auth.Service + if service == "" { + service = "oapi" + } + timestamp := time.Now() - _, err := signer.Sign(localVarRequest, reader, "oapi", "eu-west-2", timestamp) + _, err := signer.Sign(localVarRequest, reader, service, region, timestamp) if err != nil { return nil, err } diff --git a/modules/openapi-generator/src/main/resources/go/configuration.mustache b/modules/openapi-generator/src/main/resources/go/configuration.mustache index 1f5436d84b7..35cea7c2b65 100644 --- a/modules/openapi-generator/src/main/resources/go/configuration.mustache +++ b/modules/openapi-generator/src/main/resources/go/configuration.mustache @@ -70,6 +70,9 @@ type APIKey struct { type AWSv4 struct { AccessKey string SecretKey string + SessionToken string + Region string + Service string } {{/withAWSV4Signature}}