/
service.go
48 lines (45 loc) · 1.24 KB
/
service.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
package accounts
import (
"context"
"github.com/armory/spinnaker-operator/pkg/accounts/account"
"github.com/armory/spinnaker-operator/pkg/inspect"
)
func foundIn(obj string, list []string) bool {
for _, s := range list {
if s == obj {
return true
}
}
return false
}
// PrepareSettings gathers all accounts for the given services in the given namespace
func PrepareSettings(ctx context.Context, svc string, accountList []account.Account) (map[string]interface{}, error) {
ss := make(map[string]interface{})
// For each account type that may deploy to this service
for accountType := range Types {
aType, err := GetType(accountType)
if err != nil {
return nil, err
}
if !foundIn(svc, aType.GetServices()) {
continue
}
aSettings := make([]map[string]interface{}, 0)
for _, a := range accountList {
if a.GetType() == accountType {
m, err := a.ToSpinnakerSettings(ctx)
if err != nil {
return nil, err
}
aSettings = append(aSettings, m)
}
}
// And that slice to the service settings under the type key (e.g. provider.kubernetes.accounts)
if len(aSettings) > 0 {
if err := inspect.SetObjectProp(ss, aType.GetAccountsKey(), aSettings); err != nil {
return ss, err
}
}
}
return ss, nil
}