Skip to content

Commit

Permalink
Feat: user role environment assignment (#660)
Browse files Browse the repository at this point in the history
* Feat: user role environment assignment

* added more tests and code

* added example

* minor fixes based on PR comments

* minor fixes based on PR comments
  • Loading branch information
TomerHeber authored Jun 21, 2023
1 parent e7fb3b7 commit 0e5ca5f
Show file tree
Hide file tree
Showing 50 changed files with 673 additions and 55 deletions.
3 changes: 3 additions & 0 deletions client/api_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ type ApiClientInterface interface {
ProviderDelete(providerId string) error
ProviderUpdate(providerId string, payload ProviderUpdatePayload) (*Provider, error)
Providers() ([]Provider, error)
AssignUserRoleToEnvironment(payload *AssignUserRoleToEnvironmentPayload) (*UserRoleEnvironmentAssignment, error)
RemoveUserRoleFromEnvironment(environmentId string, userId string) error
UserRoleEnvironmentAssignments(environmentId string) ([]UserRoleEnvironmentAssignment, error)
}

func NewApiClient(client http.HttpClientInterface, defaultOrganizationId string) ApiClientInterface {
Expand Down
44 changes: 44 additions & 0 deletions client/api_client_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion client/api_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (client *ApiClient) ApiKeyCreate(payload ApiKeyCreatePayload) (*ApiKey, err
}

func (client *ApiClient) ApiKeyDelete(id string) error {
return client.http.Delete("/api-keys/" + id)
return client.http.Delete("/api-keys/"+id, nil)
}

func (client *ApiClient) ApiKeys() ([]ApiKey, error) {
Expand Down
2 changes: 1 addition & 1 deletion client/api_key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ var _ = Describe("ApiKey Client", func() {

Describe("Delete ApiKey", func() {
BeforeEach(func() {
httpCall = mockHttpClient.EXPECT().Delete("/api-keys/" + mockApiKey.Id)
httpCall = mockHttpClient.EXPECT().Delete("/api-keys/"+mockApiKey.Id, nil)
apiClient.ApiKeyDelete(mockApiKey.Id)
})

Expand Down
2 changes: 1 addition & 1 deletion client/cloud_credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,5 +151,5 @@ func (client *ApiClient) CredentialsCreate(request CredentialCreatePayload) (Cre
}

func (client *ApiClient) CloudCredentialsDelete(id string) error {
return client.http.Delete("/credentials/" + id)
return client.http.Delete("/credentials/"+id, nil)
}
2 changes: 1 addition & 1 deletion client/cloud_credentials_project_assignment.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func (client *ApiClient) AssignCloudCredentialsToProject(projectId string, crede
}

func (client *ApiClient) RemoveCloudCredentialsFromProject(projectId string, credentialId string) error {
return client.http.Delete("/credentials/deployment/" + credentialId + "/project/" + projectId)
return client.http.Delete("/credentials/deployment/"+credentialId+"/project/"+projectId, nil)
}

func (client *ApiClient) CloudCredentialIdsInProject(projectId string) ([]string, error) {
Expand Down
2 changes: 1 addition & 1 deletion client/cloud_credentials_project_assignment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ var _ = Describe("Credentials Project Assignment", func() {
var actualError error
BeforeEach(func() {
httpCall = mockHttpClient.EXPECT().
Delete("/credentials/deployment/" + credentialId + "/project/" + projectId).
Delete("/credentials/deployment/"+credentialId+"/project/"+projectId, nil).
Return(errors.New(errorInfo)).
Times(1)
actualError = apiClient.RemoveCloudCredentialsFromProject(projectId, credentialId)
Expand Down
2 changes: 1 addition & 1 deletion client/cloud_credentials_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ var _ = Describe("CloudCredentials", func() {

Describe("CloudCredentialsDelete", func() {
BeforeEach(func() {
httpCall = mockHttpClient.EXPECT().Delete("/credentials/" + mockCredentials.Id)
httpCall = mockHttpClient.EXPECT().Delete("/credentials/"+mockCredentials.Id, nil)
apiClient.CloudCredentialsDelete(mockCredentials.Id)
})

Expand Down
2 changes: 1 addition & 1 deletion client/configuration_variable.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func getSchema(params ConfigurationVariableCreateParams) map[string]interface{}
}

func (client *ApiClient) ConfigurationVariableDelete(id string) error {
return client.http.Delete("configuration/" + id)
return client.http.Delete("configuration/"+id, nil)
}

func (client *ApiClient) ConfigurationVariableUpdate(updateParams ConfigurationVariableUpdateParams) (ConfigurationVariable, error) {
Expand Down
2 changes: 1 addition & 1 deletion client/configuration_variable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ var _ = Describe("Configuration Variable", func() {

Describe("ConfigurationVariableDelete", func() {
BeforeEach(func() {
httpCall = mockHttpClient.EXPECT().Delete("configuration/" + mockConfigurationVariable.Id)
httpCall = mockHttpClient.EXPECT().Delete("configuration/"+mockConfigurationVariable.Id, nil)
apiClient.ConfigurationVariableDelete(mockConfigurationVariable.Id)
})

Expand Down
2 changes: 1 addition & 1 deletion client/cost_credentials_project_assignment.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func (client *ApiClient) AssignCostCredentialsToProject(projectId string, creden
}

func (client *ApiClient) RemoveCostCredentialsFromProject(projectId string, credentialId string) error {
return client.http.Delete("/costs/project/" + projectId + "/credentials/" + credentialId)
return client.http.Delete("/costs/project/"+projectId+"/credentials/"+credentialId, nil)
}

func (client *ApiClient) CostCredentialIdsInProject(projectId string) ([]CostCredentialProjectAssignment, error) {
Expand Down
2 changes: 1 addition & 1 deletion client/cost_credentials_project_assignment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ var _ = Describe(" Cost Credentials Project Assignment", func() {
var actualError error
BeforeEach(func() {
httpCall = mockHttpClient.EXPECT().
Delete("/costs/project/" + projectId + "/credentials/" + credentialId).
Delete("/costs/project/"+projectId+"/credentials/"+credentialId, nil).
Return(errors.New(errorInfo)).
Times(1)
actualError = apiClient.RemoveCostCredentialsFromProject(projectId, credentialId)
Expand Down
2 changes: 1 addition & 1 deletion client/custom_flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (client *ApiClient) CustomFlow(id string) (*CustomFlow, error) {
}

func (client *ApiClient) CustomFlowDelete(id string) error {
return client.http.Delete("/custom-flow/" + id)
return client.http.Delete("/custom-flow/"+id, nil)
}

func (client *ApiClient) CustomFlowUpdate(id string, payload CustomFlowCreatePayload) (*CustomFlow, error) {
Expand Down
2 changes: 1 addition & 1 deletion client/custom_flow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ var _ = Describe("Custom Flow Client", func() {

Describe("Delete Custom Flow", func() {
BeforeEach(func() {
httpCall = mockHttpClient.EXPECT().Delete("/custom-flow/" + mockCustomFlow.Id)
httpCall = mockHttpClient.EXPECT().Delete("/custom-flow/"+mockCustomFlow.Id, nil)
httpCall.Times(1)
apiClient.CustomFlowDelete(mockCustomFlow.Id)
})
Expand Down
2 changes: 1 addition & 1 deletion client/git_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (client *ApiClient) GitToken(id string) (*GitToken, error) {
}

func (client *ApiClient) GitTokenDelete(id string) error {
return client.http.Delete("/tokens/" + id)
return client.http.Delete("/tokens/"+id, nil)
}

func (client *ApiClient) GitTokens() ([]GitToken, error) {
Expand Down
2 changes: 1 addition & 1 deletion client/git_token_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ var _ = Describe("GitToken Client", func() {

Describe("Delete GitToken", func() {
BeforeEach(func() {
httpCall = mockHttpClient.EXPECT().Delete("/tokens/" + mockGitToken.Id)
httpCall = mockHttpClient.EXPECT().Delete("/tokens/"+mockGitToken.Id, nil)
apiClient.GitTokenDelete(mockGitToken.Id)
})

Expand Down
2 changes: 1 addition & 1 deletion client/gpg_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (client *ApiClient) GpgKeyCreate(payload *GpgKeyCreatePayload) (*GpgKey, er
}

func (client *ApiClient) GpgKeyDelete(id string) error {
return client.http.Delete("/gpg-keys/" + id)
return client.http.Delete("/gpg-keys/"+id, nil)
}

func (client *ApiClient) GpgKeys() ([]GpgKey, error) {
Expand Down
2 changes: 1 addition & 1 deletion client/gpg_key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ var _ = Describe("Gpg Token Client", func() {
var err error

BeforeEach(func() {
mockHttpClient.EXPECT().Delete("/gpg-keys/" + mockGpgKey.Id)
mockHttpClient.EXPECT().Delete("/gpg-keys/"+mockGpgKey.Id, nil)
err = apiClient.GpgKeyDelete(mockGpgKey.Id)
})

Expand Down
6 changes: 3 additions & 3 deletions client/http/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type HttpClientInterface interface {
Get(path string, params map[string]string, response interface{}) error
Post(path string, request interface{}, response interface{}) error
Put(path string, request interface{}, response interface{}) error
Delete(path string) error
Delete(path string, params map[string]string) error
Patch(path string, request interface{}, response interface{}) error
}

Expand Down Expand Up @@ -83,8 +83,8 @@ func (client *HttpClient) Get(path string, params map[string]string, response in
return client.httpResult(result, err)
}

func (client *HttpClient) Delete(path string) error {
result, err := client.request().Delete(path)
func (client *HttpClient) Delete(path string, params map[string]string) error {
result, err := client.request().SetQueryParams(params).Delete(path)
return client.httpResult(result, err)
}

Expand Down
8 changes: 4 additions & 4 deletions client/http/client_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions client/http/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,15 +189,15 @@ var _ = Describe("Http Client", func() {

Describe("Delete", func() {
It("2XX response", func() {
var err = httpclient.Delete(successURI)
var err = httpclient.Delete(successURI, nil)

AssertHttpCall("DELETE", successUrl)
AssertNoError(err)
AssertAuth()
})

It("5XX response", func() {
var err = httpclient.Delete(failureURI)
var err = httpclient.Delete(failureURI, nil)

AssertHttpCall("DELETE", failureUrl)
AssertError(err)
Expand Down
2 changes: 1 addition & 1 deletion client/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (client *ApiClient) Module(id string) (*Module, error) {
}

func (client *ApiClient) ModuleDelete(id string) error {
return client.http.Delete("/modules/" + id)
return client.http.Delete("/modules/"+id, nil)
}

func (client *ApiClient) ModuleUpdate(id string, payload ModuleUpdatePayload) (*Module, error) {
Expand Down
2 changes: 1 addition & 1 deletion client/module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ var _ = Describe("Module Client", func() {

Describe("Delete Module", func() {
BeforeEach(func() {
httpCall = mockHttpClient.EXPECT().Delete("/modules/" + mockModule.Id)
httpCall = mockHttpClient.EXPECT().Delete("/modules/"+mockModule.Id, nil)
apiClient.ModuleDelete(mockModule.Id)
})

Expand Down
2 changes: 1 addition & 1 deletion client/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (client *ApiClient) NotificationCreate(payload NotificationCreatePayload) (
}

func (client *ApiClient) NotificationDelete(id string) error {
if err := client.http.Delete("/notifications/endpoints/" + id); err != nil {
if err := client.http.Delete("/notifications/endpoints/"+id, nil); err != nil {
return err
}
return nil
Expand Down
2 changes: 1 addition & 1 deletion client/notification_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ var _ = Describe("Notification Client", func() {

Describe("NotificationDelete", func() {
BeforeEach(func() {
httpCall = mockHttpClient.EXPECT().Delete("/notifications/endpoints/" + mockNotification.Id)
httpCall = mockHttpClient.EXPECT().Delete("/notifications/endpoints/"+mockNotification.Id, nil)
apiClient.NotificationDelete(mockNotification.Id)
})

Expand Down
2 changes: 1 addition & 1 deletion client/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (client *ApiClient) ProjectCreate(payload ProjectCreatePayload) (Project, e
}

func (client *ApiClient) ProjectDelete(id string) error {
return client.http.Delete("/projects/" + id)
return client.http.Delete("/projects/"+id, nil)
}

func (client *ApiClient) ProjectUpdate(id string, payload ProjectUpdatePayload) (Project, error) {
Expand Down
2 changes: 1 addition & 1 deletion client/project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ var _ = Describe("Project", func() {

Describe("ProjectDelete", func() {
BeforeEach(func() {
httpCall = mockHttpClient.EXPECT().Delete("/projects/" + mockProject.Id)
httpCall = mockHttpClient.EXPECT().Delete("/projects/"+mockProject.Id, nil)
apiClient.ProjectDelete(mockProject.Id)
})

Expand Down
2 changes: 1 addition & 1 deletion client/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (client *ApiClient) Provider(providerId string) (*Provider, error) {
}

func (client *ApiClient) ProviderDelete(providerId string) error {
return client.http.Delete("/providers/" + providerId)
return client.http.Delete("/providers/"+providerId, nil)
}

func (client *ApiClient) ProviderUpdate(providerId string, payload ProviderUpdatePayload) (*Provider, error) {
Expand Down
2 changes: 1 addition & 1 deletion client/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ var _ = Describe("Provider Client", func() {

Describe("Delete Provider", func() {
BeforeEach(func() {
httpCall = mockHttpClient.EXPECT().Delete("/providers/" + mockProvider.Id).Times(1)
httpCall = mockHttpClient.EXPECT().Delete("/providers/"+mockProvider.Id, nil).Times(1)
apiClient.ProviderDelete(mockProvider.Id)
})

Expand Down
2 changes: 1 addition & 1 deletion client/remote_state_access.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ func (client *ApiClient) RemoteStateAccessConfigurationCreate(environmentId stri
}

func (client *ApiClient) RemoteStateAccessConfigurationDelete(environmentId string) error {
return client.http.Delete("/remote-backend/states/" + environmentId + "/access-control")
return client.http.Delete("/remote-backend/states/"+environmentId+"/access-control", nil)
}
2 changes: 1 addition & 1 deletion client/remote_state_access_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ var _ = Describe("RemoteStateAccess", func() {
var err error

BeforeEach(func() {
httpCall = mockHttpClient.EXPECT().Delete("/remote-backend/states/" + environmentId + "/access-control")
httpCall = mockHttpClient.EXPECT().Delete("/remote-backend/states/"+environmentId+"/access-control", nil)
httpCall.Times(1)
err = apiClient.RemoteStateAccessConfigurationDelete(environmentId)
})
Expand Down
2 changes: 1 addition & 1 deletion client/role.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (client *ApiClient) Role(id string) (*Role, error) {
}

func (client *ApiClient) RoleDelete(id string) error {
return client.http.Delete("/roles/" + id)
return client.http.Delete("/roles/"+id, nil)
}

func (client *ApiClient) RoleUpdate(id string, payload RoleUpdatePayload) (*Role, error) {
Expand Down
2 changes: 1 addition & 1 deletion client/role_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ var _ = Describe("Role", func() {

Describe("RoleDelete", func() {
BeforeEach(func() {
httpCall = mockHttpClient.EXPECT().Delete("/roles/" + mockRole.Id)
httpCall = mockHttpClient.EXPECT().Delete("/roles/"+mockRole.Id, nil)
apiClient.RoleDelete(mockRole.Id)
})

Expand Down
2 changes: 1 addition & 1 deletion client/sshkey.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (client *ApiClient) SshKeyCreate(payload SshKeyCreatePayload) (*SshKey, err
}

func (client *ApiClient) SshKeyDelete(id string) error {
return client.http.Delete("/ssh-keys/" + id)
return client.http.Delete("/ssh-keys/"+id, nil)
}

func (client *ApiClient) SshKeys() ([]SshKey, error) {
Expand Down
Loading

0 comments on commit 0e5ca5f

Please sign in to comment.