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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
package manifests
import (
"bytes"
"encoding/json"
"fmt"
"reflect"
"sort"
"sigs.k8s.io/yaml"
)
type None struct{}
type PermissionInventory struct {
ProviderCluster string `json:",omitempty"`
}
type MarketIdentity struct {
Workspace string `json:",omitempty"`
}
type MarketNetwork struct {
NetworkID string `json:",omitempty"`
StateDir string `json:",omitempty"`
GuestTLSDir string `json:",omitempty"`
PDSPrivateKeyHex string `json:",omitempty"`
BobPDSPrivateKeyHex string `json:",omitempty"`
DispatcherPort int `json:",omitempty"`
GuestTLSPort int `json:",omitempty"`
Ports NetworkPorts
}
type NetworkPorts struct {
Plc int
Relay int
Dispatcher int
DispatcherTLS int
AlicePds int
BobPds int
}
type MarketBidder struct {
StateDir string `json:",omitempty"`
Handle string `json:",omitempty"`
PdsUrl string `json:",omitempty"`
PlcDirectoryUrl string `json:",omitempty"`
IngressProxyHost string `json:",omitempty"`
GuestTLSPort int `json:",omitempty"`
CABundle string `json:",omitempty"`
Policy string `json:",omitempty"`
Vault BidderVault
Kcp KcpRef
Guest BidderGuest
Trust string
Read string
ExtraArgs string
ProviderArgs string
Pds RepoPds
}
type RepoPds struct {
StateDir string `json:",omitempty"`
Identity string `json:",omitempty"`
KcpServer string `json:",omitempty"`
KcpWorkspace string `json:",omitempty"`
VaultServer string `json:",omitempty"`
VaultClient string `json:",omitempty"`
VaultKcpServer string `json:",omitempty"`
VaultMount string `json:",omitempty"`
VaultMountClient string `json:",omitempty"`
VaultWorkspace string `json:",omitempty"`
PlcDirectoryUrl string `json:",omitempty"`
IngressProxyHost string `json:",omitempty"`
AssociateService string `json:",omitempty"`
WatchEventSources string
Trust string
Read string
ExtraArgs string
}
type BidderGuest struct {
StateDir string `json:",omitempty"`
Handle string `json:",omitempty"`
VaultClient string `json:",omitempty"`
Read string
ExtraArgs string
}
type BidderVault struct {
Server string `json:",omitempty"`
Client string `json:",omitempty"`
KcpServer string `json:",omitempty"`
}
type MarketRequester struct {
StateDir string `json:",omitempty"`
CABundle string `json:",omitempty"`
Kcp KcpRef
Vault BidderVault
ExtraArgs string
}
type SshGateway struct {
StateDir string `json:",omitempty"`
CABundle string `json:",omitempty"`
EnvAllow string `json:",omitempty"`
Kcp KcpRef
Vault BidderVault
IrohDial IrohDial
ExtraArgs string
ExtraRead string
VaultExtra string
}
type IrohDial struct {
Unit string `json:",omitempty"`
Socket string `json:",omitempty"`
Dumbpipe string `json:",omitempty"`
}
type KcpRef struct {
Server string `json:",omitempty"`
Workspace string `json:",omitempty"`
}
var valueTypes = map[string]func() reflect.Type{
"None": func() reflect.Type { return reflect.TypeFor[*None]() },
"PermissionInventory": func() reflect.Type { return reflect.TypeFor[*PermissionInventory]() },
"MarketIdentity": func() reflect.Type { return reflect.TypeFor[*MarketIdentity]() },
"MarketNetwork": func() reflect.Type { return reflect.TypeFor[*MarketNetwork]() },
"MarketBidder": func() reflect.Type { return reflect.TypeFor[*MarketBidder]() },
"Gateway": func() reflect.Type { return reflect.TypeFor[*Gateway]() },
"MarketRequester": func() reflect.Type { return reflect.TypeFor[*MarketRequester]() },
"SshGateway": func() reflect.Type { return reflect.TypeFor[*SshGateway]() },
}
type Gateway struct {
StateDir string `json:",omitempty"`
KcpServer string `json:",omitempty"`
ExtraProjected string
GatewayWorkspace string `json:",omitempty"`
GatewayName string `json:",omitempty"`
TLS string `json:",omitempty"`
Trust string `json:",omitempty"`
ExtraArgs string
ExtraRead string
TestArgs string
TestRead string
IdentityWorkspace string `json:",omitempty"`
Vault GatewayVault
Requester GatewayRequester
Pds RepoPds
}
type GatewayRequester struct {
StateDir string `json:",omitempty"`
Vault GatewayVault
ExtraArgs string
ExtraRead string
ExtraProjected string
}
type GatewayVault struct {
Server string `json:",omitempty"`
Client string `json:",omitempty"`
}
const CaptureLogicalCluster = "LogicalCluster"
var captureKinds = map[string]reflect.Kind{
CaptureLogicalCluster: reflect.String,
}
func ValueTypeNames() []string {
out := make([]string, 0, len(valueTypes))
for n := range valueTypes {
out = append(out, n)
}
sort.Strings(out)
return out
}
func NewValues(name string) (any, error) {
t, ok := valueTypes[name]
if !ok {
return nil, fmt.Errorf("manifests: no values type %q (%v)", name, ValueTypeNames())
}
return reflect.New(t().Elem()).Interface(), nil
}
func DecodeValues(name string, raw []byte) (any, error) {
v, err := NewValues(name)
if err != nil {
return nil, err
}
if len(bytes.TrimSpace(raw)) == 0 {
return v, nil
}
if err := yaml.UnmarshalStrict(raw, v); err != nil {
return nil, fmt.Errorf("manifests: values %s: %w", name, err)
}
return v, nil
}
func SetCaptured(values any, c Capture, raw string) error {
rv := reflect.ValueOf(values)
if rv.Kind() != reflect.Pointer || rv.Elem().Kind() != reflect.Struct {
return fmt.Errorf("manifests: capture into %s: values is not a pointer to a struct", c.Into)
}
f := rv.Elem().FieldByName(c.Into)
if !f.IsValid() || !f.CanSet() || f.Kind() != captureKinds[c.From] {
return fmt.Errorf("manifests: capture %s into %s: no such %s field", c.From, c.Into, captureKinds[c.From])
}
switch c.From {
case CaptureLogicalCluster:
if raw == "" {
return fmt.Errorf("manifests: capture %s: an empty logical cluster", c.Into)
}
f.SetString(raw)
default:
return fmt.Errorf("manifests: capture %s: unknown source %q", c.Into, c.From)
}
return nil
}
func dataOf(values any) (map[string]any, error) {
b, err := json.Marshal(values)
if err != nil {
return nil, fmt.Errorf("manifests: values: %w", err)
}
d := json.NewDecoder(bytes.NewReader(b))
d.UseNumber()
out := map[string]any{}
if err := d.Decode(&out); err != nil {
return nil, fmt.Errorf("manifests: values: %w", err)
}
return out, nil
}