diff --git a/environment.go b/environment.go index 79cf6e3..a5f87e9 100644 --- a/environment.go +++ b/environment.go @@ -18,6 +18,7 @@ type Environments interface { Read(ctx context.Context, environmentID string) (*Environment, error) Create(ctx context.Context, options EnvironmentCreateOptions) (*Environment, error) Update(ctx context.Context, environmentID string, options EnvironmentUpdateOptions) (*Environment, error) + UpdateDefaultProviderConfigurationOnly(ctx context.Context, environmentID string, options EnvironmentUpdateOptionsDefaultProviderConfigurationOnly) (*Environment, error) Delete(ctx context.Context, environmentID string) error } @@ -35,11 +36,6 @@ const ( EnvironmentStatusInactive EnvironmentStatus = "Inactive" ) -// CloudCredential relationship -type CloudCredential struct { - ID string `jsonapi:"primary,cloud-credentials"` -} - // EnvironmentList represents a list of environments. type EnvironmentList struct { *Pagination @@ -56,7 +52,6 @@ type Environment struct { // Relations Account *Account `jsonapi:"relation,account"` - CloudCredentials []*CloudCredential `jsonapi:"relation,cloud-credentials"` PolicyGroups []*PolicyGroup `jsonapi:"relation,policy-groups"` DefaultProviderConfigurations []*ProviderConfiguration `jsonapi:"relation,default-provider-configurations"` ProviderConfigurations []*ProviderConfiguration `jsonapi:"relation,provider-configurations"` @@ -85,7 +80,6 @@ type EnvironmentCreateOptions struct { // Relations Account *Account `jsonapi:"relation,account"` - CloudCredentials []*CloudCredential `jsonapi:"relation,cloud-credentials,omitempty"` PolicyGroups []*PolicyGroup `jsonapi:"relation,policy-groups,omitempty"` DefaultProviderConfigurations []*ProviderConfiguration `jsonapi:"relation,default-provider-configurations,omitempty"` @@ -192,11 +186,16 @@ type EnvironmentUpdateOptions struct { CostEstimationEnabled *bool `jsonapi:"attr,cost-estimation-enabled,omitempty"` // Relations - CloudCredentials []*CloudCredential `jsonapi:"relation,cloud-credentials"` PolicyGroups []*PolicyGroup `jsonapi:"relation,policy-groups"` DefaultProviderConfigurations []*ProviderConfiguration `jsonapi:"relation,default-provider-configurations"` } +type EnvironmentUpdateOptionsDefaultProviderConfigurationOnly struct { + ID string `jsonapi:"primary,environments"` + // Relations + DefaultProviderConfigurations []*ProviderConfiguration `jsonapi:"relation,default-provider-configurations"` +} + // Update settings of an existing environment. func (s *environments) Update(ctx context.Context, environmentID string, options EnvironmentUpdateOptions) (*Environment, error) { // Make sure we don't send a user provided ID. @@ -217,6 +216,24 @@ func (s *environments) Update(ctx context.Context, environmentID string, options return env, nil } +func (s *environments) UpdateDefaultProviderConfigurationOnly(ctx context.Context, environmentID string, options EnvironmentUpdateOptionsDefaultProviderConfigurationOnly) (*Environment, error) { + options.ID = "" + + u := fmt.Sprintf("environments/%s", url.QueryEscape(environmentID)) + req, err := s.client.newRequest("PATCH", u, &options) + if err != nil { + return nil, err + } + + env := &Environment{} + err = s.client.do(ctx, req, env) + if err != nil { + return nil, err + } + + return env, nil +} + // Delete an environment by its ID. func (s *environments) Delete(ctx context.Context, environmentID string) error { if !validStringID(&environmentID) { diff --git a/vcs_provider_test.go b/vcs_provider_test.go index 1e486ef..93881dd 100644 --- a/vcs_provider_test.go +++ b/vcs_provider_test.go @@ -51,8 +51,6 @@ func TestVCSProvidersList(t *testing.T) { }) t.Run("with invalid environment filter", func(t *testing.T) { - // TODO: remove skip after SCALRCORE-26063 - t.Skip("Default shared VCS providers are returned") response, err := client.VcsProviders.List(ctx, VcsProvidersListOptions{Environment: String(badIdentifier)}) assert.Len(t, response.Items, 0) assert.NoError(t, err)