Skip to content

Commit

Permalink
Add update workspace integration with houston
Browse files Browse the repository at this point in the history
  • Loading branch information
andscoop committed Jul 9, 2018
1 parent 79202e0 commit e8be215
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 6 deletions.
1 change: 0 additions & 1 deletion auth/auth.go
Expand Up @@ -97,6 +97,5 @@ func Login(oAuthOnly bool) error {

// Logout logs a user out of the docker registry. Will need to logout of Houston next.
func Logout() {
// forget jwt
config.CFG.CloudAPIToken.SetProjectString("")
}
16 changes: 12 additions & 4 deletions cmd/workspace.go
Expand Up @@ -6,7 +6,8 @@ import (
)

var (
createDesc string
workspaceUpdateAttrs = []string{"label"}
createDesc string

workspaceRootCmd = &cobra.Command{
Use: "workspace",
Expand Down Expand Up @@ -46,7 +47,10 @@ var (
Aliases: []string{"up"},
Short: "Update an Astronomer workspace",
Long: "Update a workspace name, as well as users and roles assigned to a workspace",
RunE: workspaceUpdate,
Args: func(cmd *cobra.Command, args []string) error {
return updateArgValidator(args[1:], workspaceUpdateAttrs)
},
RunE: workspaceUpdate,
}

workspaceUserRootCmd = &cobra.Command{
Expand Down Expand Up @@ -116,9 +120,13 @@ func workspaceDelete(cmd *cobra.Command, args []string) error {
return workspace.Delete(args[0])
}

// TODO
func workspaceUpdate(cmd *cobra.Command, args []string) error {
return nil
argsMap, err := argsToMap(args[1:])
if err != nil {
return err
}

return workspace.Update(args[0], argsMap)
}

func workspaceUserAdd(cmd *cobra.Command, args []string) error {
Expand Down
24 changes: 23 additions & 1 deletion houston/houston.go
Expand Up @@ -202,6 +202,18 @@ var (
}
}`

workspaceUpdateRequest = `
mutation UpdateWorkspace {
updateWorkspace(workspaceUuid:"%s",
payload: %s
) {
uuid
description
label
active
}
}`

workspaceUserAddRequest = `
mutation AddWorkspaceUser {
workspaceAddUser(
Expand Down Expand Up @@ -479,11 +491,21 @@ func (c *Client) RemoveWorkspaceUser(workspaceId, email string) (*Workspace, err
func (c *Client) UpdateDeployment(deploymentId, jsonPayload string) (*Deployment, error) {
request := fmt.Sprintf(deploymentUpdateRequest, deploymentId, jsonPayload)

fmt.Println(request)
response, err := c.QueryHouston(request)
if err != nil {
return nil, errors.Wrap(err, "UpdateDeployment Failed")
}

return response.Data.UpdateDeployment, nil
}

func (c *Client) UpdateWorkspace(workspaceId, jsonPayload string) (*Workspace, error) {
request := fmt.Sprintf(workspaceUpdateRequest, workspaceId, jsonPayload)

response, err := c.QueryHouston(request)
if err != nil {
return nil, errors.Wrap(err, "UpdateWorkspace Failed")
}

return response.Data.UpdateWorkspace, nil
}
1 change: 1 addition & 0 deletions houston/types.go
Expand Up @@ -16,6 +16,7 @@ type HoustonResponse struct {
GetUsers []User `json:"users,omitempty"`
GetWorkspace []Workspace `json:"workspaces,omitempty"`
UpdateDeployment *Deployment `json:"updateDeployment,omitempty`
UpdateWorkspace *Workspace `json:updateWorkspace,omitempty`
} `json:"data"`
Errors []Error `json:"errors,omitempty"`
}
Expand Down
1 change: 1 addition & 0 deletions messages/messages.go
Expand Up @@ -60,6 +60,7 @@ var (
HOUSTON_WORKSPACE_DELETE_SUCCESS = "Succesfully deleted %s (%s)\n"
HOUSTON_WORKSPACE_USER_ADD_SUCCESS = "Successfully added user %s from workspace (%s)\n"
HOUSTON_WORKSPACE_USER_REMOVE_SUCCESS = "Successfully removed user %s from workspace (%s)\n"
HOUSTON_WORKSPACE_UPDATE_SUCCESS = "Successfully updated workspace %s"
HOUSTON_USER_CREATE_SUCCESS = "Successfully created user (%s) with email %s\n"

INPUT_PASSWORD = "Password: "
Expand Down
15 changes: 15 additions & 0 deletions workspace/workspace.go
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/astronomerio/astro-cli/houston"
"github.com/astronomerio/astro-cli/messages"
"github.com/astronomerio/astro-cli/pkg/httputil"
"github.com/astronomerio/astro-cli/pkg/jsonstr"
)

var (
Expand Down Expand Up @@ -48,3 +49,17 @@ func Delete(uuid string) error {
fmt.Printf(messages.HOUSTON_WORKSPACE_DELETE_SUCCESS, ws.Label, ws.Uuid)
return nil
}

// Update an astronomer workspace
func Update(workspaceId string, args map[string]string) error {
s := jsonstr.MapToJsonObjStr(args)

ws, err := api.UpdateWorkspace(workspaceId, s)
if err != nil {
return err
}

fmt.Printf(messages.HOUSTON_WORKSPACE_UPDATE_SUCCESS, ws.Uuid)

return nil
}

0 comments on commit e8be215

Please sign in to comment.