Skip to content

Commit a9e797c

Browse files
author
Kamil Piotrowski
authored
Add additional AWS v4 signature parameters to go client generator (#8706)
1 parent f3c164d commit a9e797c

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

modules/openapi-generator/src/main/resources/go/client.mustache

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,16 +358,27 @@ func (c *APIClient) prepareRequest(
358358
{{#withAWSV4Signature}}
359359
// AWS Signature v4 Authentication
360360
if auth, ok := ctx.Value(ContextAWSv4).(AWSv4); ok {
361-
creds := awscredentials.NewStaticCredentials(auth.AccessKey, auth.SecretKey, "")
361+
creds := awscredentials.NewStaticCredentials(auth.AccessKey, auth.SecretKey, auth.SessionToken)
362362
signer := awsv4.NewSigner(creds)
363363
var reader *strings.Reader
364364
if body == nil {
365365
reader = strings.NewReader("")
366366
} else {
367367
reader = strings.NewReader(body.String())
368368
}
369+
370+
// Define default values for region and service to maintain backward compatibility
371+
region := auth.Region
372+
if region == "" {
373+
region = "eu-west-2"
374+
}
375+
service := auth.Service
376+
if service == "" {
377+
service = "oapi"
378+
}
379+
369380
timestamp := time.Now()
370-
_, err := signer.Sign(localVarRequest, reader, "oapi", "eu-west-2", timestamp)
381+
_, err := signer.Sign(localVarRequest, reader, service, region, timestamp)
371382
if err != nil {
372383
return nil, err
373384
}

modules/openapi-generator/src/main/resources/go/configuration.mustache

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ type APIKey struct {
7070
type AWSv4 struct {
7171
AccessKey string
7272
SecretKey string
73+
SessionToken string
74+
Region string
75+
Service string
7376
}
7477

7578
{{/withAWSV4Signature}}

0 commit comments

Comments
 (0)