/
util.go
42 lines (38 loc) · 842 Bytes
/
util.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
package ecspresso
import (
"path/filepath"
"strings"
"github.com/aws/aws-sdk-go-v2/aws/arn"
"github.com/google/go-jsonnet"
)
func isLongArnFormat(a string) (bool, error) {
an, err := arn.Parse(a)
if err != nil {
return false, err
}
rs := strings.Split(an.Resource, "/")
switch rs[0] {
case "container-instance", "service", "task":
return len(rs) >= 3, nil
default:
return false, nil
}
}
func (d *App) readDefinitionFile(path string) ([]byte, error) {
switch filepath.Ext(path) {
case jsonnetExt:
vm := jsonnet.MakeVM()
for k, v := range d.option.ExtStr {
vm.ExtVar(k, v)
}
for k, v := range d.option.ExtCode {
vm.ExtCode(k, v)
}
jsonStr, err := vm.EvaluateFile(path)
if err != nil {
return nil, err
}
return d.loader.ReadWithEnvBytes([]byte(jsonStr))
}
return d.loader.ReadWithEnv(path)
}