Skip to content

Commit

Permalink
fix for a non system admin user to create a deployment (#594)
Browse files Browse the repository at this point in the history
* fix for a non system admin user to create a deployment

* Changing function arguments

* fix unit tests & linting changes

Co-authored-by: neel-astro <[email protected]>
  • Loading branch information
kushalmalani and neel-astro committed Jun 10, 2022
1 parent 50b270b commit 88a2539
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 36 deletions.
6 changes: 3 additions & 3 deletions astro-client/astro.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type Client interface {
CreateImage(input ImageCreateInput) (*Image, error)
DeployImage(input ImageDeployInput) (*Image, error)
// Cluster
ListClusters(vars map[string]interface{}) ([]Cluster, error)
ListClusters(organizationID string) ([]Cluster, error)
// RuntimeRelease
ListInternalRuntimeReleases() ([]RuntimeRelease, error)
ListPublicRuntimeReleases() ([]RuntimeRelease, error)
Expand Down Expand Up @@ -174,10 +174,10 @@ func (c *HTTPClient) DeployImage(input ImageDeployInput) (*Image, error) {
return resp.Data.DeployImage, nil
}

func (c *HTTPClient) ListClusters(vars map[string]interface{}) ([]Cluster, error) {
func (c *HTTPClient) ListClusters(organizationID string) ([]Cluster, error) {
req := Request{
Query: GetClusters,
Variables: map[string]interface{}{"input": vars},
Variables: map[string]interface{}{"organizationId": organizationID},
}

resp, err := req.DoWithClient(c)
Expand Down
4 changes: 2 additions & 2 deletions astro-client/astro_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ func TestListClusters(t *testing.T) {
})
astroClient := NewAstroClient(client)

resp, err := astroClient.ListClusters(map[string]interface{}{})
resp, err := astroClient.ListClusters("test-org-id")
assert.NoError(t, err)
assert.Equal(t, resp, mockResponse.Data.GetClusters)
})
Expand All @@ -607,7 +607,7 @@ func TestListClusters(t *testing.T) {
})
astroClient := NewAstroClient(client)

_, err := astroClient.ListClusters(map[string]interface{}{})
_, err := astroClient.ListClusters("test-org-id")
assert.Contains(t, err.Error(), "Internal Server Error")
})
}
Expand Down
46 changes: 23 additions & 23 deletions astro-client/mocks/Client.go

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

3 changes: 1 addition & 2 deletions cloud/deployment/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,7 @@ func selectCluster(clusterID, organizationID string, client astro.Client) (newCl
Header: []string{"#", "CLUSTER NAME", "CLOUD PROVIDER", "CLUSTER ID"},
}
// cluster request
clusterInput := map[string]interface{}{"organizationId": organizationID}
cs, err := client.ListClusters(clusterInput)
cs, err := client.ListClusters(organizationID)
if err != nil {
return "", errors.Wrap(err, astro.AstronomerConnectionErrMsg)
}
Expand Down
10 changes: 5 additions & 5 deletions cloud/deployment/deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func TestCreate(t *testing.T) {
mockClient := new(astro_mocks.Client)
mockClient.On("GetDeploymentConfig").Return(astro.DeploymentConfig{RuntimeReleases: []astro.RuntimeRelease{{Version: "4.2.5"}}}, nil).Once()
mockClient.On("ListWorkspaces").Return([]astro.Workspace{{ID: ws, OrganizationID: "test-org-id"}}, nil).Once()
mockClient.On("ListClusters", map[string]interface{}{"organizationId": "test-org-id"}).Return([]astro.Cluster{{ID: csID}}, nil).Once()
mockClient.On("ListClusters", "test-org-id").Return([]astro.Cluster{{ID: csID}}, nil).Once()
mockClient.On("CreateDeployment", mock.Anything).Return(astro.Deployment{ID: "test-id"}, nil).Once()

// mock os.Stdin
Expand Down Expand Up @@ -266,7 +266,7 @@ func TestSelectCluster(t *testing.T) {
csID := "test-cluster-id"
t.Run("list cluster failure", func(t *testing.T) {
mockClient := new(astro_mocks.Client)
mockClient.On("ListClusters", map[string]interface{}{"organizationId": orgID}).Return([]astro.Cluster{}, errMock).Once()
mockClient.On("ListClusters", orgID).Return([]astro.Cluster{}, errMock).Once()

_, err := selectCluster("", orgID, mockClient)
assert.ErrorIs(t, err, errMock)
Expand All @@ -275,7 +275,7 @@ func TestSelectCluster(t *testing.T) {

t.Run("cluster id via selection", func(t *testing.T) {
mockClient := new(astro_mocks.Client)
mockClient.On("ListClusters", map[string]interface{}{"organizationId": orgID}).Return([]astro.Cluster{{ID: csID}}, nil).Once()
mockClient.On("ListClusters", orgID).Return([]astro.Cluster{{ID: csID}}, nil).Once()

// mock os.Stdin
input := []byte("1")
Expand All @@ -300,7 +300,7 @@ func TestSelectCluster(t *testing.T) {

t.Run("cluster id invalid selection", func(t *testing.T) {
mockClient := new(astro_mocks.Client)
mockClient.On("ListClusters", map[string]interface{}{"organizationId": orgID}).Return([]astro.Cluster{{ID: csID}}, nil).Once()
mockClient.On("ListClusters", orgID).Return([]astro.Cluster{{ID: csID}}, nil).Once()

// mock os.Stdin
input := []byte("4")
Expand All @@ -324,7 +324,7 @@ func TestSelectCluster(t *testing.T) {

t.Run("not able to find cluster", func(t *testing.T) {
mockClient := new(astro_mocks.Client)
mockClient.On("ListClusters", map[string]interface{}{"organizationId": orgID}).Return([]astro.Cluster{{ID: csID}}, nil).Once()
mockClient.On("ListClusters", orgID).Return([]astro.Cluster{{ID: csID}}, nil).Once()

_, err := selectCluster("test-invalid-id", orgID, mockClient)
assert.Error(t, err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/cloud/deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func TestDeploymentCreate(t *testing.T) {
mockClient := new(astro_mocks.Client)
mockClient.On("GetDeploymentConfig").Return(astro.DeploymentConfig{RuntimeReleases: []astro.RuntimeRelease{{Version: "4.2.5"}}}, nil).Once()
mockClient.On("ListWorkspaces").Return([]astro.Workspace{{ID: ws, OrganizationID: "test-org-id"}}, nil).Once()
mockClient.On("ListClusters", map[string]interface{}{"organizationId": "test-org-id"}).Return([]astro.Cluster{{ID: csID}}, nil).Once()
mockClient.On("ListClusters", "test-org-id").Return([]astro.Cluster{{ID: csID}}, nil).Once()
mockClient.On("CreateDeployment", mock.Anything).Return(astro.Deployment{ID: "test-id"}, nil).Once()
astroClient = mockClient

Expand Down

0 comments on commit 88a2539

Please sign in to comment.