diff --git a/bluemix/configuration/core_config/bx_config.go b/bluemix/configuration/core_config/bx_config.go index 41c3c0e..456a686 100644 --- a/bluemix/configuration/core_config/bx_config.go +++ b/bluemix/configuration/core_config/bx_config.go @@ -55,6 +55,7 @@ type BXConfigData struct { AlphaCommandsEnabled string HTTPTimeout int TypeOfSSO string + FallbackAccount models.Account FallbackIAMTokens struct { IAMToken string IAMRefreshToken string @@ -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 @@ -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 diff --git a/bluemix/configuration/core_config/bx_config_test.go b/bluemix/configuration/core_config/bx_config_test.go index 79171a5..098af62 100644 --- a/bluemix/configuration/core_config/bx_config_test.go +++ b/bluemix/configuration/core_config/bx_config_test.go @@ -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) diff --git a/bluemix/configuration/core_config/repository.go b/bluemix/configuration/core_config/repository.go index 1189a27..bb69e71 100644 --- a/bluemix/configuration/core_config/repository.go +++ b/bluemix/configuration/core_config/repository.go @@ -54,6 +54,7 @@ type Repository interface { TypeOfSSO() string AlphaCommandsEnabled() string AssumedTrustedProfileId() string + FallbackAccount() models.Account FallbackIAMToken() string FallbackIAMRefreshToken() string HTTPTimeout() int @@ -95,6 +96,7 @@ type Repository interface { SetIAMToken(string) SetIAMRefreshToken(string) SetFallbackIAMTokens(string, string) + SetFallbackAccount(string, string, string) SetAssumedTrustedProfileId(string) ClearSession() SetAccount(models.Account)