From dbeba017b92e04ccd8f2ba3b75c5295c0d253f69 Mon Sep 17 00:00:00 2001 From: Tomer Heber Date: Wed, 22 May 2024 07:49:20 -0500 Subject: [PATCH] Feat: add API calls for configuration set assignment (#857) --- .gitignore | 3 ++ client/api_client.go | 2 ++ client/api_client_mock.go | 28 +++++++++++++++++++ client/configuration_set_assignment.go | 20 +++++++++++++ client/configuration_set_assignment_test.go | 31 +++++++++++++++++++++ 5 files changed, 84 insertions(+) create mode 100644 client/configuration_set_assignment.go create mode 100644 client/configuration_set_assignment_test.go diff --git a/.gitignore b/.gitignore index b942d683..19032aee 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,6 @@ attic .vscode/ .idea/ tf + +# macosx +.DS_Store diff --git a/client/api_client.go b/client/api_client.go index 3396d7f0..4ac95a03 100644 --- a/client/api_client.go +++ b/client/api_client.go @@ -160,6 +160,8 @@ type ApiClientInterface interface { ConfigurationSet(id 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 } func NewApiClient(client http.HttpClientInterface, defaultOrganizationId string) ApiClientInterface { diff --git a/client/api_client_mock.go b/client/api_client_mock.go index e6ed1f07..50e2b20c 100644 --- a/client/api_client_mock.go +++ b/client/api_client_mock.go @@ -230,6 +230,20 @@ 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() @@ -2089,6 +2103,20 @@ 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/configuration_set_assignment.go b/client/configuration_set_assignment.go new file mode 100644 index 00000000..1d466e75 --- /dev/null +++ b/client/configuration_set_assignment.go @@ -0,0 +1,20 @@ +package client + +import ( + "fmt" + "strings" +) + +func (client *ApiClient) AssignConfigurationSets(scope string, scopeId string, sets []string) error { + setIds := strings.Join(sets, ",") + url := fmt.Sprintf("/configuration-sets/assignments/%s/%s?setIds=%s", scope, scopeId, setIds) + + return client.http.Post(url, nil, nil) +} + +func (client *ApiClient) UnassignConfigurationSets(scope string, scopeId string, sets []string) error { + setIds := strings.Join(sets, ",") + url := fmt.Sprintf("/configuration-sets/assignments/%s/%s", scope, scopeId) + + return client.http.Delete(url, map[string]string{"setIds": setIds}) +} diff --git a/client/configuration_set_assignment_test.go b/client/configuration_set_assignment_test.go new file mode 100644 index 00000000..4b274f7f --- /dev/null +++ b/client/configuration_set_assignment_test.go @@ -0,0 +1,31 @@ +package client_test + +import ( + . "github.com/onsi/ginkgo" +) + +var _ = Describe("Configuration Set", func() { + scope := "environment" + scopeId := "12345" + setIds := []string{"1", "2", "3"} + + Describe("assign configuration sets", func() { + BeforeEach(func() { + httpCall = mockHttpClient.EXPECT().Post("/configuration-sets/assignments/environment/12345?setIds=1,2,3", nil, nil).Times(1) + apiClient.AssignConfigurationSets(scope, scopeId, setIds) + }) + + It("Should send post request", func() {}) + }) + + Describe("unassign configuration sets", func() { + BeforeEach(func() { + httpCall = mockHttpClient.EXPECT().Delete("/configuration-sets/assignments/environment/12345", map[string]string{ + "setIds": "1,2,3", + }).Times(1) + apiClient.UnassignConfigurationSets(scope, scopeId, setIds) + }) + + It("Should send delete request", func() {}) + }) +})