aws / aws-sdk-go-v2

AWS SDK for the Go programming language.
https://aws.github.io/aws-sdk-go-v2/docs/
Apache License 2.0
2.68k stars 651 forks source link

Credentials field name is wrong #2797

Closed mehiatt closed 2 months ago

mehiatt commented 2 months ago

Acknowledgements

Describe the bug

If you try to use aws.Credentials type with an incoming assume role request, it doesn't map the values correctly because it uses "Expires" vs "Expiration"

Regression Issue

Expected Behavior

If the other match, it seems like the expiration date field should also. While this may not be the standard use case, I see a few points with the AWS GoV2 that could benefit from this as well. Maintaining names would also help people when they go though AWS docs and code examples.

Current Behavior

Tldr: It seems like is Expiration either omitted or misspelled in Credentials type.

Reproduction Steps

To reproduce:

type AwsCredentials struct {
Credentials aws.Credentials
}

Have the above type and then the following code (omitting if err != nil {statements for readability) :

req, err := http.NewRequest("GET", "https://"+our creds endpoint+"/role-aliases/"+role name here+"/credentials", nil)     // make req

req.Header.Add("x-amzn-iot-thingname", deviceName)            //add header
res, err := httpClient.Do(req)                                //do request
defer res.Body.Close()

awsCreds := &types.AwsCredentials{}                           // using Credentials Type here to init
json.NewDecoder(res.Body).Decode(awsCreds)                    // decoding with that type

Now if you print out awsCreds, it returns 0001-01-01T00:00:00Z for Expires - I am assuming the default go time object. All the other fields in Credentials match the response names ->

AccessKeyID = AccessKeyId (case is technically slightly off here, but the values still map correctly) SessionToken = SessionToken SecretAccessKey = SecretAccessKey

Possible Solution

No response

Additional Information/Context

No response

AWS Go SDK V2 Module Versions Used

latest

Compiler and Version used

1.19

Operating System and version

ubuntu 22.04

lucix-aws commented 2 months ago

We can't change the name of a field in a public API just for the sake of having these field names match up like this. The nomenclature here across AWS is generally inconsistent, some APIs use Expires, others use Expiration. If you want to deserialize some credentials value, you'll need to write logic to handle the mapping.

github-actions[bot] commented 2 months ago

This issue is now closed. Comments on closed issues are hard for our team to see. If you need more assistance, please open a new issue that references this one.