forked from aws/amazon-ecs-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflags.go
More file actions
313 lines (286 loc) · 10.4 KB
/
flags.go
File metadata and controls
313 lines (286 loc) · 10.4 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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
// Copyright 2015-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License"). You may
// not use this file except in compliance with the License. A copy of the
// License is located at
//
// http://aws.amazon.com/apache2.0/
//
// or in the "license" file accompanying this file. This file is distributed
// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
// express or implied. See the License for the specific language governing
// permissions and limitations under the License.
package flags
import (
"fmt"
"os"
"github.com/aws/amazon-ecs-cli/ecs-cli/modules/utils"
"github.com/aws/aws-sdk-go/service/ecs"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
)
// Flag names used by the cli.
const (
// Configure
AccessKeyFlag = "access-key"
SecretKeyFlag = "secret-key"
SessionTokenFlag = "session-token"
RegionFlag = "region"
EndpointFlag = "endpoint"
AwsRegionEnvVar = "AWS_REGION"
AwsDefaultRegionEnvVar = "AWS_DEFAULT_REGION"
AwsDefaultProfileEnvVar = "AWS_DEFAULT_PROFILE"
ProfileFlag = "profile"
ClusterFlag = "cluster"
ClusterEnvVar = "ECS_CLUSTER"
VerboseFlag = "verbose"
ClusterConfigFlag = "cluster-config"
ECSProfileFlag = "ecs-profile"
ProfileNameFlag = "profile-name"
ConfigNameFlag = "config-name"
AWSProfileFlag = "aws-profile"
ECSProfileEnvVar = "ECS_PROFILE"
AWSProfileEnvVar = "AWS_PROFILE"
AWSAccessKeyEnvVar = "AWS_ACCESS_KEY_ID"
AWSSecretKeyEnvVar = "AWS_SECRET_ACCESS_KEY"
// logs
TaskIDFlag = "task-id"
TaskDefinitionFlag = "task-def"
FollowLogsFlag = "follow"
FilterPatternFlag = "filter-pattern"
SinceFlag = "since"
StartTimeFlag = "start-time"
EndTimeFlag = "end-time"
TimeStampsFlag = "timestamps"
CreateLogsFlag = "create-log-groups"
// Service Discovery
PrivateDNSNamespaceNameFlag = "private-dns-namespace"
PrivateDNSNamespaceIDFlag = "private-dns-namespace-id"
PublicDNSNamespaceIDFlag = "public-dns-namespace-id"
PublicDNSNamespaceNameFlag = "public-dns-namespace"
EnableServiceDiscoveryFlag = "enable-service-discovery"
DNSTypeFlag = "dns-type"
DNSTTLFlag = "dns-ttl"
ServiceDiscoveryContainerNameFlag = "sd-container-name"
ServiceDiscoveryContainerPortFlag = "sd-container-port"
HealthcheckCustomConfigFailureThresholdFlag = "healthcheck-custom-config-failure-threshold"
DeletePrivateNamespaceFlag = "delete-namespace"
UpdateServiceDiscoveryFlag = "update-service-discovery"
ComposeProjectNamePrefixFlag = "compose-project-name-prefix"
ComposeProjectNamePrefixDefaultValue = "ecscompose-"
ComposeServiceNamePrefixFlag = "compose-service-name-prefix"
ComposeServiceNamePrefixDefaultValue = ComposeProjectNamePrefixDefaultValue + "service-"
CFNStackNameFlag = "cfn-stack-name"
CFNStackNamePrefixDefaultValue = utils.ECSCLIResourcePrefix
LaunchTypeFlag = "launch-type"
DefaultLaunchTypeFlag = "default-launch-type"
SchedulingStrategyFlag = "scheduling-strategy"
// Cluster
AsgMaxSizeFlag = "size"
VpcAzFlag = "azs"
SecurityGroupFlag = "security-group"
SourceCidrFlag = "cidr"
EcsPortFlag = "port"
SubnetIdsFlag = "subnets"
VpcIdFlag = "vpc"
InstanceTypeFlag = "instance-type"
SpotPriceFlag = "spot-price"
InstanceRoleFlag = "instance-role"
ImageIdFlag = "image-id"
KeypairNameFlag = "keypair"
CapabilityIAMFlag = "capability-iam"
NoAutoAssignPublicIPAddressFlag = "no-associate-public-ip-address"
ForceFlag = "force"
EmptyFlag = "empty"
UserDataFlag = "extra-user-data"
// Image
RegistryIdFlag = "registry-id"
TaggedFlag = "tagged"
UntaggedFlag = "untagged"
UseFIPSFlag = "use-fips" // TODO: repurpose to use more generally with other services/workflows
// Compose
ProjectNameFlag = "project-name"
ComposeFileNameFlag = "file"
TaskRoleArnFlag = "task-role-arn"
ECSParamsFileNameFlag = "ecs-params"
ForceUpdateFlag = "force-update"
RegistryCredsFileNameFlag = "registry-creds"
// Compose Service
CreateServiceCommandName = "create"
DeploymentMaxPercentDefaultValue = 200
DeploymentMaxPercentFlag = "deployment-max-percent"
DeploymentMinHealthyPercentDefaultValue = 100
DeploymentMinHealthyPercentFlag = "deployment-min-healthy-percent"
TargetGroupArnFlag = "target-group-arn"
ContainerNameFlag = "container-name"
ContainerPortFlag = "container-port"
LoadBalancerNameFlag = "load-balancer-name"
HealthCheckGracePeriodFlag = "health-check-grace-period"
RoleFlag = "role"
ComposeServiceTimeOutFlag = "timeout"
ForceDeploymentFlag = "force-deployment"
// Registry Creds
UpdateExistingSecretsFlag = "update-existing-secrets"
RoleNameFlag = "role-name"
NoRoleFlag = "no-role"
NoOutputFileFlag = "no-output-file"
OutputDirFlag = "output-dir"
DesiredTaskStatus = "desired-status"
)
// OptionalRegionAndProfileFlags provides these flags:
// OptionalRegionFlag inline overrides region
// OptionalClusterConfigFlag specifies the cluster profile to read from config
// OptionalProfileConfigFlag specifies the credentials profile to read from the config
// OptionalAWSProfileFlag specifies the AWS Profile to use for credential information
func OptionalRegionAndProfileFlags() []cli.Flag {
return []cli.Flag{
cli.StringFlag{
Name: RegionFlag + ", r",
Usage: fmt.Sprintf(
"[Optional] Specifies the AWS region to use. Defaults to the region configured using the configure command",
),
},
cli.StringFlag{
Name: ClusterConfigFlag,
Usage: fmt.Sprintf(
"[Optional] Specifies the name of the ECS cluster configuration to use. Defaults to the default cluster configuration.",
),
},
cli.StringFlag{
Name: ECSProfileFlag,
EnvVar: ECSProfileEnvVar,
Usage: fmt.Sprintf(
"[Optional] Specifies the name of the ECS profile configuration to use. Defaults to the default profile configuration.",
),
},
cli.StringFlag{
Name: AWSProfileFlag,
EnvVar: AWSProfileEnvVar,
Usage: fmt.Sprintf(
"[Optional] Use the AWS credentials from an existing named profile in ~/.aws/credentials.",
),
},
}
}
// OptionalClusterFlag inline overrides cluster
func OptionalClusterFlag() cli.Flag {
return cli.StringFlag{
Name: ClusterFlag + ", c",
Usage: fmt.Sprintf(
"[Optional] Specifies the ECS cluster name to use. Defaults to the cluster configured using the configure command",
),
}
}
// OptionalConfigFlags returns the concatenation of OptionalRegionAndProfileFlags and OptionalClusterFlag
func OptionalConfigFlags() []cli.Flag {
return append(OptionalRegionAndProfileFlags(), OptionalClusterFlag())
}
// OptionalLaunchTypeFlag allows users to specify the launch type for their task/service/cluster
func OptionalLaunchTypeFlag() []cli.Flag {
return []cli.Flag{
cli.StringFlag{
Name: LaunchTypeFlag,
Usage: fmt.Sprintf(
"[Optional] Specifies the launch type. Options: EC2 or FARGATE. Overrides the default launch type stored in your cluster configuration. Defaults to EC2 if a cluster configuration is not used.",
),
},
}
}
// OptionalSchedulingStrategyFlag allows users to specify the scheduling strategy for their task/service/cluster
func OptionalSchedulingStrategyFlag() []cli.Flag {
return []cli.Flag{
cli.StringFlag{
Name: SchedulingStrategyFlag,
Usage: fmt.Sprintf(
"[Optional] Specifies the scheduling strategy type. Options: REPLICA (default) or DAEMON.",
),
},
}
}
// OptionalCreateLogsFlag allows users to specify the launch type for their task/service/cluster
func OptionalCreateLogsFlag() []cli.Flag {
return []cli.Flag{
cli.BoolFlag{
Name: CreateLogsFlag,
Usage: fmt.Sprintf(
"[Optional] Create the CloudWatch log groups specified in your compose file(s).",
),
},
}
}
// OptionalForceUpdateFlag allows users to force an update of running tasks on compose up.
func OptionalForceUpdateFlag() []cli.Flag {
return []cli.Flag{
cli.BoolFlag{
Name: ForceUpdateFlag + ",u",
Usage: "[Optional] Forces update of task or service with current run parameters",
},
}
}
func DebugFlag() []cli.Flag {
return []cli.Flag{
cli.BoolFlag{
Name: VerboseFlag + ",debug",
Usage: "[Optional] Increase the verbosity of command output to aid in diagnostics.",
},
}
}
func FipsEndpointFlag() []cli.Flag {
return []cli.Flag{
cli.BoolFlag{
Name: UseFIPSFlag + ",fips",
Usage: "[Optional] Routes calls to AWS services through FIPS endpoints.",
},
}
}
// OptionalDesiredStatusFlag allows users to filter tasks returned by the ps commands
func OptionalDesiredStatusFlag() []cli.Flag {
return []cli.Flag{
cli.StringFlag{
Name: DesiredTaskStatus,
Usage: fmt.Sprintf(
"[Optional] Filter tasks by desired status. Valid values: %s or %s",
ecs.DesiredStatusRunning,
ecs.DesiredStatusStopped,
),
},
}
}
// UsageErrorFactory Returns a usage error function for the specified command
func UsageErrorFactory(command string) func(*cli.Context, error, bool) error {
return func(c *cli.Context, err error, isSubcommand bool) error {
if err != nil {
logrus.Error(err)
}
err = cli.ShowCommandHelp(c, command)
if err != nil {
logrus.Debug(err)
}
os.Exit(1)
return err
}
}
func CFNResourceFlags() []string {
return []string{
AsgMaxSizeFlag,
VpcAzFlag,
SecurityGroupFlag,
SourceCidrFlag,
EcsPortFlag,
SubnetIdsFlag,
VpcIdFlag,
InstanceTypeFlag,
InstanceRoleFlag,
ImageIdFlag,
KeypairNameFlag,
SpotPriceFlag,
}
}
// AppendFlags appends a series of lists of flags
func AppendFlags(flags ...[]cli.Flag) []cli.Flag {
var allFlags []cli.Flag
for _, set := range flags {
allFlags = append(allFlags, set...)
}
return allFlags
}