/
deployment.go
127 lines (102 loc) · 3.5 KB
/
deployment.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package cmd
import (
"github.com/astronomerio/astro-cli/deployment"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)
var (
allDeployments bool
deploymentUpdateAttrs = []string{"label"}
deploymentRootCmd = &cobra.Command{
Use: "deployment",
Aliases: []string{"de"},
Short: "Manage airflow deployments",
Long: "Deployments are individual Airflow clusters running on an installation of the Astronomer platform.",
}
deploymentCreateCmd = &cobra.Command{
Use: "create DEPLOYMENT",
Aliases: []string{"cr"},
Short: "Create a new Astronomer Deployment",
Long: "Create a new Astronomer Deployment",
Args: cobra.ExactArgs(1),
RunE: deploymentCreate,
}
deploymentDeleteCmd = &cobra.Command{
Use: "delete DEPLOYMENT",
Aliases: []string{"de"},
Short: "Delete an airflow deployment",
Long: "Delete an airflow deployment",
Args: cobra.ExactArgs(1),
RunE: deploymentDelete,
}
deploymentListCmd = &cobra.Command{
Use: "list",
Aliases: []string{"ls"},
Short: "List airflow deployments",
Long: "List airflow deployments",
RunE: deploymentList,
}
deploymentUpdateCmd = &cobra.Command{
Use: "update",
Aliases: []string{"up"},
Short: "Update airflow deployments",
Long: "Update airflow deployments",
Args: func(cmd *cobra.Command, args []string) error {
return updateArgValidator(args[1:], deploymentUpdateAttrs)
},
RunE: deploymentUpdate,
}
)
func init() {
// deployment root
RootCmd.AddCommand(deploymentRootCmd)
deploymentRootCmd.PersistentFlags().StringVar(&workspaceId, "workspace-id", "", "workspace assigned to deployment")
// deploymentRootCmd.Flags().StringVar(&workspaceId, "workspace", "", "workspace assigned to deployment")
// deployment create
deploymentRootCmd.AddCommand(deploymentCreateCmd)
// deployment delete
deploymentRootCmd.AddCommand(deploymentDeleteCmd)
// deployment list
deploymentRootCmd.AddCommand(deploymentListCmd)
deploymentListCmd.Flags().BoolVarP(&allDeployments, "all", "a", false, "Show deployments across all workspaces")
// deployment update
deploymentRootCmd.AddCommand(deploymentUpdateCmd)
}
func deploymentCreate(cmd *cobra.Command, args []string) error {
ws, err := coalesceWorkspace()
if err != nil {
return errors.Wrap(err, "failed to find a valid workspace")
// fmt.Println("Default workspace id not set, set default workspace id or pass a workspace in via the --workspace-id flag")
}
// Silence Usage as we have now validated command input
cmd.SilenceUsage = true
return deployment.Create(args[0], ws)
}
func deploymentDelete(cmd *cobra.Command, args []string) error {
// Silence Usage as we have now validated command input
cmd.SilenceUsage = true
return deployment.Delete(args[0])
}
func deploymentList(cmd *cobra.Command, args []string) error {
ws, err := coalesceWorkspace()
if err != nil {
return errors.Wrap(err, "failed to find a valid workspace")
// fmt.Println("Default workspace id not set, set default workspace id or pass a workspace in via the --workspace-id flag")
}
// Don't validate workspace if viewing all deployments
if allDeployments {
ws = ""
}
// Silence Usage as we have now validated command input
cmd.SilenceUsage = true
return deployment.List(ws, allDeployments)
}
func deploymentUpdate(cmd *cobra.Command, args []string) error {
argsMap, err := argsToMap(args[1:])
if err != nil {
return err
}
// Silence Usage as we have now validated command input
cmd.SilenceUsage = true
return deployment.Update(args[0], argsMap)
}