Add additional AWS v4 signature parameters to go client generator (#8706)

This commit is contained in:
Kamil Piotrowski 2021-02-21 15:07:22 +01:00 committed by GitHub
parent f3c164d1ad
commit a9e797c6ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 2 deletions

View File

@ -358,7 +358,7 @@ func (c *APIClient) prepareRequest(
{{#withAWSV4Signature}} {{#withAWSV4Signature}}
// AWS Signature v4 Authentication // AWS Signature v4 Authentication
if auth, ok := ctx.Value(ContextAWSv4).(AWSv4); ok { 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) signer := awsv4.NewSigner(creds)
var reader *strings.Reader var reader *strings.Reader
if body == nil { if body == nil {
@ -366,8 +366,19 @@ func (c *APIClient) prepareRequest(
} else { } else {
reader = strings.NewReader(body.String()) 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() timestamp := time.Now()
_, err := signer.Sign(localVarRequest, reader, "oapi", "eu-west-2", timestamp) _, err := signer.Sign(localVarRequest, reader, service, region, timestamp)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -70,6 +70,9 @@ type APIKey struct {
type AWSv4 struct { type AWSv4 struct {
AccessKey string AccessKey string
SecretKey string SecretKey string
SessionToken string
Region string
Service string
} }
{{/withAWSV4Signature}} {{/withAWSV4Signature}}