-
Notifications
You must be signed in to change notification settings - Fork 1
/
format-1.16.go
executable file
·112 lines (95 loc) · 2.85 KB
/
format-1.16.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// Copyright 2013 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package agent
import (
"encoding/base64"
"launchpad.net/goyaml"
"launchpad.net/juju-core/version"
)
var format_1_16 = formatter_1_16{}
// formatter_1_16 is the formatter for the 1.16 format.
type formatter_1_16 struct {
}
// Ensure that the formatter_1_16 struct implements the formatter interface.
var _ formatter = formatter_1_16{}
// format_1_16Serialization holds information for a given agent.
type format_1_16Serialization struct {
Tag string
Nonce string
UpgradedToVersion *version.Number `yaml:"upgradedToVersion"`
CACert string
StateAddresses []string `yaml:",omitempty"`
StatePassword string `yaml:",omitempty"`
APIAddresses []string `yaml:",omitempty"`
APIPassword string `yaml:",omitempty"`
OldPassword string
Values map[string]string
// Only state server machines have these next three items
StateServerCert string `yaml:",omitempty"`
StateServerKey string `yaml:",omitempty"`
APIPort int `yaml:",omitempty"`
}
func init() {
registerFormat(format_1_16)
}
const legacyFormatFilename = "format"
// legacyFormatPrefix is the prefix of the legacy format file.
const legacyFormatPrefix = "format "
// decode64 makes sure that for an empty string we have a nil slice, not an
// empty slice, which is what the base64 DecodeString function returns.
func decode64(value string) (result []byte, err error) {
if value != "" {
result, err = base64.StdEncoding.DecodeString(value)
}
return
}
func (formatter_1_16) version() string {
return "1.16"
}
func (formatter_1_16) unmarshal(data []byte) (*configInternal, error) {
var format format_1_16Serialization
if err := goyaml.Unmarshal(data, &format); err != nil {
return nil, err
}
caCert, err := decode64(format.CACert)
if err != nil {
return nil, err
}
stateServerCert, err := decode64(format.StateServerCert)
if err != nil {
return nil, err
}
stateServerKey, err := decode64(format.StateServerKey)
if err != nil {
return nil, err
}
if format.UpgradedToVersion == nil {
// Assume it's 1.16.0.
upgradedToVersion := version.MustParse("1.16.0")
format.UpgradedToVersion = &upgradedToVersion
}
config := &configInternal{
tag: format.Tag,
nonce: format.Nonce,
upgradedToVersion: *format.UpgradedToVersion,
caCert: caCert,
oldPassword: format.OldPassword,
stateServerCert: stateServerCert,
stateServerKey: stateServerKey,
apiPort: format.APIPort,
values: format.Values,
}
if len(format.StateAddresses) > 0 {
config.stateDetails = &connectionDetails{
format.StateAddresses,
format.StatePassword,
}
}
if len(format.APIAddresses) > 0 {
config.apiDetails = &connectionDetails{
format.APIAddresses,
format.APIPassword,
}
}
return config, nil
}