diff --git a/client/api_client.go b/client/api_client.go index 1e1127f3..3f02d059 100644 --- a/client/api_client.go +++ b/client/api_client.go @@ -152,19 +152,12 @@ type ApiClientInterface interface { TeamRoleAssignments(payload *TeamRoleAssignmentListPayload) ([]TeamRoleAssignmentPayload, error) KubernetesCredentialsCreate(payload *KubernetesCredentialsCreatePayload) (*Credentials, error) KubernetesCredentialsUpdate(id string, payload *KubernetesCredentialsUpdatePayload) (*Credentials, error) - EnvironmentImportCreate(payload *EnvironmentImportCreatePayload) (*EnvironmentImport, error) - EnvironmentImportUpdate(id string, payload *EnvironmentImportUpdatePayload) (*EnvironmentImport, error) - EnvironmentImportGet(id string) (*EnvironmentImport, error) - EnvironmentImportDelete(id string) error ConfigurationSetCreate(payload *CreateConfigurationSetPayload) (*ConfigurationSet, error) ConfigurationSetUpdate(id string, payload *UpdateConfigurationSetPayload) (*ConfigurationSet, error) ConfigurationSet(id string) (*ConfigurationSet, error) ConfigurationSets(scope string, scopeId string) ([]ConfigurationSet, error) ConfigurationSetDelete(id string) error ConfigurationVariablesBySetId(setId string) ([]ConfigurationVariable, error) - AssignConfigurationSets(scope string, scopeId string, sets []string) error - UnassignConfigurationSets(scope string, scopeId string, sets []string) error - ConfigurationSetsAssignments(scope string, scopeId string) ([]ConfigurationSet, error) } func NewApiClient(client http.HttpClientInterface, defaultOrganizationId string) ApiClientInterface { diff --git a/client/api_client_mock.go b/client/api_client_mock.go index 0e8557ae..fd1a98e7 100644 --- a/client/api_client_mock.go +++ b/client/api_client_mock.go @@ -230,20 +230,6 @@ func (mr *MockApiClientInterfaceMockRecorder) AssignCloudCredentialsToProject(ar return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AssignCloudCredentialsToProject", reflect.TypeOf((*MockApiClientInterface)(nil).AssignCloudCredentialsToProject), arg0, arg1) } -// AssignConfigurationSets mocks base method. -func (m *MockApiClientInterface) AssignConfigurationSets(arg0, arg1 string, arg2 []string) error { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "AssignConfigurationSets", arg0, arg1, arg2) - ret0, _ := ret[0].(error) - return ret0 -} - -// AssignConfigurationSets indicates an expected call of AssignConfigurationSets. -func (mr *MockApiClientInterfaceMockRecorder) AssignConfigurationSets(arg0, arg1, arg2 any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AssignConfigurationSets", reflect.TypeOf((*MockApiClientInterface)(nil).AssignConfigurationSets), arg0, arg1, arg2) -} - // AssignCostCredentialsToProject mocks base method. func (m *MockApiClientInterface) AssignCostCredentialsToProject(arg0, arg1 string) (CostCredentialProjectAssignment, error) { m.ctrl.T.Helper() @@ -807,65 +793,6 @@ func (mr *MockApiClientInterfaceMockRecorder) EnvironmentDriftDetection(arg0 any return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "EnvironmentDriftDetection", reflect.TypeOf((*MockApiClientInterface)(nil).EnvironmentDriftDetection), arg0) } -// EnvironmentImportCreate mocks base method. -func (m *MockApiClientInterface) EnvironmentImportCreate(arg0 *EnvironmentImportCreatePayload) (*EnvironmentImport, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "EnvironmentImportCreate", arg0) - ret0, _ := ret[0].(*EnvironmentImport) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// EnvironmentImportCreate indicates an expected call of EnvironmentImportCreate. -func (mr *MockApiClientInterfaceMockRecorder) EnvironmentImportCreate(arg0 any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "EnvironmentImportCreate", reflect.TypeOf((*MockApiClientInterface)(nil).EnvironmentImportCreate), arg0) -} - -// EnvironmentImportDelete mocks base method. -func (m *MockApiClientInterface) EnvironmentImportDelete(arg0 string) error { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "EnvironmentImportDelete", arg0) - ret0, _ := ret[0].(error) - return ret0 -} - -// EnvironmentImportDelete indicates an expected call of EnvironmentImportDelete. -func (mr *MockApiClientInterfaceMockRecorder) EnvironmentImportDelete(arg0 any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "EnvironmentImportDelete", reflect.TypeOf((*MockApiClientInterface)(nil).EnvironmentImportDelete), arg0) -} - -// EnvironmentImportGet mocks base method. -func (m *MockApiClientInterface) EnvironmentImportGet(arg0 string) (*EnvironmentImport, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "EnvironmentImportGet", arg0) - ret0, _ := ret[0].(*EnvironmentImport) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// EnvironmentImportGet indicates an expected call of EnvironmentImportGet. -func (mr *MockApiClientInterfaceMockRecorder) EnvironmentImportGet(arg0 any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "EnvironmentImportGet", reflect.TypeOf((*MockApiClientInterface)(nil).EnvironmentImportGet), arg0) -} - -// EnvironmentImportUpdate mocks base method. -func (m *MockApiClientInterface) EnvironmentImportUpdate(arg0 string, arg1 *EnvironmentImportUpdatePayload) (*EnvironmentImport, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "EnvironmentImportUpdate", arg0, arg1) - ret0, _ := ret[0].(*EnvironmentImport) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// EnvironmentImportUpdate indicates an expected call of EnvironmentImportUpdate. -func (mr *MockApiClientInterfaceMockRecorder) EnvironmentImportUpdate(arg0, arg1 any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "EnvironmentImportUpdate", reflect.TypeOf((*MockApiClientInterface)(nil).EnvironmentImportUpdate), arg0, arg1) -} - // EnvironmentMarkAsArchived mocks base method. func (m *MockApiClientInterface) EnvironmentMarkAsArchived(arg0 string) error { m.ctrl.T.Helper() @@ -2147,20 +2074,6 @@ func (mr *MockApiClientInterfaceMockRecorder) Templates() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Templates", reflect.TypeOf((*MockApiClientInterface)(nil).Templates)) } -// UnassignConfigurationSets mocks base method. -func (m *MockApiClientInterface) UnassignConfigurationSets(arg0, arg1 string, arg2 []string) error { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "UnassignConfigurationSets", arg0, arg1, arg2) - ret0, _ := ret[0].(error) - return ret0 -} - -// UnassignConfigurationSets indicates an expected call of UnassignConfigurationSets. -func (mr *MockApiClientInterfaceMockRecorder) UnassignConfigurationSets(arg0, arg1, arg2 any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UnassignConfigurationSets", reflect.TypeOf((*MockApiClientInterface)(nil).UnassignConfigurationSets), arg0, arg1, arg2) -} - // UnsubscribeWorkflowTrigger mocks base method. func (m *MockApiClientInterface) UnsubscribeWorkflowTrigger(arg0 string, arg1 WorkflowTriggerEnvironments) error { m.ctrl.T.Helper() diff --git a/client/environment_import.go b/client/environment_import.go deleted file mode 100644 index 843a5190..00000000 --- a/client/environment_import.go +++ /dev/null @@ -1,100 +0,0 @@ -package client - -type EnvironmentImport struct { - Id string `json:"id"` - Name string `json:"name"` - OrganizationId string `json:"organizationId"` - Workspace string `json:"workspace"` - Variables []Variable `json:"variables"` - GitConfig GitConfig `json:"gitConfig"` - IacType string `json:"iacType"` // opentofu or terraform - IacVersion string `json:"iacVersion"` -} - -type Variable struct { - Name string `json:"name"` - Value string `json:"value,omitempty"` - IsSensitive bool `json:"isSensitive"` - Type string `json:"type"` // string or JSON -} - -type GitConfig struct { - Path string `json:"path,omitempty"` - Revision string `json:"revision,omitempty"` - Repository string `json:"repository,omitempty"` - Provider string `json:"provider,omitempty"` -} - -type EnvironmentImportCreatePayload struct { - Name string `json:"name,omitempty"` - Workspace string `json:"workspace,omitempty"` - Variables []Variable `json:"variables,omitempty"` - GitConfig GitConfig `json:"gitConfig,omitempty"` - IacType string `json:"iacType,omitempty"` - IacVersion string `json:"iacVersion,omitempty"` -} - -type EnvironmentImportUpdatePayload struct { - Name string `json:"name,omitempty"` - Variables []Variable `json:"variables,omitempty"` - GitConfig GitConfig `json:"gitConfig,omitempty"` - IacType string `json:"iacType,omitempty"` - IacVersion string `json:"iacVersion,omitempty"` -} - -func (client *ApiClient) EnvironmentImportCreate(payload *EnvironmentImportCreatePayload) (*EnvironmentImport, error) { - organizationId, err := client.OrganizationId() - if err != nil { - return nil, err - } - - payloadWithOrganzationId := struct { - OrganizationId string `json:"organizationId"` - EnvironmentImportCreatePayload - }{ - organizationId, - *payload, - } - - var result EnvironmentImport - if err := client.http.Post("/staging-environments", payloadWithOrganzationId, &result); err != nil { - return nil, err - } - - return &result, nil -} - -func (client *ApiClient) EnvironmentImportUpdate(id string, payload *EnvironmentImportUpdatePayload) (*EnvironmentImport, error) { - organizationId, err := client.OrganizationId() - if err != nil { - return nil, err - } - - payloadWithOrganzationId := struct { - OrganizationId string `json:"organizationId"` - EnvironmentImportUpdatePayload - }{ - organizationId, - *payload, - } - - var result EnvironmentImport - if err := client.http.Put("/staging-environments/"+id, payloadWithOrganzationId, &result); err != nil { - return nil, err - } - - return &result, nil -} - -func (client *ApiClient) EnvironmentImportGet(id string) (*EnvironmentImport, error) { - var result EnvironmentImport - if err := client.http.Get("/staging-environments/"+id, nil, &result); err != nil { - return nil, err - } - - return &result, nil -} - -func (client *ApiClient) EnvironmentImportDelete(id string) error { - return client.http.Delete("/environment-imports/"+id, nil) -} diff --git a/client/environment_import_test.go b/client/environment_import_test.go deleted file mode 100644 index 9dc615c4..00000000 --- a/client/environment_import_test.go +++ /dev/null @@ -1,135 +0,0 @@ -package client_test - -import ( - . "github.com/env0/terraform-provider-env0/client" - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" - "go.uber.org/mock/gomock" -) - -var _ = Describe("Environment Import Client", func() { - mockEnvironmentImport := EnvironmentImport{ - Id: "id", - Name: "name", - IacType: "tofu", - IacVersion: "1.0", - Workspace: "workspace", - Variables: []Variable{{ - Name: "name", - Value: "value", - IsSensitive: false, - Type: "string", - }, - }, - } - - Describe("EnvironmentImportGet", func() { - var result *EnvironmentImport - - BeforeEach(func() { - mockHttpClient.EXPECT(). - Get("/staging-environments/"+mockEnvironmentImport.Id, nil, gomock.Any()). - Do(func(path string, request interface{}, response *EnvironmentImport) { - *response = mockEnvironmentImport - }).Times(1) - result, _ = apiClient.EnvironmentImportGet(mockEnvironmentImport.Id) - }) - - It("Should return the environment import", func() { - Expect(*result).To(Equal(mockEnvironmentImport)) - }) - }) - - Describe("EnvironmentImportCreate", func() { - var result *EnvironmentImport - var err error - - BeforeEach(func() { - mockOrganizationIdCall(organizationId).Times(1) - - payload := EnvironmentImportCreatePayload{ - Name: "name", - IacType: "tofu", - IacVersion: "1.0", - Workspace: "workspace", - Variables: []Variable{{ - Name: "name", - Value: "value", - IsSensitive: false, - Type: "string", - }, - }} - - expectedPayload := struct { - OrganizationId string `json:"organizationId"` - EnvironmentImportCreatePayload - }{ - organizationId, - payload, - } - - httpCall = mockHttpClient.EXPECT(). - Post("/staging-environments", expectedPayload, gomock.Any()). - Do(func(path string, request interface{}, response *EnvironmentImport) { - *response = mockEnvironmentImport - }).Times(1) - - result, err = apiClient.EnvironmentImportCreate(&payload) - }) - - It("Should not return error", func() { - Expect(err).To(BeNil()) - }) - - It("Should return the created environment import", func() { - Expect(*result).To(Equal(mockEnvironmentImport)) - }) - }) - - Describe("EnvironmentImportUpdate", func() { - var result *EnvironmentImport - var mockedResponse EnvironmentImport - BeforeEach(func() { - mockOrganizationIdCall(organizationId).Times(1) - payload := EnvironmentImportUpdatePayload{ - Name: "new name", - } - - mockedResponse = mockEnvironmentImport - mockedResponse.Name = payload.Name - - expectedPayload := struct { - OrganizationId string `json:"organizationId"` - EnvironmentImportUpdatePayload - }{ - organizationId, - payload, - } - - httpCall = mockHttpClient.EXPECT(). - Put("/staging-environments/"+mockEnvironmentImport.Id, expectedPayload, gomock.Any()). - Do(func(path string, request interface{}, response *EnvironmentImport) { - *response = mockedResponse - }).Times(1) - - result, _ = apiClient.EnvironmentImportUpdate(mockEnvironmentImport.Id, &payload) - }) - - It("Should return environment import received from API", func() { - Expect(*result).To(Equal(mockedResponse)) - }) - }) - - Describe("EnvironmentImportDelete", func() { - var err error - - BeforeEach(func() { - mockHttpClient.EXPECT().Delete("/environment-imports/"+mockEnvironmentImport.Id, nil).Times(1) - err = apiClient.EnvironmentImportDelete(mockEnvironmentImport.Id) - }) - - It("Should not return error", func() { - Expect(err).To(BeNil()) - }) - }) -})