-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.go
43 lines (39 loc) · 862 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
43
package main
import (
"encoding/json"
"errors"
"os"
"strings"
)
func GetStateDescriptionsFromEnv(env string) ([]StateDescription, error) {
strval, ok := os.LookupEnv(env)
if !ok {
return []StateDescription{}, errors.New("value not found")
}
decoder := json.NewDecoder(strings.NewReader(strval))
descriptions := make([]StateDescription, 0)
err := decoder.Decode(&descriptions)
if err != nil {
return []StateDescription{}, err
}
return descriptions, nil
}
func MatchStateMap(current map[string]ResourceState, required []ResourceState) bool {
// do not match if no resources are available
if len(current) == 0 {
return false
}
for _, c := range current {
isRequiredState := false
for _, rs := range required {
if rs == c {
isRequiredState = true
break
}
}
if !isRequiredState {
return false
}
}
return true
}