-
Notifications
You must be signed in to change notification settings - Fork 7
/
export.go
80 lines (67 loc) · 2.14 KB
/
export.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
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
package export
import (
"github.com/kbst/kbst/pkg/stack"
"github.com/zclconf/go-cty/cty"
ctyJson "github.com/zclconf/go-cty/cty/json"
)
type Stack struct {
BaseDomain string `json:"base_domain"`
Environments []Environment `json:"environments"`
Clusters []Cluster `json:"clusters"`
NodePools []NodePool `json:"node_pools"`
Services []Service `json:"services"`
}
type Environment struct {
Key string `json:"key"`
IsBaseKey bool `json:"is_base_key"`
}
type Configuration struct {
EnvironmentKey string `json:"environment_key"`
Attributes map[string]ctyJson.SimpleJSONValue `json:"attributes"`
}
type Cluster struct {
NamePrefix string `json:"name_prefix"`
Provider string `json:"provider"`
Region string `json:"region"`
Version string `json:"version"`
Configurations []Configuration `json:"configurations"`
}
type NodePool struct {
PoolName string `json:"pool_name"`
ClusterName string `json:"cluster_name"`
Provider string `json:"provider"`
Region string `json:"region"`
Version string `json:"version"`
Configurations []Configuration `json:"configurations"`
}
type Service struct {
EntryName string `json:"entry_name"`
ClusterName string `json:"cluster_name"`
Provider string `json:"provider"`
Version string `json:"version"`
Configurations []Configuration `json:"configurations"`
}
func (s *Stack) StackEnvironments() []stack.Environment {
envs := []stack.Environment{}
for _, e := range s.Environments {
envs = append(envs, stack.Environment{
Key: e.Key,
IsBaseKey: e.IsBaseKey,
})
}
return envs
}
func (s *Stack) StackConfigurations(in []Configuration) []stack.Configuration {
cfgs := []stack.Configuration{}
for _, cfg := range in {
sAttrs := map[string]cty.Value{}
for k, v := range cfg.Attributes {
sAttrs[k] = v.Value
}
cfgs = append(cfgs, stack.Configuration{
EnvironmentKey: cfg.EnvironmentKey,
Attributes: sAttrs,
})
}
return cfgs
}