Skip to content

Commit 021e104

Browse files
committed
Tagging utils
1 parent f6aa876 commit 021e104

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

ecs-cli/modules/commands/flags/flags.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ const (
140140
OutputDirFlag = "output-dir"
141141

142142
DesiredTaskStatus = "desired-status"
143+
144+
ResourceTagsFlag = "tags"
143145
)
144146

145147
// OptionalRegionAndProfileFlags provides these flags:
@@ -251,7 +253,7 @@ func DebugFlag() []cli.Flag {
251253
func FipsEndpointFlag() []cli.Flag {
252254
return []cli.Flag{
253255
cli.BoolFlag{
254-
Name: UseFIPSFlag + ",fips",
256+
Name: UseFIPSFlag + ",fips",
255257
Usage: "[Optional] Routes calls to AWS services through FIPS endpoints.",
256258
},
257259
}

ecs-cli/modules/utils/utils.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,11 @@ package utils
1717
import (
1818
"fmt"
1919
"os"
20+
"strings"
2021

22+
"github.com/aws/aws-sdk-go/aws"
2123
"github.com/aws/aws-sdk-go/aws/awserr"
24+
"github.com/aws/aws-sdk-go/service/ecs"
2225
)
2326

2427
const (
@@ -58,3 +61,20 @@ func EntityAlreadyExists(err error) bool {
5861
}
5962
return false
6063
}
64+
65+
// GetTags parses AWS Resource tags from the flag value
66+
// users specify tags in this format: key1=value1,key2=value2,key3=value3
67+
func GetTags(flagValue string, tags []*ecs.Tag) ([]*ecs.Tag, error) {
68+
keyValPairs := strings.Split(flagValue, ",")
69+
for _, pair := range keyValPairs {
70+
split := strings.Split(pair, "=")
71+
if len(split) != 2 {
72+
return nil, fmt.Errorf("Tag input not formatted correctly: %s", pair)
73+
}
74+
tags = append(tags, &ecs.Tag{
75+
Key: aws.String(split[0]),
76+
Value: aws.String(split[1]),
77+
})
78+
}
79+
return tags, nil
80+
}

0 commit comments

Comments
 (0)