-
Notifications
You must be signed in to change notification settings - Fork 19
/
sync_desire.go
54 lines (47 loc) · 1.34 KB
/
sync_desire.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
package v1
// DesireRequest body of request to sync desired data
type DesireRequest struct {
Infos []ResourceInfo `yaml:"infos" json:"infos"`
}
// DesireResponse body of response to sync desired data
type DesireResponse struct {
Values []ResourceValue `yaml:"values" json:"values"`
}
// ResourceInfo desired info
type ResourceInfo struct {
Kind Kind `yaml:"kind,omitempty" json:"kind,omitempty"`
Name string `yaml:"name,omitempty" json:"name,omitempty"`
Version string `yaml:"version,omitempty" json:"version,omitempty"`
}
// ResourceValue desired value
type ResourceValue struct {
ResourceInfo `yaml:",inline" json:",inline"`
Value LazyValue `yaml:"value,omitempty" json:"value,omitempty"`
}
// App return app data if its kind is app
func (v *ResourceValue) App() *Application {
if v.Kind == KindApplication || v.Kind == KindApp {
var app Application
v.Value.Unmarshal(&app)
return &app
}
return nil
}
// Config return config data if its kind is config
func (v *ResourceValue) Config() *Configuration {
if v.Kind == KindConfiguration || v.Kind == KindConfig {
var cfg Configuration
v.Value.Unmarshal(&cfg)
return &cfg
}
return nil
}
// Secret return secret data if its kind is secret
func (v *ResourceValue) Secret() *Secret {
if v.Kind == KindSecret {
var sec Secret
v.Value.Unmarshal(&sec)
return &sec
}
return nil
}