Skip to content

Commit

Permalink
Added ServiceAccount in workspace rolebinding response and showing it… (
Browse files Browse the repository at this point in the history
#467)

* Added ServiceAccount in workspace rolebinding response and showing it in user list command

* implemented circle ci suggestion

* Reference to SA struct

* Implemented commented changes

* gofumpt

Co-authored-by: Rujhan Arora <rujhanarora@Rujhans-MacBook-Pro.local>
  • Loading branch information
rujhan-arora-astronomer and Rujhan Arora committed Jan 4, 2022
1 parent b77918c commit 563ba28
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 9 deletions.
16 changes: 10 additions & 6 deletions houston/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,12 +399,16 @@ mutation UpdateDeployment($deploymentId: Uuid!, $payload: JSON!, $executor: Exec
createdAt
updatedAt
roleBindings {
role
user {
id
username
}
}
role
user {
id
username
}
serviceAccount {
id
label
}
}
}
}`

Expand Down
3 changes: 2 additions & 1 deletion houston/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,8 @@ type RoleBinding struct {
ID string `json:"id"`
Username string `json:"username"`
} `json:"user"`
Deployment Deployment `json:"deployment"`
ServiceAccount WorkspaceServiceAccount `json:"serviceAccount"`
Deployment Deployment `json:"deployment"`
}

// Workspace contains all components of an Astronomer Workspace
Expand Down
7 changes: 5 additions & 2 deletions workspace/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,12 @@ func ListRoles(workspaceID string, client *houston.Client, out io.Writer) error
for i := range workspace.RoleBindings {
role := workspace.RoleBindings[i]
var color bool
tab.AddRow([]string{role.User.Username, role.User.ID, role.Role}, color)
if role.User.Username != "" {
tab.AddRow([]string{role.User.Username, role.User.ID, role.Role}, color)
} else {
tab.AddRow([]string{role.ServiceAccount.Label, role.ServiceAccount.ID, role.Role}, color)
}
}

tab.Print(out)
return nil
}
Expand Down
67 changes: 67 additions & 0 deletions workspace/user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,73 @@ func TestListRoles(t *testing.T) {
assert.Equal(t, expected, buf.String())
}

func TestListRolesWithServiceAccounts(t *testing.T) {
testUtil.InitTestConfig()
okResponse := `{
"data": {
"workspaces": [
{
"id": "ckbv7zvb100pe0760xp98qnh9",
"label": "w1",
"description": "",
"createdAt": "2020-06-25T20:09:29.917Z",
"updatedAt": "2020-06-25T20:09:29.917Z",
"roleBindings": [
{
"role": "WORKSPACE_ADMIN",
"user": {
"id": "ckbv7zpkh00og0760ki4mhl6r",
"username": "andrii@astronomer.io"
}
},
{
"role": "WORKSPACE_ADMIN",
"serviceAccount": {
"id": "ckxaolfky0822zsvcrgts3c6a",
"label": "WA1"
}
}
]
},
{
"id": "ckbv8pwbq00wk0760us7ktcgd",
"label": "wwww",
"description": "",
"createdAt": "2020-06-25T20:29:44.294Z",
"updatedAt": "2020-06-25T20:29:44.294Z",
"roleBindings": [
{
"role": "WORKSPACE_ADMIN",
"user": {
"id": "ckbv7zpkh00og0760ki4mhl6r",
"username": "andriiii@astronomer.io"
}
}
]
}
]
}
}`
client := testUtil.NewTestClient(func(req *http.Request) *http.Response {
return &http.Response{
StatusCode: 200,
Body: ioutil.NopCloser(bytes.NewBufferString(okResponse)),
Header: make(http.Header),
}
})
api := houston.NewHoustonClient(client)
wsID := "ck1qg6whg001r08691y117hub"

buf := new(bytes.Buffer)
err := ListRoles(wsID, api, buf)
assert.NoError(t, err)
expected := ` USERNAME ID ROLE
andrii@astronomer.io ckbv7zpkh00og0760ki4mhl6r WORKSPACE_ADMIN
WA1 ckxaolfky0822zsvcrgts3c6a WORKSPACE_ADMIN
`
assert.Equal(t, expected, buf.String())
}

func TestListRolesError(t *testing.T) {
testUtil.InitTestConfig()

Expand Down

0 comments on commit 563ba28

Please sign in to comment.