blob: 86447feb7891b7329e2abfdf7574b0411cb928b5 [file] [log] [blame]
giolekva8aa73e82022-07-09 11:34:39 +04001package installer
giolekva050609f2021-12-29 15:51:40 +04002
giolekva8aa73e82022-07-09 11:34:39 +04003import (
Giorgi Lekveishvili3f697b12024-01-04 00:56:06 +04004 "bytes"
gio0eaf2712024-04-14 13:08:46 +04005 _ "embed"
Giorgi Lekveishvili9b52ab92024-01-05 13:12:48 +04006 "encoding/json"
Giorgi Lekveishvilibd6be7f2023-05-26 15:51:28 +04007 "fmt"
Giorgi Lekveishvili08af67a2024-01-18 08:53:05 +04008 template "html/template"
gio3cdee592024-04-17 10:15:56 +04009 "net"
gioe72b54f2024-04-22 10:44:41 +040010 "net/netip"
Giorgi Lekveishvili4257b902023-07-07 17:08:42 +040011 "strings"
Giorgi Lekveishvili0ccd1482023-06-21 15:02:24 +040012
Giorgi Lekveishvili9b52ab92024-01-05 13:12:48 +040013 "cuelang.org/go/cue"
gio308105e2024-04-19 13:12:13 +040014 "cuelang.org/go/cue/build"
15 "cuelang.org/go/cue/cuecontext"
16 "cuelang.org/go/cue/load"
Giorgi Lekveishvili9b52ab92024-01-05 13:12:48 +040017 cueyaml "cuelang.org/go/encoding/yaml"
giof8843412024-05-22 16:38:05 +040018 helmv2 "github.com/fluxcd/helm-controller/api/v2"
giolekva8aa73e82022-07-09 11:34:39 +040019)
giolekva050609f2021-12-29 15:51:40 +040020
giof8843412024-05-22 16:38:05 +040021//go:embed app_configs/dodo_app.cue
22var dodoAppCue []byte
gio0eaf2712024-04-14 13:08:46 +040023
giof8843412024-05-22 16:38:05 +040024//go:embed app_configs/app_base.cue
25var cueBaseConfig []byte
gio0eaf2712024-04-14 13:08:46 +040026
giof8843412024-05-22 16:38:05 +040027//go:embed app_configs/app_global_env.cue
28var cueEnvAppGlobal []byte
Giorgi Lekveishvilie009a5d2024-01-05 14:10:11 +040029
giof8843412024-05-22 16:38:05 +040030//go:embed app_configs/app_global_infra.cue
31var cueInfraAppGlobal []byte
Giorgi Lekveishvilie009a5d2024-01-05 14:10:11 +040032
gioe72b54f2024-04-22 10:44:41 +040033type rendered struct {
giof8843412024-05-22 16:38:05 +040034 Name string
35 Readme string
36 Resources CueAppData
37 HelmCharts HelmCharts
38 ContainerImages map[string]ContainerImage
39 Ports []PortForward
40 Data CueAppData
41 URL string
42 Help []HelpDocument
43 Icon string
Davit Tabidze56f86a42024-04-09 19:15:25 +040044}
45
46type HelpDocument struct {
47 Title string
48 Contents string
49 Children []HelpDocument
Giorgi Lekveishvili9b52ab92024-01-05 13:12:48 +040050}
51
giof8843412024-05-22 16:38:05 +040052type ContainerImage struct {
53 Registry string `json:"registry"`
54 Repository string `json:"repository"`
55 Name string `json:"name"`
56 Tag string `json:"tag"`
57}
58
59type helmChartRef struct {
60 Kind string `json:"kind"`
61}
62
63type HelmCharts struct {
64 Git map[string]HelmChartGitRepo
65}
66
67type HelmChartGitRepo struct {
68 Address string `json:"address"`
69 Branch string `json:"branch"`
70 Path string `json:"path"`
71}
72
gioe72b54f2024-04-22 10:44:41 +040073type EnvAppRendered struct {
74 rendered
75 Config AppInstanceConfig
76}
77
78type InfraAppRendered struct {
79 rendered
80 Config InfraAppInstanceConfig
81}
82
gio3cdee592024-04-17 10:15:56 +040083type PortForward struct {
84 Allocator string `json:"allocator"`
85 Protocol string `json:"protocol"`
86 SourcePort int `json:"sourcePort"`
87 TargetService string `json:"targetService"`
88 TargetPort int `json:"targetPort"`
89}
90
91type AppType int
92
93const (
94 AppTypeInfra AppType = iota
95 AppTypeEnv
96)
97
Giorgi Lekveishvili08af67a2024-01-18 08:53:05 +040098type App interface {
99 Name() string
gio44f621b2024-04-29 09:44:38 +0400100 Type() AppType
101 Slug() string
Giorgi Lekveishvili08af67a2024-01-18 08:53:05 +0400102 Description() string
103 Icon() template.HTML
104 Schema() Schema
gioef01fbb2024-04-12 16:52:59 +0400105 Namespace() string
gio3cdee592024-04-17 10:15:56 +0400106}
107
108type InfraConfig struct {
gioe72b54f2024-04-22 10:44:41 +0400109 Name string `json:"pcloudEnvName,omitempty"` // #TODO(gio): change to name
110 PublicIP []net.IP `json:"publicIP,omitempty"`
111 InfraNamespacePrefix string `json:"namespacePrefix,omitempty"`
112 InfraAdminPublicKey []byte `json:"infraAdminPublicKey,omitempty"`
gio3cdee592024-04-17 10:15:56 +0400113}
114
115type InfraApp interface {
116 App
giof8843412024-05-22 16:38:05 +0400117 Render(release Release, infra InfraConfig, values map[string]any, charts map[string]helmv2.HelmChartTemplateSpec) (InfraAppRendered, error)
gioe72b54f2024-04-22 10:44:41 +0400118}
119
120type EnvNetwork struct {
121 DNS net.IP `json:"dns,omitempty"`
122 DNSInClusterIP net.IP `json:"dnsInClusterIP,omitempty"`
123 Ingress net.IP `json:"ingress,omitempty"`
124 Headscale net.IP `json:"headscale,omitempty"`
125 ServicesFrom net.IP `json:"servicesFrom,omitempty"`
126 ServicesTo net.IP `json:"servicesTo,omitempty"`
127}
128
129func NewEnvNetwork(subnet net.IP) (EnvNetwork, error) {
130 addr, err := netip.ParseAddr(subnet.String())
131 if err != nil {
132 return EnvNetwork{}, err
133 }
134 if !addr.Is4() {
135 return EnvNetwork{}, fmt.Errorf("Expected IPv4, got %s instead", addr)
136 }
137 dns := addr.Next()
138 ingress := dns.Next()
139 headscale := ingress.Next()
140 b := addr.AsSlice()
141 if b[3] != 0 {
142 return EnvNetwork{}, fmt.Errorf("Expected last byte to be zero, got %d instead", b[3])
143 }
144 b[3] = 10
145 servicesFrom, ok := netip.AddrFromSlice(b)
146 if !ok {
147 return EnvNetwork{}, fmt.Errorf("Must not reach")
148 }
149 b[3] = 254
150 servicesTo, ok := netip.AddrFromSlice(b)
151 if !ok {
152 return EnvNetwork{}, fmt.Errorf("Must not reach")
153 }
154 b[3] = b[2]
155 b[2] = b[1]
156 b[0] = 10
157 b[1] = 44
158 dnsInClusterIP, ok := netip.AddrFromSlice(b)
159 if !ok {
160 return EnvNetwork{}, fmt.Errorf("Must not reach")
161 }
162 return EnvNetwork{
163 DNS: net.ParseIP(dns.String()),
164 DNSInClusterIP: net.ParseIP(dnsInClusterIP.String()),
165 Ingress: net.ParseIP(ingress.String()),
166 Headscale: net.ParseIP(headscale.String()),
167 ServicesFrom: net.ParseIP(servicesFrom.String()),
168 ServicesTo: net.ParseIP(servicesTo.String()),
169 }, nil
gio3cdee592024-04-17 10:15:56 +0400170}
171
gioe72b54f2024-04-22 10:44:41 +0400172type EnvConfig struct {
173 Id string `json:"id,omitempty"`
174 InfraName string `json:"pcloudEnvName,omitempty"`
175 Domain string `json:"domain,omitempty"`
176 PrivateDomain string `json:"privateDomain,omitempty"`
177 ContactEmail string `json:"contactEmail,omitempty"`
178 AdminPublicKey string `json:"adminPublicKey,omitempty"`
179 PublicIP []net.IP `json:"publicIP,omitempty"`
180 NameserverIP []net.IP `json:"nameserverIP,omitempty"`
181 NamespacePrefix string `json:"namespacePrefix,omitempty"`
182 Network EnvNetwork `json:"network,omitempty"`
gio3cdee592024-04-17 10:15:56 +0400183}
184
185type EnvApp interface {
186 App
giof8843412024-05-22 16:38:05 +0400187 Render(release Release, env EnvConfig, values map[string]any, charts map[string]helmv2.HelmChartTemplateSpec) (EnvAppRendered, error)
Giorgi Lekveishvilie009a5d2024-01-05 14:10:11 +0400188}
189
Giorgi Lekveishvili08af67a2024-01-18 08:53:05 +0400190type cueApp struct {
191 name string
192 description string
193 icon template.HTML
194 namespace string
195 schema Schema
gio308105e2024-04-19 13:12:13 +0400196 cfg cue.Value
197 data CueAppData
Giorgi Lekveishvili08af67a2024-01-18 08:53:05 +0400198}
199
gio308105e2024-04-19 13:12:13 +0400200type CueAppData map[string][]byte
201
202func ParseCueAppConfig(data CueAppData) (cue.Value, error) {
203 ctx := cuecontext.New()
204 buildCtx := build.NewContext()
205 cfg := &load.Config{
206 Context: buildCtx,
207 Overlay: map[string]load.Source{},
Giorgi Lekveishvili08af67a2024-01-18 08:53:05 +0400208 }
gio308105e2024-04-19 13:12:13 +0400209 names := make([]string, 0)
210 for n, b := range data {
211 a := fmt.Sprintf("/%s", n)
212 names = append(names, a)
213 cfg.Overlay[a] = load.FromString("package main\n\n" + string(b))
214 }
215 instances := load.Instances(names, cfg)
216 for _, inst := range instances {
217 if inst.Err != nil {
218 return cue.Value{}, inst.Err
219 }
220 }
221 if len(instances) != 1 {
222 return cue.Value{}, fmt.Errorf("invalid")
223 }
224 ret := ctx.BuildInstance(instances[0])
225 if ret.Err() != nil {
226 return cue.Value{}, ret.Err()
227 }
228 if err := ret.Validate(); err != nil {
229 return cue.Value{}, err
230 }
231 return ret, nil
232}
233
234func newCueApp(config cue.Value, data CueAppData) (cueApp, error) {
gio3cdee592024-04-17 10:15:56 +0400235 cfg := struct {
236 Name string `json:"name"`
237 Namespace string `json:"namespace"`
238 Description string `json:"description"`
239 Icon string `json:"icon"`
240 }{}
Giorgi Lekveishvili08af67a2024-01-18 08:53:05 +0400241 if err := config.Decode(&cfg); err != nil {
242 return cueApp{}, err
243 }
gio44f621b2024-04-29 09:44:38 +0400244 schema, err := NewCueSchema("input", config.LookupPath(cue.ParsePath("input")))
Giorgi Lekveishvili08af67a2024-01-18 08:53:05 +0400245 if err != nil {
246 return cueApp{}, err
247 }
248 return cueApp{
249 name: cfg.Name,
250 description: cfg.Description,
251 icon: template.HTML(cfg.Icon),
252 namespace: cfg.Namespace,
253 schema: schema,
254 cfg: config,
gio308105e2024-04-19 13:12:13 +0400255 data: data,
Giorgi Lekveishvili08af67a2024-01-18 08:53:05 +0400256 }, nil
257}
258
gio308105e2024-04-19 13:12:13 +0400259func ParseAndCreateNewCueApp(data CueAppData) (cueApp, error) {
260 config, err := ParseCueAppConfig(data)
261 if err != nil {
262 return cueApp{}, err
263 }
264 return newCueApp(config, data)
265}
266
Giorgi Lekveishvili08af67a2024-01-18 08:53:05 +0400267func (a cueApp) Name() string {
268 return a.name
269}
270
gio44f621b2024-04-29 09:44:38 +0400271func (a cueApp) Slug() string {
272 return strings.ReplaceAll(strings.ToLower(a.name), " ", "-")
273}
274
Giorgi Lekveishvili08af67a2024-01-18 08:53:05 +0400275func (a cueApp) Description() string {
276 return a.description
277}
278
279func (a cueApp) Icon() template.HTML {
280 return a.icon
281}
282
283func (a cueApp) Schema() Schema {
284 return a.schema
285}
286
gioef01fbb2024-04-12 16:52:59 +0400287func (a cueApp) Namespace() string {
288 return a.namespace
Giorgi Lekveishvili08af67a2024-01-18 08:53:05 +0400289}
290
gioe72b54f2024-04-22 10:44:41 +0400291func (a cueApp) render(values map[string]any) (rendered, error) {
292 ret := rendered{
gio44f621b2024-04-29 09:44:38 +0400293 Name: a.Slug(),
gio308105e2024-04-19 13:12:13 +0400294 Resources: make(CueAppData),
giof8843412024-05-22 16:38:05 +0400295 HelmCharts: HelmCharts{
296 Git: make(map[string]HelmChartGitRepo),
297 },
298 ContainerImages: make(map[string]ContainerImage),
299 Ports: make([]PortForward, 0),
300 Data: a.data,
Giorgi Lekveishvili9b52ab92024-01-05 13:12:48 +0400301 }
Giorgi Lekveishvili08af67a2024-01-18 08:53:05 +0400302 var buf bytes.Buffer
gio3cdee592024-04-17 10:15:56 +0400303 if err := json.NewEncoder(&buf).Encode(values); err != nil {
gioe72b54f2024-04-22 10:44:41 +0400304 return rendered{}, err
Giorgi Lekveishvili9b52ab92024-01-05 13:12:48 +0400305 }
Giorgi Lekveishvili08af67a2024-01-18 08:53:05 +0400306 ctx := a.cfg.Context()
307 d := ctx.CompileBytes(buf.Bytes())
308 res := a.cfg.Unify(d).Eval()
309 if err := res.Err(); err != nil {
gioe72b54f2024-04-22 10:44:41 +0400310 return rendered{}, err
Giorgi Lekveishvili08af67a2024-01-18 08:53:05 +0400311 }
312 if err := res.Validate(); err != nil {
gioe72b54f2024-04-22 10:44:41 +0400313 return rendered{}, err
Giorgi Lekveishvili08af67a2024-01-18 08:53:05 +0400314 }
gio308105e2024-04-19 13:12:13 +0400315 full, err := json.MarshalIndent(res, "", "\t")
316 if err != nil {
gioe72b54f2024-04-22 10:44:41 +0400317 return rendered{}, err
gio308105e2024-04-19 13:12:13 +0400318 }
319 ret.Data["rendered.json"] = full
Giorgi Lekveishvili08af67a2024-01-18 08:53:05 +0400320 readme, err := res.LookupPath(cue.ParsePath("readme")).String()
321 if err != nil {
gioe72b54f2024-04-22 10:44:41 +0400322 return rendered{}, err
Giorgi Lekveishvili08af67a2024-01-18 08:53:05 +0400323 }
324 ret.Readme = readme
Giorgi Lekveishvilib59b7c22024-04-03 22:17:50 +0400325 if err := res.LookupPath(cue.ParsePath("portForward")).Decode(&ret.Ports); err != nil {
gioe72b54f2024-04-22 10:44:41 +0400326 return rendered{}, err
Giorgi Lekveishvilib59b7c22024-04-03 22:17:50 +0400327 }
gio0eaf2712024-04-14 13:08:46 +0400328 {
giof8843412024-05-22 16:38:05 +0400329 charts := res.LookupPath(cue.ParsePath("charts"))
330 i, err := charts.Fields()
331 if err != nil {
332 return rendered{}, err
333 }
334 for i.Next() {
335 var chartRef helmChartRef
336 if err := i.Value().Decode(&chartRef); err != nil {
337 return rendered{}, err
338 }
339 if chartRef.Kind == "GitRepository" {
340 var chart HelmChartGitRepo
341 if err := i.Value().Decode(&chart); err != nil {
342 return rendered{}, err
343 }
344 ret.HelmCharts.Git[cleanName(i.Selector().String())] = chart
345 }
346 }
347 }
348 {
349 images := res.LookupPath(cue.ParsePath("images"))
350 i, err := images.Fields()
351 if err != nil {
352 return rendered{}, err
353 }
354 for i.Next() {
355 var img ContainerImage
356 if err := i.Value().Decode(&img); err != nil {
357 return rendered{}, err
358 }
359 ret.ContainerImages[cleanName(i.Selector().String())] = img
360 }
361 }
362 {
gio0eaf2712024-04-14 13:08:46 +0400363 output := res.LookupPath(cue.ParsePath("output"))
364 i, err := output.Fields()
365 if err != nil {
gioe72b54f2024-04-22 10:44:41 +0400366 return rendered{}, err
gio0eaf2712024-04-14 13:08:46 +0400367 }
368 for i.Next() {
369 if contents, err := cueyaml.Encode(i.Value()); err != nil {
370 return rendered{}, err
371 } else {
372 name := fmt.Sprintf("%s.yaml", cleanName(i.Selector().String()))
373 ret.Resources[name] = contents
374 }
375 }
376 }
377 {
378 resources := res.LookupPath(cue.ParsePath("resources"))
379 i, err := resources.Fields()
380 if err != nil {
381 return rendered{}, err
382 }
383 for i.Next() {
384 if contents, err := cueyaml.Encode(i.Value()); err != nil {
385 return rendered{}, err
386 } else {
387 name := fmt.Sprintf("%s.yaml", cleanName(i.Selector().String()))
388 ret.Resources[name] = contents
389 }
Giorgi Lekveishvili3f697b12024-01-04 00:56:06 +0400390 }
Giorgi Lekveishvili3f697b12024-01-04 00:56:06 +0400391 }
Davit Tabidze56f86a42024-04-09 19:15:25 +0400392 helpValue := res.LookupPath(cue.ParsePath("help"))
393 if helpValue.Exists() {
394 if err := helpValue.Decode(&ret.Help); err != nil {
gioe72b54f2024-04-22 10:44:41 +0400395 return rendered{}, err
Davit Tabidze56f86a42024-04-09 19:15:25 +0400396 }
397 }
398 url, err := res.LookupPath(cue.ParsePath("url")).String()
399 if err != nil {
gioe72b54f2024-04-22 10:44:41 +0400400 return rendered{}, err
Davit Tabidze56f86a42024-04-09 19:15:25 +0400401 }
gio09a3e5b2024-04-26 14:11:06 +0400402 ret.URL = url
Davit Tabidze56f86a42024-04-09 19:15:25 +0400403 icon, err := res.LookupPath(cue.ParsePath("icon")).String()
404 if err != nil {
gioe72b54f2024-04-22 10:44:41 +0400405 return rendered{}, err
Davit Tabidze56f86a42024-04-09 19:15:25 +0400406 }
407 ret.Icon = icon
Giorgi Lekveishvili3f697b12024-01-04 00:56:06 +0400408 return ret, nil
409}
410
gio3cdee592024-04-17 10:15:56 +0400411type cueEnvApp struct {
412 cueApp
Giorgi Lekveishvilibd6be7f2023-05-26 15:51:28 +0400413}
414
gio308105e2024-04-19 13:12:13 +0400415func NewCueEnvApp(data CueAppData) (EnvApp, error) {
416 app, err := ParseAndCreateNewCueApp(data)
Giorgi Lekveishvili743fb432023-11-08 17:19:40 +0400417 if err != nil {
418 return nil, err
419 }
gio3cdee592024-04-17 10:15:56 +0400420 return cueEnvApp{app}, nil
Giorgi Lekveishvili743fb432023-11-08 17:19:40 +0400421}
422
gio0eaf2712024-04-14 13:08:46 +0400423func NewDodoApp(appCfg []byte) (EnvApp, error) {
424 return NewCueEnvApp(CueAppData{
425 "app.cue": appCfg,
426 "base.cue": []byte(cueBaseConfig),
giof8843412024-05-22 16:38:05 +0400427 "pcloud_app.cue": dodoAppCue,
gio0eaf2712024-04-14 13:08:46 +0400428 "env_app.cue": []byte(cueEnvAppGlobal),
429 })
430}
431
gio3cdee592024-04-17 10:15:56 +0400432func (a cueEnvApp) Type() AppType {
433 return AppTypeEnv
434}
435
giof8843412024-05-22 16:38:05 +0400436func (a cueEnvApp) Render(release Release, env EnvConfig, values map[string]any, charts map[string]helmv2.HelmChartTemplateSpec) (EnvAppRendered, error) {
gio3cdee592024-04-17 10:15:56 +0400437 networks := CreateNetworks(env)
438 derived, err := deriveValues(values, a.Schema(), networks)
439 if err != nil {
gioe72b54f2024-04-22 10:44:41 +0400440 return EnvAppRendered{}, nil
gio3cdee592024-04-17 10:15:56 +0400441 }
giof8843412024-05-22 16:38:05 +0400442 if charts == nil {
443 charts = make(map[string]helmv2.HelmChartTemplateSpec)
444 }
gio3cdee592024-04-17 10:15:56 +0400445 ret, err := a.cueApp.render(map[string]any{
giof8843412024-05-22 16:38:05 +0400446 "global": env,
447 "release": release,
448 "input": derived,
449 "localCharts": charts,
450 "networks": networkMap(networks),
gio3cdee592024-04-17 10:15:56 +0400451 })
452 if err != nil {
gioe72b54f2024-04-22 10:44:41 +0400453 return EnvAppRendered{}, err
gio3cdee592024-04-17 10:15:56 +0400454 }
gioe72b54f2024-04-22 10:44:41 +0400455 return EnvAppRendered{
456 rendered: ret,
457 Config: AppInstanceConfig{
gio44f621b2024-04-29 09:44:38 +0400458 AppId: a.Slug(),
gioe72b54f2024-04-22 10:44:41 +0400459 Env: env,
460 Release: release,
461 Values: values,
462 Input: derived,
gio09a3e5b2024-04-26 14:11:06 +0400463 URL: ret.URL,
gioe72b54f2024-04-22 10:44:41 +0400464 Help: ret.Help,
gio09a3e5b2024-04-26 14:11:06 +0400465 Icon: ret.Icon,
gioe72b54f2024-04-22 10:44:41 +0400466 },
467 }, nil
gio3cdee592024-04-17 10:15:56 +0400468}
469
470type cueInfraApp struct {
471 cueApp
472}
473
gio308105e2024-04-19 13:12:13 +0400474func NewCueInfraApp(data CueAppData) (InfraApp, error) {
475 app, err := ParseAndCreateNewCueApp(data)
Giorgi Lekveishvili743fb432023-11-08 17:19:40 +0400476 if err != nil {
Giorgi Lekveishvili08af67a2024-01-18 08:53:05 +0400477 return nil, err
Giorgi Lekveishvili743fb432023-11-08 17:19:40 +0400478 }
gio3cdee592024-04-17 10:15:56 +0400479 return cueInfraApp{app}, nil
480}
481
482func (a cueInfraApp) Type() AppType {
483 return AppTypeInfra
484}
485
giof8843412024-05-22 16:38:05 +0400486func (a cueInfraApp) Render(release Release, infra InfraConfig, values map[string]any, charts map[string]helmv2.HelmChartTemplateSpec) (InfraAppRendered, error) {
487 if charts == nil {
488 charts = make(map[string]helmv2.HelmChartTemplateSpec)
489 }
gioe72b54f2024-04-22 10:44:41 +0400490 ret, err := a.cueApp.render(map[string]any{
giof8843412024-05-22 16:38:05 +0400491 "global": infra,
492 "release": release,
493 "input": values,
494 "localCharts": charts,
gio3cdee592024-04-17 10:15:56 +0400495 })
gioe72b54f2024-04-22 10:44:41 +0400496 if err != nil {
497 return InfraAppRendered{}, err
498 }
499 return InfraAppRendered{
500 rendered: ret,
501 Config: InfraAppInstanceConfig{
gio44f621b2024-04-29 09:44:38 +0400502 AppId: a.Slug(),
gioe72b54f2024-04-22 10:44:41 +0400503 Infra: infra,
504 Release: release,
505 Values: values,
506 Input: values,
gio09a3e5b2024-04-26 14:11:06 +0400507 URL: ret.URL,
508 Help: ret.Help,
gioe72b54f2024-04-22 10:44:41 +0400509 },
510 }, nil
Giorgi Lekveishvilief21c132024-01-17 18:57:58 +0400511}
512
Giorgi Lekveishvili08af67a2024-01-18 08:53:05 +0400513func cleanName(s string) string {
514 return strings.ReplaceAll(strings.ReplaceAll(s, "\"", ""), "'", "")
Giorgi Lekveishvilief21c132024-01-17 18:57:58 +0400515}
gioe72b54f2024-04-22 10:44:41 +0400516
517func join[T fmt.Stringer](items []T, sep string) string {
518 var tmp []string
519 for _, i := range items {
520 tmp = append(tmp, i.String())
521 }
522 return strings.Join(tmp, ",")
523}
gio0eaf2712024-04-14 13:08:46 +0400524
525func networkMap(networks []Network) map[string]Network {
526 ret := make(map[string]Network)
527 for _, n := range networks {
528 ret[strings.ToLower(n.Name)] = n
529 }
530 return ret
531}