Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#1192 - Fix shared config loading of Duration Seconds from roles to use raw instead of int64 #1193

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions config/shared_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -613,8 +613,8 @@ func mergeSections(dst, src ini.Sections) error {

// role duration seconds key update
if srcSection.Has(roleDurationSecondsKey) {
roleDurationSeconds := srcSection.Int(roleDurationSecondsKey)
v, err := ini.NewIntValue(roleDurationSeconds)
roleDurationSeconds := srcSection.Raw(roleDurationSecondsKey)
v, err := ini.NewRawIntValue(roleDurationSeconds)
if err != nil {
return fmt.Errorf("error merging role duration seconds key, %w", err)
}
Expand Down
7 changes: 7 additions & 0 deletions config/shared_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"strconv"
"strings"
"testing"
"time"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/internal/ini"
Expand Down Expand Up @@ -302,6 +303,8 @@ func TestLoadSharedConfigFromSection(t *testing.T) {
if err != nil {
t.Fatalf("failed to load test config file, %s, %v", filename, err)
}
seconds, _ := time.ParseDuration("3601s")

cases := map[string]struct {
Profile string
Expected SharedConfig
Expand All @@ -319,6 +322,10 @@ func TestLoadSharedConfigFromSection(t *testing.T) {
Profile: "profile short_profile_name_first",
Expected: SharedConfig{Region: "short_profile_name_first_alt"},
},
"profile with durations": {
Profile: "profile alt_durations",
Expected: SharedConfig{RoleDurationSeconds: &seconds},
},
"profile with partial creds": {
Profile: "profile partial_creds",
Expected: SharedConfig{},
Expand Down
3 changes: 3 additions & 0 deletions config/testdata/shared_config
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ aws_secret_access_key = SECRET
[profile alt_profile_name]
region = alt_profile_name_region

[profile alt_durations]
duration_seconds=3601

[profile short_profile_name_first]
region = short_profile_name_first_short

Expand Down
5 changes: 5 additions & 0 deletions internal/ini/literal_tokens.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,11 @@ func NewIntValue(i int64) (Value, error) {
return newValue(IntegerType, 10, []rune{rune(i)})
}

// NewRawIntValue returns an Integer Value type generated using a rune input.
func NewRawIntValue(i []rune) (Value, error) {
return newValue(IntegerType, 10, i)
}

// Append will append values and change the type to a string
// type.
func (v *Value) Append(tok Token) {
Expand Down
6 changes: 6 additions & 0 deletions internal/ini/visitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,12 @@ func (t Section) Int(k string) int64 {
return t.values[k].IntValue()
}


// Raw returns a raw value at k
func (t Section) Raw(k string) []rune {
return t.values[k].raw
}

// Float64 returns a float value at k
func (t Section) Float64(k string) float64 {
return t.values[k].FloatValue()
Expand Down