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

feat: fallback account config #434

Merged
merged 1 commit into from
Mar 12, 2025
Merged
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
16 changes: 16 additions & 0 deletions bluemix/configuration/core_config/bx_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ type BXConfigData struct {
AlphaCommandsEnabled string
HTTPTimeout int
TypeOfSSO string
FallbackAccount models.Account
FallbackIAMTokens struct {
IAMToken string
IAMRefreshToken string
Expand Down Expand Up @@ -430,6 +431,13 @@ func (c *bxConfig) TypeOfSSO() (style string) {
return
}

func (c *bxConfig) FallbackAccount() (a models.Account) {
c.read(func() {
a = c.data.FallbackAccount
})
return
}

func (c *bxConfig) FallbackIAMToken() (t string) {
c.read(func() {
t = c.data.FallbackIAMTokens.IAMToken
Expand Down Expand Up @@ -669,6 +677,14 @@ func (c *bxConfig) SetTypeOfSSO(style string) {
})
}

func (c *bxConfig) SetFallbackAccount(guid, name, owner string) {
c.write(func() {
c.data.FallbackAccount.GUID = guid
c.data.FallbackAccount.Name = name
c.data.FallbackAccount.Owner = owner
})
}

func (c *bxConfig) SetFallbackIAMTokens(token, refreshToken string) {
c.write(func() {
c.data.FallbackIAMTokens.IAMToken = token
Expand Down
22 changes: 22 additions & 0 deletions bluemix/configuration/core_config/bx_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,28 @@ func TestMOD(t *testing.T) {
t.Cleanup(cleanupConfigFiles)
}

func TestFallback(t *testing.T) {

config := prepareConfigForCLI(`{}`, t)

// check initial state
assert.Empty(t, config.FallbackAccount().GUID)
assert.Empty(t, config.FallbackIAMToken())
assert.Empty(t, config.FallbackIAMRefreshToken())

// update mod time and check that mod should not be checked again
config.SetFallbackAccount("value1", "value2", "value3")
assert.True(t, config.FallbackAccount().GUID == "value1")
assert.True(t, config.FallbackAccount().Name == "value2")
assert.True(t, config.FallbackAccount().Owner == "value3")

config.SetFallbackIAMTokens("value1", "value2")
assert.True(t, config.FallbackIAMToken() == "value1")
assert.True(t, config.FallbackIAMRefreshToken() == "value2")

t.Cleanup(cleanupConfigFiles)
}

func TestLastUpdateSessionTime(t *testing.T) {

config := prepareConfigForCLI(`{}`, t)
Expand Down
2 changes: 2 additions & 0 deletions bluemix/configuration/core_config/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ type Repository interface {
TypeOfSSO() string
AlphaCommandsEnabled() string
AssumedTrustedProfileId() string
FallbackAccount() models.Account
FallbackIAMToken() string
FallbackIAMRefreshToken() string
HTTPTimeout() int
Expand Down Expand Up @@ -95,6 +96,7 @@ type Repository interface {
SetIAMToken(string)
SetIAMRefreshToken(string)
SetFallbackIAMTokens(string, string)
SetFallbackAccount(string, string, string)
SetAssumedTrustedProfileId(string)
ClearSession()
SetAccount(models.Account)
Expand Down