Skip to content

Commit

Permalink
Switch wording from UUID to ID (#184)
Browse files Browse the repository at this point in the history
* Replace UUID to ID

* fix deployment delete
  • Loading branch information
andriisoldatenko authored and schnie committed Mar 4, 2019
1 parent 49d4ba5 commit f0e0ba3
Show file tree
Hide file tree
Showing 13 changed files with 145 additions and 170 deletions.
12 changes: 6 additions & 6 deletions airflow/docker.go
Expand Up @@ -40,7 +40,7 @@ var (
tab = printutil.Table{
Padding: []int{5, 30, 30, 50},
DynamicPadding: true,
Header: []string{"#", "LABEL", "DEPLOYMENT NAME", "WORKSPACE", "DEPLOYMENT UUID"},
Header: []string{"#", "LABEL", "DEPLOYMENT NAME", "WORKSPACE", "DEPLOYMENT ID"},
}
)

Expand Down Expand Up @@ -385,13 +385,13 @@ func PS(airflowHome string) error {
// Deploy pushes a new docker image
func Deploy(path, name, wsId string, prompt bool) error {
if len(wsId) == 0 {
return errors.New("no workspace uuid provided")
return errors.New("no workspace id provided")
}

// Validate workspace
wsReq := houston.Request{
Query: houston.WorkspacesGetRequest,
Variables: map[string]interface{}{"workspaceUuid": wsId},
Variables: map[string]interface{}{"workspaceId": wsId},
}

wsResp, err := wsReq.Do()
Expand All @@ -400,15 +400,15 @@ func Deploy(path, name, wsId string, prompt bool) error {
}

if len(wsResp.Data.GetWorkspaces) == 0 {
return fmt.Errorf("no workspaces with uuid (%s) found", wsId)
return fmt.Errorf("no workspaces with id (%s) found", wsId)
}

w := wsResp.Data.GetWorkspaces[0]

// Get Deployments from workspace UUID
// Get Deployments from workspace ID
deReq := houston.Request{
Query: houston.DeploymentsGetRequest,
Variables: map[string]interface{}{"workspaceUuid": w.Uuid},
Variables: map[string]interface{}{"workspaceId": w.Id},
}

deResp, err := deReq.Do()
Expand Down
4 changes: 2 additions & 2 deletions auth/auth.go
Expand Up @@ -154,8 +154,8 @@ func Login(domain string, oAuthOnly bool) error {

if len(workspaces) == 1 && len(c.Workspace) == 0 {
w := workspaces[0]
c.SetContextKey("workspace", w.Uuid)
fmt.Printf(messages.CONFIG_SET_DEFAULT_WORKSPACE, w.Label, w.Uuid)
c.SetContextKey("workspace", w.Id)
fmt.Printf(messages.CONFIG_SET_DEFAULT_WORKSPACE, w.Label, w.Id)
}

if len(workspaces) != 1 && len(c.Workspace) == 0 {
Expand Down
2 changes: 1 addition & 1 deletion cmd/airflow.go
Expand Up @@ -185,7 +185,7 @@ func airflowInit(cmd *cobra.Command, args []string) error {
fmt.Sprintf("%s \nYou are not in an empty directory. Are you sure you want to initialize a project?", config.WorkingPath))

if !i {
fmt.Println("Cancelling project initialization...\n")
fmt.Println("Cancelling project initialization...")
os.Exit(1)
}
}
Expand Down
47 changes: 23 additions & 24 deletions cmd/serviceaccount.go
Expand Up @@ -7,9 +7,8 @@ import (
)

var (
workspaceUuid string
deploymentUuid string
userUuid string
deploymentId string
userId string
systemSA bool
category string
label string
Expand All @@ -30,7 +29,7 @@ var (
}

saDeleteCmd = &cobra.Command{
Use: "delete [SA-UUID]",
Use: "delete [SA-ID]",
Aliases: []string{"de"},
Short: "Delete a service-account in the astronomer platform",
Long: "Delete a service-account in the astronomer platform",
Expand All @@ -40,8 +39,8 @@ var (

saGetCmd = &cobra.Command{
Use: "get",
Short: "Get a service-account by entity type and entity uuid",
Long: "Get a service-account by entity type and entity uuid",
Short: "Get a service-account by entity type and entity id",
Long: "Get a service-account by entity type and entity id",
RunE: saGet,
}
)
Expand All @@ -52,24 +51,24 @@ func init() {

// Service-account create
saRootCmd.AddCommand(saCreateCmd)
saCreateCmd.Flags().StringVarP(&workspaceUuid, "workspace-uuid", "w", "", "[UUID]")
saCreateCmd.Flags().StringVarP(&deploymentUuid, "deployment-uuid", "d", "", "[UUID]")
saCreateCmd.Flags().StringVarP(&userUuid, "user-uuid", "u", "", "[UUID]")
saCreateCmd.Flags().StringVarP(&workspaceId, "workspace-id", "w", "", "[ID]")
saCreateCmd.Flags().StringVarP(&deploymentId, "deployment-id", "d", "", "[ID]")
saCreateCmd.Flags().StringVarP(&userId, "user-id", "u", "", "[ID]")
saCreateCmd.Flags().BoolVarP(&systemSA, "system-sa", "s", false, "")
saCreateCmd.Flags().StringVarP(&category, "category", "c", "default", "CATEGORY")
saCreateCmd.Flags().StringVarP(&label, "label", "l", "", "LABEL")

saRootCmd.AddCommand(saGetCmd)
saGetCmd.Flags().StringVarP(&workspaceUuid, "workspace-uuid", "w", "", "[UUID]")
saGetCmd.Flags().StringVarP(&deploymentUuid, "deployment-uuid", "d", "", "[UUID]")
saGetCmd.Flags().StringVarP(&userUuid, "user-uuid", "u", "", "[UUID]")
saGetCmd.Flags().StringVarP(&workspaceId, "workspace-id", "w", "", "[ID]")
saGetCmd.Flags().StringVarP(&deploymentId, "deployment-id", "d", "", "[ID]")
saGetCmd.Flags().StringVarP(&userId, "user-id", "u", "", "[ID]")
saGetCmd.Flags().BoolVarP(&systemSA, "system-sa", "s", false, "")

saRootCmd.AddCommand(saDeleteCmd)
}

func getValidEntity() (string, string, error) {
var uuid string
var id string
var entityType string
singleArgVerify := 0

Expand All @@ -78,34 +77,34 @@ func getValidEntity() (string, string, error) {
singleArgVerify++
}

if len(workspaceUuid) > 0 {
if len(workspaceId) > 0 {
entityType = "WORKSPACE"
uuid = workspaceUuid
id = workspaceId
singleArgVerify++
}

if len(deploymentUuid) > 0 {
if len(deploymentId) > 0 {
entityType = "DEPLOYMENT"
uuid = deploymentUuid
id = deploymentId
singleArgVerify++
}

if len(userUuid) > 0 {
if len(userId) > 0 {
entityType = "USER"
uuid = userUuid
id = userId
singleArgVerify++
}

if singleArgVerify != 1 {
return "", "", errors.New("must specify exactly one service-account type (system, workspace deployment, user")
}

return entityType, uuid, nil
return entityType, id, nil
}

func saCreate(cmd *cobra.Command, args []string) error {
// Validation
entityType, uuid, err := getValidEntity()
entityType, id, err := getValidEntity()
if err != nil {
return err
}
Expand All @@ -117,7 +116,7 @@ func saCreate(cmd *cobra.Command, args []string) error {
// Silence Usage as we have now validated command input
cmd.SilenceUsage = true

return sa.Create(uuid, label, category, entityType)
return sa.Create(id, label, category, entityType)
}

func saDelete(cmd *cobra.Command, args []string) error {
Expand All @@ -128,13 +127,13 @@ func saDelete(cmd *cobra.Command, args []string) error {
}

func saGet(cmd *cobra.Command, args []string) error {
entityType, uuid, err := getValidEntity()
entityType, id, err := getValidEntity()
if err != nil {
return err
}

// Silence Usage as we have now validated command input
cmd.SilenceUsage = true

return sa.Get(entityType, uuid)
return sa.Get(entityType, id)
}
6 changes: 3 additions & 3 deletions cmd/workspace.go
Expand Up @@ -187,11 +187,11 @@ func workspaceSwitch(cmd *cobra.Command, args []string) error {
// Silence Usage as we have now validated command input
cmd.SilenceUsage = true

uuid := ""
id := ""

if len(args) == 1 {
uuid = args[0]
id = args[0]
}

return workspace.Switch(uuid)
return workspace.Switch(id)
}
18 changes: 9 additions & 9 deletions deployment/deployment.go
Expand Up @@ -20,7 +20,7 @@ var (
func Create(label, ws string) error {
req := houston.Request{
Query: houston.DeploymentCreateRequest,
Variables: map[string]interface{}{"label": label, "workspaceUuid": ws},
Variables: map[string]interface{}{"label": label, "workspaceId": ws},
}

r, err := req.Do()
Expand All @@ -44,10 +44,10 @@ func Create(label, ws string) error {
return nil
}

func Delete(uuid string) error {
func Delete(id string) error {
req := houston.Request{
Query: houston.DeploymentDeleteRequest,
Variables: map[string]interface{}{"deploymentUuid": uuid},
Variables: map[string]interface{}{"deploymentId": id},
}

_, err := req.Do()
Expand All @@ -56,7 +56,7 @@ func Delete(uuid string) error {
}

// TODO - add back in tab print once houston returns all relevant information
// tab.AddRow([]string{d.Label, d.ReleaseName, d.Id, d.Workspace.Uuid}, false)
// tab.AddRow([]string{d.Label, d.ReleaseName, d.Id, d.Workspace.Id}, false)
// tab.SuccessMsg = "\n Successfully deleted deployment"
// tab.Print()
fmt.Println("\n Successfully deleted deployment")
Expand All @@ -67,7 +67,7 @@ func Delete(uuid string) error {
// List all airflow deployments
func List(ws string, all bool) error {
var deployments []houston.Deployment
var r *houston.HoustonResponse
var r *houston.Response
var err error

req := houston.Request{
Expand All @@ -80,7 +80,7 @@ func List(ws string, all bool) error {
return err
}
} else {
req.Variables = map[string]interface{}{"workspaceUuid": ws}
req.Variables = map[string]interface{}{"workspaceId": ws}
r, err = req.Do()
if err != nil {
return err
Expand All @@ -94,7 +94,7 @@ func List(ws string, all bool) error {
// Build rows
for _, d := range deployments {
if all {
ws = d.Workspace.Uuid
ws = d.Workspace.Id
}
tab.AddRow([]string{d.Label, d.ReleaseName, "v" + d.Version, d.Id}, false)
}
Expand All @@ -105,10 +105,10 @@ func List(ws string, all bool) error {
}

// Update an airflow deployment
func Update(uuid string, args map[string]string) error {
func Update(id string, args map[string]string) error {
req := houston.Request{
Query: houston.DeploymentUpdateRequest,
Variables: map[string]interface{}{"deploymentUuid": uuid, "payload": args},
Variables: map[string]interface{}{"deploymentId": id, "payload": args},
}

r, err := req.Do()
Expand Down
6 changes: 3 additions & 3 deletions houston/houston.go
Expand Up @@ -39,7 +39,7 @@ type Request struct {
}

// Do (request) is a wrapper to more easily pass variables to a client.Do request
func (r *Request) Do() (*HoustonResponse, error) {
func (r *Request) Do() (*Response, error) {
api := NewHoustonClient(httputil.NewHTTPClient())

doOpts := httputil.DoOptions{
Expand All @@ -53,7 +53,7 @@ func (r *Request) Do() (*HoustonResponse, error) {
}

// Do executes a query against the Houston API, logging out any errors contained in the response object
func (c *Client) Do(doOpts httputil.DoOptions) (*HoustonResponse, error) {
func (c *Client) Do(doOpts httputil.DoOptions) (*Response, error) {
cl, err := cluster.GetCurrentCluster()
if err != nil {
return nil, err
Expand Down Expand Up @@ -81,7 +81,7 @@ func (c *Client) Do(doOpts httputil.DoOptions) (*HoustonResponse, error) {
Raw: httpResponse,
Body: string(body),
}
decode := HoustonResponse{}
decode := Response{}
err = json.NewDecoder(strings.NewReader(response.Body)).Decode(&decode)
if err != nil {
return nil, errors.Wrap(err, "Failed to JSON decode Houston response")
Expand Down

0 comments on commit f0e0ba3

Please sign in to comment.