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
87 lines (75 loc) · 1.81 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
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
81
82
83
84
85
86
87
package main
import (
"github.com/caos/orbos/internal/api"
boomapi "github.com/caos/orbos/internal/operator/boom/api"
"github.com/caos/orbos/internal/operator/orbiter"
"github.com/caos/orbos/internal/operator/orbiter/kinds/orb"
"github.com/spf13/cobra"
)
func APICommand(rv RootValues) *cobra.Command {
var (
cmd = &cobra.Command{
Use: "api",
Short: "Upgrade the yml-files to the newest version",
Long: "Upgrade the yml-files to the newest version",
}
)
cmd.RunE = func(cmd *cobra.Command, args []string) error {
_, monitor, orbConfig, gitClient, errFunc := rv()
if errFunc != nil {
return errFunc(cmd)
}
if err := orbConfig.IsComplete(); err != nil {
return err
}
if err := gitClient.Configure(orbConfig.URL, []byte(orbConfig.Repokey)); err != nil {
return err
}
if err := gitClient.Clone(); err != nil {
return err
}
foundOrbiter, err := api.ExistsOrbiterYml(gitClient)
if err != nil {
return err
}
if foundOrbiter {
_, _, _, migrate, desired, _, _, err := orbiter.Adapt(gitClient, monitor, make(chan struct{}), orb.AdaptFunc(
orbConfig,
gitCommit,
true,
false,
gitClient,
))
if err != nil {
return err
}
if migrate {
if err := api.PushOrbiterYml(monitor, "Update orbiter.yml", gitClient, desired); err != nil {
return err
}
}
}
foundBoom, err := api.ExistsBoomYml(gitClient)
if err != nil {
return err
}
if foundBoom {
desired, err := api.ReadBoomYml(gitClient)
if err != nil {
return err
}
toolset, migrate, _, err := boomapi.ParseToolset(desired)
if err != nil {
return err
}
if migrate {
desired.Parsed = toolset
if err := api.PushBoomYml(monitor, "Update boom.yml", gitClient, desired); err != nil {
return err
}
}
}
return nil
}
return cmd
}