-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.go
More file actions
165 lines (159 loc) · 4.34 KB
/
main.go
File metadata and controls
165 lines (159 loc) · 4.34 KB
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
package main
import (
"context"
"log"
"os"
"github.com/dpc-sdp/bay-cli/cmd/kms"
cli "github.com/urfave/cli/v3"
deployment "github.com/dpc-sdp/bay-cli/cmd/deployment"
elastic_cloud "github.com/dpc-sdp/bay-cli/cmd/elastic-cloud"
project_map "github.com/dpc-sdp/bay-cli/cmd/project-map"
)
const (
EnvLagoonProject = "LAGOON_PROJECT"
EnvLagoonEnvironmentType = "LAGOON_ENVIRONMENT_TYPE"
)
func main() {
app := &cli.Command{
Name: "bay",
Usage: "CLI tool to interact with the Bay container platform",
Commands: []*cli.Command{
{
Name: "kms",
Usage: "interact with KMS encryption service",
Commands: []*cli.Command{
{
Name: "encrypt",
Usage: "encrypt data",
UsageText: "cat file.pem | bay kms encrypt > file.pem.asc",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "project",
Usage: "Name of lagoon project",
Sources: cli.EnvVars(EnvLagoonProject),
Required: true,
},
&cli.StringFlag{
Name: "key",
Usage: "Name of key",
Sources: cli.EnvVars(EnvLagoonEnvironmentType),
Required: true,
},
},
Action: kms.Encrypt,
},
{
Name: "decrypt",
Usage: "decrypt a file",
UsageText: "cat file.pem.asc | bay kms decrypt > file.pem",
Action: kms.Decrypt,
},
},
},
{
Name: "project-map",
Usage: "commands to show relationships between projects",
Commands: []*cli.Command{
{
Name: "by-backend",
Usage: "shows all frontends that connect to a specific backend",
UsageText: "bay project-map by-backend --all",
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "all",
Usage: "List all projects",
},
&cli.StringFlag{
Name: "output",
Usage: "Output format - supports json, table",
DefaultText: "table",
},
},
Action: project_map.ByBackend,
},
{
Name: "by-frontend",
Usage: "shows the backend that a list of frontends connect to",
UsageText: "bay project-map by-frontend --all",
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "all",
Usage: "List all projects",
},
&cli.StringFlag{
Name: "output",
Usage: "Output format - supports json, table",
DefaultText: "table",
},
},
Action: project_map.ByFrontend,
},
},
},
{
Name: "deployment",
Usage: "commands for deployment actions",
Commands: []*cli.Command{
{
Name: "metadata",
Usage: "generates a json object with deployment metadata",
UsageText: "bay deployment metadata",
Action: deployment.DeploymentMetadata,
},
},
},
{
Name: "elastic-cloud",
Usage: "commands to interact with Elastic Cloud deployments",
Hidden: true,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "deployment-id",
Usage: "cloud deployment ID as listed on the Elastic Cloud 'manage' page",
Required: true,
Sources: cli.EnvVars("EC_DEPLOYMENT_CLOUD_ID"),
},
&cli.StringFlag{
Name: "deployment-api-key",
Required: true,
Hidden: true,
Sources: cli.EnvVars("EC_DEPLOYMENT_API_KEY"),
},
},
Commands: []*cli.Command{
{
Name: "unassigned-shards",
Usage: "Prints unassigned shards in JSON format",
UsageText: "bay elastic-cloud unassigned-shards",
Action: elastic_cloud.ListUnassignedShards,
Flags: []cli.Flag{},
},
{
Name: "delete-stale",
Usage: "deletes stale indices (> 30 days old)",
UsageText: "bay elastic-cloud delete-stale",
Action: elastic_cloud.DeleteStaleIndices,
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "force",
Usage: "skips all confirmation prompts and immediately executes mutations",
},
&cli.BoolFlag{
Name: "output-delete-list",
Usage: "outputs a list of indices that would be deleted",
},
&cli.Int64Flag{
Name: "age",
Value: int64(30),
Usage: "sets the minimum age of indices to be marked for deletion",
},
},
},
},
},
},
}
if err := app.Run(context.Background(), os.Args); err != nil {
log.Fatal(err)
}
}