Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into feature/SCALRCORE-…
Browse files Browse the repository at this point in the history
…26173
  • Loading branch information
soltysss committed Jun 13, 2023
2 parents e4cd75d + f8be8d1 commit 6822e5d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
33 changes: 25 additions & 8 deletions environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
Expand All @@ -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"`
Expand Down Expand Up @@ -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"`

Expand Down Expand Up @@ -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.
Expand All @@ -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) {
Expand Down
2 changes: 0 additions & 2 deletions vcs_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 6822e5d

Please sign in to comment.