-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
task.go
45 lines (40 loc) · 931 Bytes
/
task.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
package ecrm
import (
"errors"
"fmt"
"strconv"
"strings"
"github.com/aws/aws-sdk-go-v2/aws/arn"
)
type taskdef struct {
name string
revision int
}
func (td taskdef) String() string {
return fmt.Sprintf("%s:%d", td.name, td.revision)
}
func parseTaskdefArn(s string) (taskdef, error) {
a, err := arn.Parse(s)
if err != nil {
return taskdef{}, err
}
if a.Service != "ecs" {
return taskdef{}, errors.New("not an ECS task definition ARN")
}
p := strings.SplitN(a.Resource, "/", 2)
if len(p) != 2 {
return taskdef{}, errors.New("invalid task definition ARN")
}
if p[0] != "task-definition" {
return taskdef{}, errors.New("not a task definition ARN")
}
nr := strings.SplitN(p[1], ":", 2)
if len(nr) != 2 {
return taskdef{}, errors.New("invalid task definition name")
}
rev, err := strconv.Atoi(nr[1])
if err != nil {
return taskdef{}, err
}
return taskdef{name: nr[0], revision: rev}, nil
}