Skip to content

Commit

Permalink
Add astro workspace user list
Browse files Browse the repository at this point in the history
  • Loading branch information
andriisoldatenko committed May 9, 2019
1 parent 0979517 commit 0e07e2f
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 16 deletions.
10 changes: 10 additions & 0 deletions Makefile
Expand Up @@ -55,3 +55,13 @@ install: build
uninstall:
$(eval DESTDIR ?= $(GOBIN))
rm $(GOBIN)/$(OUTPUT)

ifeq (debug,$(firstword $(MAKECMDGOALS)))
# use the rest as arguments for "debug"
DEBUG_ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS))
$(eval $(DEBUG_ARGS):;@:)
endif

debug:
echo $(RUN_ARGS)
dlv debug github.com/astronomer/astro-cli -- $(DEBUG_ARGS)
6 changes: 5 additions & 1 deletion cmd/workspace.go
Expand Up @@ -209,5 +209,9 @@ func workspaceSwitch(cmd *cobra.Command, args []string) error {
}

func workspaceUserList(cmd *cobra.Command, args []string) error {
return workspace.ListRoles()
ws, err := coalesceWorkspace()
if err != nil {
return errors.Wrap(err, "failed to find a valid workspace")
}
return workspace.ListRoles(ws)
}
15 changes: 7 additions & 8 deletions houston/queries.go
@@ -1,6 +1,5 @@
package houston


var (
AuthConfigGetRequest = `
query GetAuthConfig($redirect: String) {
Expand Down Expand Up @@ -220,6 +219,13 @@ var (
active
createdAt
updatedAt
roleBindings {
role
user {
id
username
}
}
}
}`

Expand Down Expand Up @@ -299,13 +305,6 @@ var (
updatedAt
}
}`
WorkspaceUserListRolesRequest = `
query GetUserRoles(
) {
getUserRoles(
) {
}
}`
DeploymentLogsGetRequest = `
query GetLogs(
$deploymentId: Uuid!
Expand Down
13 changes: 11 additions & 2 deletions houston/types.go
Expand Up @@ -124,6 +124,14 @@ type User struct {
// profile
}

type RoleBinding struct {
Role string `json:"role"`
User struct {
Id string `json:"id"`
Username string `json:"username"`
} `json:"user"`
}

// Workspace contains all components of an Astronomer Workspace
type Workspace struct {
Id string `json:"id"`
Expand All @@ -132,8 +140,9 @@ type Workspace struct {
Active bool `json:"active"`
Users []User `json:"users"`
// groups
CreatedAt string `json:"createdAt"`
UpdatedAt string `json:"updatedAt"`
CreatedAt string `json:"createdAt"`
UpdatedAt string `json:"updatedAt"`
RoleBindings []RoleBinding `json:"roleBindings"`
}

// DeploymentLog contains all log related to deployment components
Expand Down
24 changes: 19 additions & 5 deletions workspace/user.go
Expand Up @@ -51,14 +51,28 @@ func Remove(workspaceId, email string) error {
return nil
}

func ListRoles() error {
func ListRoles(workspaceId string) error {
req := houston.Request{
Query: houston.WorkspaceUserListRolesRequest,
Variables: map[string]interface{}{},
Query: houston.WorkspacesGetRequest,
Variables: map[string]interface{}{"workspaceId": workspaceId},
}
_, err := req.Do()
r, err := req.Do()

if err != nil {
return err
}
workspace := r.Data.GetWorkspaces[0]

tab := printutil.Table{
Padding: []int{44, 50},
DynamicPadding: true,
Header: []string{"USERNAME", "ID", "ROLE"},
}
for _, role := range workspace.RoleBindings {
var color bool
tab.AddRow([]string{role.User.Username, role.User.Id, role.Role}, color)
}

tab.Print()
return nil
}
}

0 comments on commit 0e07e2f

Please sign in to comment.