This repository has been archived by the owner on Apr 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
api.go
55 lines (50 loc) · 1.72 KB
/
api.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
package api
import (
"github.com/caos/orbos/internal/operator/boom/api/common"
"github.com/caos/orbos/internal/operator/boom/api/migrate"
"github.com/caos/orbos/internal/operator/boom/api/v1beta1"
"github.com/caos/orbos/internal/operator/boom/api/v1beta2"
"github.com/caos/orbos/internal/secret"
"github.com/caos/orbos/internal/tree"
"github.com/pkg/errors"
)
func ParseToolset(desiredTree *tree.Tree) (*v1beta2.Toolset, bool, map[string]*secret.Secret, error) {
desiredKindCommon := common.New()
if err := desiredTree.Original.Decode(desiredKindCommon); err != nil {
return nil, false, nil, errors.Wrap(err, "parsing desired state failed")
}
switch desiredKindCommon.APIVersion {
case "boom.caos.ch/v1beta1":
old, _, err := v1beta1.ParseToolset(desiredTree)
if err != nil {
return nil, false, nil, err
}
new, secrets := migrate.V1beta1Tov1beta2(old)
return new, true, secrets, err
case "boom.caos.ch/v1beta2":
desiredKind, secrets, err := v1beta2.ParseToolset(desiredTree)
if err != nil {
return nil, false, nil, err
}
return desiredKind, false, secrets, nil
default:
return nil, false, nil, errors.New("APIVersion unknown")
}
}
/*
func SecretsFunc() secret.Func {
return func(monitor mntr.Monitor, desiredTree *tree.Tree) (secrets map[string]*secret.Secret, err error) {
desiredKindCommon := common.New()
if err := desiredTree.Original.Decode(desiredKindCommon); err != nil {
return nil, errors.Wrap(err, "parsing desired state failed")
}
switch desiredKindCommon.APIVersion {
case "boom.caos.ch/v1beta1":
return v1beta1.SecretsFunc(desiredTree)
case "boom.caos.ch/v1beta2":
return v1beta2.SecretsFunc(desiredTree)
default:
return nil, errors.New("APIVersion unknown")
}
}
}*/