diff --git a/bluemix/configuration/core_config/cf_config.go b/bluemix/configuration/core_config/cf_config.go index 9fd46763..b6ef4dc3 100644 --- a/bluemix/configuration/core_config/cf_config.go +++ b/bluemix/configuration/core_config/cf_config.go @@ -11,30 +11,31 @@ import ( ) type CFConfigData struct { - ConfigVersion int - Target string + AccessToken string APIVersion string + AsyncTimeout uint AuthorizationEndpoint string - LoggregatorEndpoint string + ColorEnabled string + ConfigVersion int DopplerEndpoint string - UaaEndpoint string - RoutingAPIEndpoint string - LoginAt time.Time - AccessToken string - RefreshToken string - UAAOAuthClient string - UAAOAuthClientSecret string - SSHOAuthClient string + Locale string + LogCacheEndPoint string + MinCLIVersion string + MinRecommendedCLIVersion string OrganizationFields models.OrganizationFields + PluginRepos []models.PluginRepo + RefreshToken string + RoutingAPIEndpoint string SpaceFields models.SpaceFields + SSHOAuthClient string SSLDisabled bool - AsyncTimeout uint + Target string Trace string - ColorEnabled string - Locale string - PluginRepos []models.PluginRepo - MinCLIVersion string - MinRecommendedCLIVersion string + UaaEndpoint string + LoginAt time.Time + UAAGrantType string + UAAOAuthClient string + UAAOAuthClientSecret string raw raw } @@ -49,7 +50,9 @@ func NewCFConfigData() *CFConfigData { } func (data *CFConfigData) Marshal() ([]byte, error) { - data.ConfigVersion = 3 + if data.ConfigVersion == 0 { + data.ConfigVersion = 4 + } return json.MarshalIndent(data, "", " ") } @@ -59,11 +62,6 @@ func (data *CFConfigData) Unmarshal(bytes []byte) error { return err } - if data.ConfigVersion != 3 { - *data = CFConfigData{raw: make(map[string]interface{})} - return nil - } - var raw raw err = json.Unmarshal(bytes, &raw) if err != nil { @@ -184,13 +182,6 @@ func (c *cfConfig) DopplerEndpoint() (endpoint string) { return } -func (c *cfConfig) LoggregatorEndpoint() (endpoint string) { - c.read(func() { - endpoint = c.data.LoggregatorEndpoint - }) - return -} - func (c *cfConfig) UAAEndpoint() (endpoint string) { c.read(func() { endpoint = c.data.UaaEndpoint @@ -356,12 +347,6 @@ func (c *cfConfig) SetAuthenticationEndpoint(endpoint string) { }) } -func (c *cfConfig) SetLoggregatorEndpoint(endpoint string) { - c.write(func() { - c.data.LoggregatorEndpoint = endpoint - }) -} - func (c *cfConfig) SetDopplerEndpoint(endpoint string) { c.write(func() { c.data.DopplerEndpoint = endpoint @@ -455,7 +440,6 @@ func (c *cfConfig) UnsetAPI() { c.data.AuthorizationEndpoint = "" c.data.UaaEndpoint = "" c.data.RoutingAPIEndpoint = "" - c.data.LoggregatorEndpoint = "" c.data.DopplerEndpoint = "" }) } diff --git a/bluemix/configuration/core_config/cf_config_test.go b/bluemix/configuration/core_config/cf_config_test.go new file mode 100644 index 00000000..d47d6cb2 --- /dev/null +++ b/bluemix/configuration/core_config/cf_config_test.go @@ -0,0 +1,140 @@ +package core_config_test + +import ( + "testing" + + "github.com/IBM-Cloud/ibm-cloud-cli-sdk/bluemix/configuration/core_config" + "github.com/stretchr/testify/assert" +) + +func TestNewConfig(t *testing.T) { + c := core_config.NewCFConfigData() + + assert.Equal(t, "cf", c.UAAOAuthClient) + assert.Equal(t, "", c.UAAOAuthClientSecret) + +} + +var v4JSON = `{ + "AccessToken": "foo", + "APIVersion": "5", + "AsyncTimeout": 0, + "AuthorizationEndpoint": "iam.test.cloud.ibm.com", + "ColorEnabled": "", + "ConfigVersion": 4, + "DopplerEndpoint": "", + "Locale": "", + "LogCacheEndPoint": "", + "MinCLIVersion": "", + "MinRecommendedCLIVersion": "", + "OrganizationFields": { + "GUID": "", + "Name": "", + "QuotaDefinition": { + "name": "", + "memory_limit": 0, + "instance_memory_limit": 0, + "total_routes": 0, + "total_services": 0, + "non_basic_services_allowed": false, + "app_instance_limit": 0 + } + }, + "PluginRepos": null, + "RefreshToken": "", + "RoutingAPIEndpoint": "", + "SpaceFields": { + "GUID": "", + "Name": "", + "AllowSSH": false + }, + "SSHOAuthClient": "", + "SSLDisabled": false, + "Target": "", + "Trace": "", + "UaaEndpoint": "", + "LoginAt": "0001-01-01T00:00:00Z", + "UAAGrantType": "", + "UAAOAuthClient": "cf", + "UAAOAuthClientSecret": "" +}` + +func TestMarshal(t *testing.T) { + c := core_config.NewCFConfigData() + c.APIVersion = "5" + c.AccessToken = "foo" + c.AuthorizationEndpoint = "iam.test.cloud.ibm.com" + + bytes, err := c.Marshal() + assert.NoError(t, err) + assert.Equal(t, string(bytes), v4JSON) +} + +func TestUnmarshalV3(t *testing.T) { + c := core_config.NewCFConfigData() + assert.NoError(t, c.Unmarshal([]byte(v4JSON))) + + assert.Equal(t, 4, c.ConfigVersion) + assert.Equal(t, "5", c.APIVersion) + assert.Equal(t, "foo", c.AccessToken) + assert.Equal(t, "iam.test.cloud.ibm.com", c.AuthorizationEndpoint) +} + +func TestUnmarshalV4(t *testing.T) { + var v3JSON = `{ + "AccessToken": "bar", + "APIVersion": "4", + "AsyncTimeout": 0, + "AuthorizationEndpoint": "iam.test.cloud.ibm.com", + "ColorEnabled": "", + "ConfigVersion": 3, + "DopplerEndpoint": "", + "Locale": "", + "LogCacheEndPoint": "", + "MinCLIVersion": "", + "MinRecommendedCLIVersion": "", + "OrganizationFields": { + "GUID": "", + "Name": "", + "QuotaDefinition": { + "name": "", + "memory_limit": 0, + "instance_memory_limit": 0, + "total_routes": 0, + "total_services": 0, + "non_basic_services_allowed": false, + "app_instance_limit": 0 + } + }, + "PluginRepos": null, + "RefreshToken": "", + "RoutingAPIEndpoint": "", + "SpaceFields": { + "GUID": "", + "Name": "", + "AllowSSH": false + }, + "SSHOAuthClient": "", + "SSLDisabled": false, + "Target": "", + "Trace": "", + "UaaEndpoint": "", + "LoginAt": "0001-01-01T00:00:00Z", + "UAAGrantType": "", + "UAAOAuthClient": "cf", + "UAAOAuthClientSecret": "" +}` + + c := core_config.NewCFConfigData() + assert.NoError(t, c.Unmarshal([]byte(v3JSON))) + + assert.Equal(t, 3, c.ConfigVersion) + assert.Equal(t, "4", c.APIVersion) + assert.Equal(t, "bar", c.AccessToken) + assert.Equal(t, "iam.test.cloud.ibm.com", c.AuthorizationEndpoint) +} + +func TestUnmarshalError(t *testing.T) { + c := core_config.NewCFConfigData() + assert.Error(t, c.Unmarshal([]byte(`{"db":cf}`))) +} diff --git a/bluemix/configuration/core_config/repository.go b/bluemix/configuration/core_config/repository.go index 17191485..fbee2307 100644 --- a/bluemix/configuration/core_config/repository.go +++ b/bluemix/configuration/core_config/repository.go @@ -106,7 +106,6 @@ type CFConfig interface { HasAPIEndpoint() bool AuthenticationEndpoint() string UAAEndpoint() string - LoggregatorEndpoint() string DopplerEndpoint() string RoutingAPIEndpoint() string SSHOAuthClient() string @@ -129,7 +128,6 @@ type CFConfig interface { SetAPIVersion(string) SetAPIEndpoint(string) SetAuthenticationEndpoint(string) - SetLoggregatorEndpoint(string) SetDopplerEndpoint(string) SetUAAEndpoint(string) SetRoutingAPIEndpoint(string)