blob: d86c9f33f7bf61065007793a83e4ed84cb06cdde [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
gio94904702024-07-26 16:58:34 +040044 Raw []byte
Davit Tabidze56f86a42024-04-09 19:15:25 +040045}
46
47type HelpDocument struct {
48 Title string
49 Contents string
50 Children []HelpDocument
Giorgi Lekveishvili9b52ab92024-01-05 13:12:48 +040051}
52
giof8843412024-05-22 16:38:05 +040053type ContainerImage struct {
54 Registry string `json:"registry"`
55 Repository string `json:"repository"`
56 Name string `json:"name"`
57 Tag string `json:"tag"`
58}
59
60type helmChartRef struct {
61 Kind string `json:"kind"`
62}
63
64type HelmCharts struct {
65 Git map[string]HelmChartGitRepo
66}
67
68type HelmChartGitRepo struct {
69 Address string `json:"address"`
70 Branch string `json:"branch"`
71 Path string `json:"path"`
72}
73
gioe72b54f2024-04-22 10:44:41 +040074type EnvAppRendered struct {
75 rendered
76 Config AppInstanceConfig
77}
78
79type InfraAppRendered struct {
80 rendered
81 Config InfraAppInstanceConfig
82}
83
gio3cdee592024-04-17 10:15:56 +040084type PortForward struct {
85 Allocator string `json:"allocator"`
gioefa0ed42024-06-13 12:31:43 +040086 ReserveAddr string `json:"reservator"`
giocdfa3722024-06-13 20:10:14 +040087 RemoveAddr string `json:"deallocator"`
gio3cdee592024-04-17 10:15:56 +040088 Protocol string `json:"protocol"`
89 SourcePort int `json:"sourcePort"`
90 TargetService string `json:"targetService"`
91 TargetPort int `json:"targetPort"`
92}
93
94type AppType int
95
96const (
97 AppTypeInfra AppType = iota
98 AppTypeEnv
99)
100
Giorgi Lekveishvili08af67a2024-01-18 08:53:05 +0400101type App interface {
102 Name() string
gio44f621b2024-04-29 09:44:38 +0400103 Type() AppType
104 Slug() string
Giorgi Lekveishvili08af67a2024-01-18 08:53:05 +0400105 Description() string
106 Icon() template.HTML
107 Schema() Schema
gioef01fbb2024-04-12 16:52:59 +0400108 Namespace() string
gio3cdee592024-04-17 10:15:56 +0400109}
110
111type InfraConfig struct {
gioe72b54f2024-04-22 10:44:41 +0400112 Name string `json:"pcloudEnvName,omitempty"` // #TODO(gio): change to name
113 PublicIP []net.IP `json:"publicIP,omitempty"`
114 InfraNamespacePrefix string `json:"namespacePrefix,omitempty"`
115 InfraAdminPublicKey []byte `json:"infraAdminPublicKey,omitempty"`
gio3cdee592024-04-17 10:15:56 +0400116}
117
118type InfraApp interface {
119 App
giof8843412024-05-22 16:38:05 +0400120 Render(release Release, infra InfraConfig, values map[string]any, charts map[string]helmv2.HelmChartTemplateSpec) (InfraAppRendered, error)
gioe72b54f2024-04-22 10:44:41 +0400121}
122
123type EnvNetwork struct {
124 DNS net.IP `json:"dns,omitempty"`
125 DNSInClusterIP net.IP `json:"dnsInClusterIP,omitempty"`
126 Ingress net.IP `json:"ingress,omitempty"`
127 Headscale net.IP `json:"headscale,omitempty"`
128 ServicesFrom net.IP `json:"servicesFrom,omitempty"`
129 ServicesTo net.IP `json:"servicesTo,omitempty"`
130}
131
132func NewEnvNetwork(subnet net.IP) (EnvNetwork, error) {
133 addr, err := netip.ParseAddr(subnet.String())
134 if err != nil {
135 return EnvNetwork{}, err
136 }
137 if !addr.Is4() {
138 return EnvNetwork{}, fmt.Errorf("Expected IPv4, got %s instead", addr)
139 }
140 dns := addr.Next()
141 ingress := dns.Next()
142 headscale := ingress.Next()
143 b := addr.AsSlice()
144 if b[3] != 0 {
145 return EnvNetwork{}, fmt.Errorf("Expected last byte to be zero, got %d instead", b[3])
146 }
147 b[3] = 10
148 servicesFrom, ok := netip.AddrFromSlice(b)
149 if !ok {
150 return EnvNetwork{}, fmt.Errorf("Must not reach")
151 }
152 b[3] = 254
153 servicesTo, ok := netip.AddrFromSlice(b)
154 if !ok {
155 return EnvNetwork{}, fmt.Errorf("Must not reach")
156 }
157 b[3] = b[2]
158 b[2] = b[1]
159 b[0] = 10
160 b[1] = 44
161 dnsInClusterIP, ok := netip.AddrFromSlice(b)
162 if !ok {
163 return EnvNetwork{}, fmt.Errorf("Must not reach")
164 }
165 return EnvNetwork{
166 DNS: net.ParseIP(dns.String()),
167 DNSInClusterIP: net.ParseIP(dnsInClusterIP.String()),
168 Ingress: net.ParseIP(ingress.String()),
169 Headscale: net.ParseIP(headscale.String()),
170 ServicesFrom: net.ParseIP(servicesFrom.String()),
171 ServicesTo: net.ParseIP(servicesTo.String()),
172 }, nil
gio3cdee592024-04-17 10:15:56 +0400173}
174
gioe72b54f2024-04-22 10:44:41 +0400175type EnvConfig struct {
176 Id string `json:"id,omitempty"`
177 InfraName string `json:"pcloudEnvName,omitempty"`
178 Domain string `json:"domain,omitempty"`
179 PrivateDomain string `json:"privateDomain,omitempty"`
180 ContactEmail string `json:"contactEmail,omitempty"`
181 AdminPublicKey string `json:"adminPublicKey,omitempty"`
182 PublicIP []net.IP `json:"publicIP,omitempty"`
183 NameserverIP []net.IP `json:"nameserverIP,omitempty"`
184 NamespacePrefix string `json:"namespacePrefix,omitempty"`
185 Network EnvNetwork `json:"network,omitempty"`
gio3cdee592024-04-17 10:15:56 +0400186}
187
188type EnvApp interface {
189 App
giocb34ad22024-07-11 08:01:13 +0400190 Render(release Release, env EnvConfig, networks []Network, values map[string]any, charts map[string]helmv2.HelmChartTemplateSpec) (EnvAppRendered, error)
Giorgi Lekveishvilie009a5d2024-01-05 14:10:11 +0400191}
192
Giorgi Lekveishvili08af67a2024-01-18 08:53:05 +0400193type cueApp struct {
194 name string
195 description string
196 icon template.HTML
197 namespace string
198 schema Schema
gio308105e2024-04-19 13:12:13 +0400199 cfg cue.Value
200 data CueAppData
Giorgi Lekveishvili08af67a2024-01-18 08:53:05 +0400201}
202
gio308105e2024-04-19 13:12:13 +0400203type CueAppData map[string][]byte
204
205func ParseCueAppConfig(data CueAppData) (cue.Value, error) {
206 ctx := cuecontext.New()
207 buildCtx := build.NewContext()
208 cfg := &load.Config{
209 Context: buildCtx,
210 Overlay: map[string]load.Source{},
Giorgi Lekveishvili08af67a2024-01-18 08:53:05 +0400211 }
gio308105e2024-04-19 13:12:13 +0400212 names := make([]string, 0)
213 for n, b := range data {
214 a := fmt.Sprintf("/%s", n)
215 names = append(names, a)
216 cfg.Overlay[a] = load.FromString("package main\n\n" + string(b))
217 }
218 instances := load.Instances(names, cfg)
219 for _, inst := range instances {
220 if inst.Err != nil {
221 return cue.Value{}, inst.Err
222 }
223 }
224 if len(instances) != 1 {
225 return cue.Value{}, fmt.Errorf("invalid")
226 }
227 ret := ctx.BuildInstance(instances[0])
228 if ret.Err() != nil {
229 return cue.Value{}, ret.Err()
230 }
231 if err := ret.Validate(); err != nil {
232 return cue.Value{}, err
233 }
234 return ret, nil
235}
236
237func newCueApp(config cue.Value, data CueAppData) (cueApp, error) {
gio3cdee592024-04-17 10:15:56 +0400238 cfg := struct {
239 Name string `json:"name"`
240 Namespace string `json:"namespace"`
241 Description string `json:"description"`
242 Icon string `json:"icon"`
243 }{}
Giorgi Lekveishvili08af67a2024-01-18 08:53:05 +0400244 if err := config.Decode(&cfg); err != nil {
245 return cueApp{}, err
246 }
gio44f621b2024-04-29 09:44:38 +0400247 schema, err := NewCueSchema("input", config.LookupPath(cue.ParsePath("input")))
Giorgi Lekveishvili08af67a2024-01-18 08:53:05 +0400248 if err != nil {
249 return cueApp{}, err
250 }
251 return cueApp{
252 name: cfg.Name,
253 description: cfg.Description,
254 icon: template.HTML(cfg.Icon),
255 namespace: cfg.Namespace,
256 schema: schema,
257 cfg: config,
gio308105e2024-04-19 13:12:13 +0400258 data: data,
Giorgi Lekveishvili08af67a2024-01-18 08:53:05 +0400259 }, nil
260}
261
gio308105e2024-04-19 13:12:13 +0400262func ParseAndCreateNewCueApp(data CueAppData) (cueApp, error) {
263 config, err := ParseCueAppConfig(data)
264 if err != nil {
265 return cueApp{}, err
266 }
267 return newCueApp(config, data)
268}
269
Giorgi Lekveishvili08af67a2024-01-18 08:53:05 +0400270func (a cueApp) Name() string {
271 return a.name
272}
273
gio44f621b2024-04-29 09:44:38 +0400274func (a cueApp) Slug() string {
275 return strings.ReplaceAll(strings.ToLower(a.name), " ", "-")
276}
277
Giorgi Lekveishvili08af67a2024-01-18 08:53:05 +0400278func (a cueApp) Description() string {
279 return a.description
280}
281
282func (a cueApp) Icon() template.HTML {
283 return a.icon
284}
285
286func (a cueApp) Schema() Schema {
287 return a.schema
288}
289
gioef01fbb2024-04-12 16:52:59 +0400290func (a cueApp) Namespace() string {
291 return a.namespace
Giorgi Lekveishvili08af67a2024-01-18 08:53:05 +0400292}
293
gioe72b54f2024-04-22 10:44:41 +0400294func (a cueApp) render(values map[string]any) (rendered, error) {
295 ret := rendered{
gio44f621b2024-04-29 09:44:38 +0400296 Name: a.Slug(),
gio308105e2024-04-19 13:12:13 +0400297 Resources: make(CueAppData),
giof8843412024-05-22 16:38:05 +0400298 HelmCharts: HelmCharts{
299 Git: make(map[string]HelmChartGitRepo),
300 },
301 ContainerImages: make(map[string]ContainerImage),
302 Ports: make([]PortForward, 0),
303 Data: a.data,
Giorgi Lekveishvili9b52ab92024-01-05 13:12:48 +0400304 }
Giorgi Lekveishvili08af67a2024-01-18 08:53:05 +0400305 var buf bytes.Buffer
gio3cdee592024-04-17 10:15:56 +0400306 if err := json.NewEncoder(&buf).Encode(values); err != nil {
gioe72b54f2024-04-22 10:44:41 +0400307 return rendered{}, err
Giorgi Lekveishvili9b52ab92024-01-05 13:12:48 +0400308 }
Giorgi Lekveishvili08af67a2024-01-18 08:53:05 +0400309 ctx := a.cfg.Context()
310 d := ctx.CompileBytes(buf.Bytes())
311 res := a.cfg.Unify(d).Eval()
312 if err := res.Err(); err != nil {
gioe72b54f2024-04-22 10:44:41 +0400313 return rendered{}, err
Giorgi Lekveishvili08af67a2024-01-18 08:53:05 +0400314 }
315 if err := res.Validate(); err != nil {
gioe72b54f2024-04-22 10:44:41 +0400316 return rendered{}, err
Giorgi Lekveishvili08af67a2024-01-18 08:53:05 +0400317 }
gio308105e2024-04-19 13:12:13 +0400318 full, err := json.MarshalIndent(res, "", "\t")
319 if err != nil {
gioe72b54f2024-04-22 10:44:41 +0400320 return rendered{}, err
gio308105e2024-04-19 13:12:13 +0400321 }
gio94904702024-07-26 16:58:34 +0400322 ret.Raw = full
gio308105e2024-04-19 13:12:13 +0400323 ret.Data["rendered.json"] = full
Giorgi Lekveishvili08af67a2024-01-18 08:53:05 +0400324 readme, err := res.LookupPath(cue.ParsePath("readme")).String()
325 if err != nil {
gioe72b54f2024-04-22 10:44:41 +0400326 return rendered{}, err
Giorgi Lekveishvili08af67a2024-01-18 08:53:05 +0400327 }
328 ret.Readme = readme
Giorgi Lekveishvilib59b7c22024-04-03 22:17:50 +0400329 if err := res.LookupPath(cue.ParsePath("portForward")).Decode(&ret.Ports); err != nil {
gioe72b54f2024-04-22 10:44:41 +0400330 return rendered{}, err
Giorgi Lekveishvilib59b7c22024-04-03 22:17:50 +0400331 }
gio0eaf2712024-04-14 13:08:46 +0400332 {
giof8843412024-05-22 16:38:05 +0400333 charts := res.LookupPath(cue.ParsePath("charts"))
334 i, err := charts.Fields()
335 if err != nil {
336 return rendered{}, err
337 }
338 for i.Next() {
339 var chartRef helmChartRef
340 if err := i.Value().Decode(&chartRef); err != nil {
341 return rendered{}, err
342 }
343 if chartRef.Kind == "GitRepository" {
344 var chart HelmChartGitRepo
345 if err := i.Value().Decode(&chart); err != nil {
346 return rendered{}, err
347 }
348 ret.HelmCharts.Git[cleanName(i.Selector().String())] = chart
349 }
350 }
351 }
352 {
353 images := res.LookupPath(cue.ParsePath("images"))
354 i, err := images.Fields()
355 if err != nil {
356 return rendered{}, err
357 }
358 for i.Next() {
359 var img ContainerImage
360 if err := i.Value().Decode(&img); err != nil {
361 return rendered{}, err
362 }
363 ret.ContainerImages[cleanName(i.Selector().String())] = img
364 }
365 }
366 {
gio0eaf2712024-04-14 13:08:46 +0400367 output := res.LookupPath(cue.ParsePath("output"))
368 i, err := output.Fields()
369 if err != nil {
gioe72b54f2024-04-22 10:44:41 +0400370 return rendered{}, err
gio0eaf2712024-04-14 13:08:46 +0400371 }
372 for i.Next() {
373 if contents, err := cueyaml.Encode(i.Value()); err != nil {
374 return rendered{}, err
375 } else {
376 name := fmt.Sprintf("%s.yaml", cleanName(i.Selector().String()))
377 ret.Resources[name] = contents
378 }
379 }
380 }
381 {
382 resources := res.LookupPath(cue.ParsePath("resources"))
383 i, err := resources.Fields()
384 if err != nil {
385 return rendered{}, err
386 }
387 for i.Next() {
388 if contents, err := cueyaml.Encode(i.Value()); err != nil {
389 return rendered{}, err
390 } else {
391 name := fmt.Sprintf("%s.yaml", cleanName(i.Selector().String()))
392 ret.Resources[name] = contents
393 }
Giorgi Lekveishvili3f697b12024-01-04 00:56:06 +0400394 }
Giorgi Lekveishvili3f697b12024-01-04 00:56:06 +0400395 }
Davit Tabidze56f86a42024-04-09 19:15:25 +0400396 helpValue := res.LookupPath(cue.ParsePath("help"))
397 if helpValue.Exists() {
398 if err := helpValue.Decode(&ret.Help); err != nil {
gioe72b54f2024-04-22 10:44:41 +0400399 return rendered{}, err
Davit Tabidze56f86a42024-04-09 19:15:25 +0400400 }
401 }
402 url, err := res.LookupPath(cue.ParsePath("url")).String()
403 if err != nil {
gioe72b54f2024-04-22 10:44:41 +0400404 return rendered{}, err
Davit Tabidze56f86a42024-04-09 19:15:25 +0400405 }
gio09a3e5b2024-04-26 14:11:06 +0400406 ret.URL = url
Davit Tabidze56f86a42024-04-09 19:15:25 +0400407 icon, err := res.LookupPath(cue.ParsePath("icon")).String()
408 if err != nil {
gioe72b54f2024-04-22 10:44:41 +0400409 return rendered{}, err
Davit Tabidze56f86a42024-04-09 19:15:25 +0400410 }
411 ret.Icon = icon
Giorgi Lekveishvili3f697b12024-01-04 00:56:06 +0400412 return ret, nil
413}
414
gio3cdee592024-04-17 10:15:56 +0400415type cueEnvApp struct {
416 cueApp
Giorgi Lekveishvilibd6be7f2023-05-26 15:51:28 +0400417}
418
gio308105e2024-04-19 13:12:13 +0400419func NewCueEnvApp(data CueAppData) (EnvApp, error) {
420 app, err := ParseAndCreateNewCueApp(data)
Giorgi Lekveishvili743fb432023-11-08 17:19:40 +0400421 if err != nil {
422 return nil, err
423 }
gio3cdee592024-04-17 10:15:56 +0400424 return cueEnvApp{app}, nil
Giorgi Lekveishvili743fb432023-11-08 17:19:40 +0400425}
426
gio0eaf2712024-04-14 13:08:46 +0400427func NewDodoApp(appCfg []byte) (EnvApp, error) {
428 return NewCueEnvApp(CueAppData{
giofc9c4ea2024-06-26 13:46:53 +0400429 "app.cue": appCfg,
430 "base.cue": []byte(cueBaseConfig),
431 "dodo.cue": dodoAppCue,
432 "env.cue": []byte(cueEnvAppGlobal),
gio0eaf2712024-04-14 13:08:46 +0400433 })
434}
435
gio3cdee592024-04-17 10:15:56 +0400436func (a cueEnvApp) Type() AppType {
437 return AppTypeEnv
438}
439
giocb34ad22024-07-11 08:01:13 +0400440func (a cueEnvApp) Render(
441 release Release,
442 env EnvConfig,
443 networks []Network,
444 values map[string]any,
445 charts map[string]helmv2.HelmChartTemplateSpec,
446) (EnvAppRendered, error) {
gio3cdee592024-04-17 10:15:56 +0400447 derived, err := deriveValues(values, a.Schema(), networks)
448 if err != nil {
gioefa0ed42024-06-13 12:31:43 +0400449 return EnvAppRendered{}, err
gio3cdee592024-04-17 10:15:56 +0400450 }
giof8843412024-05-22 16:38:05 +0400451 if charts == nil {
452 charts = make(map[string]helmv2.HelmChartTemplateSpec)
453 }
gio3cdee592024-04-17 10:15:56 +0400454 ret, err := a.cueApp.render(map[string]any{
giof8843412024-05-22 16:38:05 +0400455 "global": env,
456 "release": release,
457 "input": derived,
458 "localCharts": charts,
gio5e49bb62024-07-20 10:43:19 +0400459 "networks": NetworkMap(networks),
gio3cdee592024-04-17 10:15:56 +0400460 })
461 if err != nil {
gioe72b54f2024-04-22 10:44:41 +0400462 return EnvAppRendered{}, err
gio3cdee592024-04-17 10:15:56 +0400463 }
gioe72b54f2024-04-22 10:44:41 +0400464 return EnvAppRendered{
465 rendered: ret,
466 Config: AppInstanceConfig{
gio44f621b2024-04-29 09:44:38 +0400467 AppId: a.Slug(),
gioe72b54f2024-04-22 10:44:41 +0400468 Env: env,
469 Release: release,
470 Values: values,
471 Input: derived,
gio09a3e5b2024-04-26 14:11:06 +0400472 URL: ret.URL,
gioe72b54f2024-04-22 10:44:41 +0400473 Help: ret.Help,
gio09a3e5b2024-04-26 14:11:06 +0400474 Icon: ret.Icon,
gioe72b54f2024-04-22 10:44:41 +0400475 },
476 }, nil
gio3cdee592024-04-17 10:15:56 +0400477}
478
479type cueInfraApp struct {
480 cueApp
481}
482
gio308105e2024-04-19 13:12:13 +0400483func NewCueInfraApp(data CueAppData) (InfraApp, error) {
484 app, err := ParseAndCreateNewCueApp(data)
Giorgi Lekveishvili743fb432023-11-08 17:19:40 +0400485 if err != nil {
Giorgi Lekveishvili08af67a2024-01-18 08:53:05 +0400486 return nil, err
Giorgi Lekveishvili743fb432023-11-08 17:19:40 +0400487 }
gio3cdee592024-04-17 10:15:56 +0400488 return cueInfraApp{app}, nil
489}
490
491func (a cueInfraApp) Type() AppType {
492 return AppTypeInfra
493}
494
giof8843412024-05-22 16:38:05 +0400495func (a cueInfraApp) Render(release Release, infra InfraConfig, values map[string]any, charts map[string]helmv2.HelmChartTemplateSpec) (InfraAppRendered, error) {
496 if charts == nil {
497 charts = make(map[string]helmv2.HelmChartTemplateSpec)
498 }
gioe72b54f2024-04-22 10:44:41 +0400499 ret, err := a.cueApp.render(map[string]any{
giof8843412024-05-22 16:38:05 +0400500 "global": infra,
501 "release": release,
502 "input": values,
503 "localCharts": charts,
gio3cdee592024-04-17 10:15:56 +0400504 })
gioe72b54f2024-04-22 10:44:41 +0400505 if err != nil {
506 return InfraAppRendered{}, err
507 }
508 return InfraAppRendered{
509 rendered: ret,
510 Config: InfraAppInstanceConfig{
gio44f621b2024-04-29 09:44:38 +0400511 AppId: a.Slug(),
gioe72b54f2024-04-22 10:44:41 +0400512 Infra: infra,
513 Release: release,
514 Values: values,
515 Input: values,
gio09a3e5b2024-04-26 14:11:06 +0400516 URL: ret.URL,
517 Help: ret.Help,
gioe72b54f2024-04-22 10:44:41 +0400518 },
519 }, nil
Giorgi Lekveishvilief21c132024-01-17 18:57:58 +0400520}
521
Giorgi Lekveishvili08af67a2024-01-18 08:53:05 +0400522func cleanName(s string) string {
523 return strings.ReplaceAll(strings.ReplaceAll(s, "\"", ""), "'", "")
Giorgi Lekveishvilief21c132024-01-17 18:57:58 +0400524}
gioe72b54f2024-04-22 10:44:41 +0400525
526func join[T fmt.Stringer](items []T, sep string) string {
527 var tmp []string
528 for _, i := range items {
529 tmp = append(tmp, i.String())
530 }
531 return strings.Join(tmp, ",")
532}
gio0eaf2712024-04-14 13:08:46 +0400533
gio5e49bb62024-07-20 10:43:19 +0400534func NetworkMap(networks []Network) map[string]Network {
gio0eaf2712024-04-14 13:08:46 +0400535 ret := make(map[string]Network)
536 for _, n := range networks {
537 ret[strings.ToLower(n.Name)] = n
538 }
539 return ret
540}