New 🌊 wave for @helm

Commit 5f85787c

5f85787c0671Merged

Svyatoslav Dumchenko <[email protected]> · 5 years ago · 4 files · ~4 modified

Description

tune config for gomplate datasources

Details

Commit
5f85787c0671
Parent
3eb569e74e3d

pkg/template/config.gomodifiedView file

@@ -1,6 +1,8 @@
11 package template
22
33 import (
4+ "net/url"
5+
46 "github.com/hairyhenderson/gomplate/v3/data"
57 )
68
@@ -9,12 +11,55 @@
911 }
1012
1113 type GomplateConfig struct {
12- Data *data.Data
13- Enabled bool
14+ Datasources map[string]Source
15+ data *data.Data
16+ Enabled bool
1417 }
1518
19+type Source struct {
20+ URL *url.URL
21+}
22+
23+func (s *Source) UnmarshalYAML(unmarshal func(v interface{}) error) error {
24+ type raw struct {
25+ URL string
26+ }
27+
28+ r := raw{}
29+ err := unmarshal(&r)
30+ if err != nil {
31+ return err
32+ }
33+
34+ u, err := url.Parse(r.URL)
35+ if err != nil {
36+ return err
37+ }
38+
39+ *s = Source{
40+ URL: u,
41+ }
42+ return nil
43+}
44+
1645 var cfg *Config
1746
1847 func SetConfig(config *Config) {
1948 cfg = config
49+
50+ if cfg == nil {
51+ return
52+ }
53+
54+ sources := map[string]*data.Source{}
55+ for k, v := range cfg.Gomplate.Datasources {
56+ sources[k] = &data.Source{
57+ Alias: k,
58+ URL: v.URL,
59+ }
60+ }
61+
62+ cfg.Gomplate.data = &data.Data{
63+ Sources: sources,
64+ }
2065 }