-
Notifications
You must be signed in to change notification settings - Fork 13
/
model_variable_override.go
56 lines (43 loc) · 1.32 KB
/
model_variable_override.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
package cac
import "gopkg.in/yaml.v3"
type VariableOverride struct {
Name string `yaml:"name,omitempty"`
ServiceName string `yaml:"serviceName,omitempty"`
Value string `yaml:"value,omitempty"`
ValueType VariableValueType `yaml:"valueType,omitempty"`
}
// We need to customize the marshaling of this object because of the way the `Value`
// field works. When the ValueType is ENCRYPTED_TEXT the value needs to be secretName:<secretName>.
func (s *VariableOverride) UnmarshalYAML(unmarshal func(interface{}) error) error {
type Alias VariableOverride
aux := &struct {
*Alias
}{
Alias: (*Alias)(s),
}
if err := unmarshal(&aux.Alias); err != nil {
return err
}
if s.ValueType == VariableOverrideValueTypes.Text {
s.Value = aux.Value
} else if s.ValueType == VariableOverrideValueTypes.EncryptedText {
ref := &SecretRef{}
if err := yaml.Unmarshal([]byte(aux.Value), ref); err != nil {
return err
}
s.Value = ref.Name
}
return nil
}
func (r *VariableOverride) MarshalYAML() (interface{}, error) {
var aux VariableOverride = *r
if r.ValueType == VariableOverrideValueTypes.Text {
aux.Value = r.Value
} else if r.ValueType == VariableOverrideValueTypes.EncryptedText {
ref := &SecretRef{
Name: r.Value,
}
aux.Value = ref.String()
}
return aux, nil
}