-
Notifications
You must be signed in to change notification settings - Fork 55
/
config_migration.go
65 lines (56 loc) · 1.57 KB
/
config_migration.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
package cmd
import "github.com/infrahq/infra/uid"
type ClientConfigV0dot1 struct {
Version string `json:"version"` // always blank in v0.1
Name string `json:"name"`
Host string `json:"host"`
Token string `json:"token"`
SkipTLSVerify bool `json:"skip-tls-verify"`
SourceID string `json:"source-id"`
}
type ClientConfigV0dot2 struct {
Version string `json:"version"` // v0.2
Hosts []ClientHostConfigV0dot2 `json:"hosts"`
}
type ClientHostConfigV0dot2 struct {
Name string `json:"name"`
Host string `json:"host"`
Token string `json:"token"`
SkipTLSVerify bool `json:"skip-tls-verify"`
SourceID uid.ID `json:"source-id"`
Current bool `json:"current"`
}
// ToV0dot2 upgrades the config to the 0.2 version
func (c ClientConfigV0dot1) ToV0dot2() *ClientConfigV0dot2 {
return &ClientConfigV0dot2{
Version: "0.2",
Hosts: []ClientHostConfigV0dot2{
{
Name: c.Name,
Host: c.Host,
Token: c.Token,
SkipTLSVerify: c.SkipTLSVerify,
Current: true,
},
},
}
}
// ToV0dot3 upgrades the config to the 0.3 version
func (c ClientConfigV0dot2) ToV0dot3() *ClientConfig {
conf := &ClientConfig{
Version: "0.3",
}
for _, h := range c.Hosts {
providerID := uid.New()
h.SourceID = providerID
conf.Hosts = append(conf.Hosts, ClientHostConfig{
Name: h.Name,
Host: h.Host,
Token: h.Token,
SkipTLSVerify: h.SkipTLSVerify,
ProviderID: providerID,
Current: h.Current,
})
}
return conf
}