@@ -3,7 +3,10 @@ package template
3
3
import (
4
4
"encoding/json"
5
5
"fmt"
6
+ "io"
6
7
"log"
8
+ "net/http"
9
+ "net/url"
7
10
"os"
8
11
9
12
"github.com/spf13/cobra"
@@ -31,23 +34,35 @@ and a 'composite template' file`,
31
34
Args : cobra .MaximumNArgs (0 ),
32
35
Run : func (cmd * cobra.Command , args []string ) {
33
36
containerTool = "docker"
34
- catalogData , err := os .Open (catalogFile )
37
+ var tempCatalog io.ReadCloser
38
+ catalogURI , err := url .ParseRequestURI (catalogFile )
35
39
if err != nil {
36
- log .Fatalf ("opening catalog config file %q: %s" , catalogFile , err )
40
+ tempCatalog , err = os .Open (catalogFile )
41
+ if err != nil {
42
+ log .Fatalf ("opening catalog config file %q: %v" , catalogFile , err )
43
+ }
44
+ defer tempCatalog .Close ()
45
+ } else {
46
+ tempResp , err := http .Get (catalogURI .String ())
47
+ if err != nil {
48
+ log .Fatalf ("fetching remote catalog config file %q: %v" , catalogFile , err )
49
+ }
50
+ tempCatalog = tempResp .Body
51
+ defer tempCatalog .Close ()
37
52
}
38
- defer catalogData . Close ()
53
+ catalogData := tempCatalog
39
54
40
55
// get catalog configurations
41
56
catalogConfig := & composite.CatalogConfig {}
42
57
catalogDoc := json.RawMessage {}
43
58
catalogDecoder := yaml .NewYAMLOrJSONDecoder (catalogData , 4096 )
44
59
err = catalogDecoder .Decode (& catalogDoc )
45
60
if err != nil {
46
- log .Fatalf ("decoding catalog config: %s " , err )
61
+ log .Fatalf ("decoding catalog config: %v " , err )
47
62
}
48
63
err = json .Unmarshal (catalogDoc , catalogConfig )
49
64
if err != nil {
50
- log .Fatalf ("unmarshalling catalog config: %s " , err )
65
+ log .Fatalf ("unmarshalling catalog config: %v " , err )
51
66
}
52
67
53
68
if catalogConfig .Schema != composite .CatalogSchema {
@@ -58,7 +73,7 @@ and a 'composite template' file`,
58
73
59
74
wd , err := os .Getwd ()
60
75
if err != nil {
61
- log .Fatalf ("getting current working directory: %s " , err )
76
+ log .Fatalf ("getting current working directory: %v " , err )
62
77
}
63
78
64
79
// setup the builders for each catalog
@@ -95,7 +110,7 @@ and a 'composite template' file`,
95
110
InputDirectory : wd ,
96
111
})
97
112
if err != nil {
98
- log .Fatalf ("getting builder %q for catalog %q: %s " , schema , catalog .Name , err )
113
+ log .Fatalf ("getting builder %q for catalog %q: %v " , schema , catalog .Name , err )
99
114
}
100
115
builderMap [schema ] = builder
101
116
}
@@ -108,9 +123,9 @@ and a 'composite template' file`,
108
123
//build the error message
109
124
var errMsg string
110
125
for cat , errs := range setupErrors {
111
- errMsg += fmt .Sprintf ("\n Catalog %s :\n " , cat )
126
+ errMsg += fmt .Sprintf ("\n Catalog %v :\n " , cat )
112
127
for _ , err := range errs {
113
- errMsg += fmt .Sprintf (" - %s \n " , err )
128
+ errMsg += fmt .Sprintf (" - %v \n " , err )
114
129
}
115
130
}
116
131
log .Fatalf ("catalog configuration file field validation failed: %s" , errMsg )
@@ -128,7 +143,7 @@ and a 'composite template' file`,
128
143
129
144
compositeData , err := os .Open (compositeFile )
130
145
if err != nil {
131
- log .Fatalf ("opening composite config file %q: %s " , compositeFile , err )
146
+ log .Fatalf ("opening composite config file %q: %v " , compositeFile , err )
132
147
}
133
148
defer compositeData .Close ()
134
149
@@ -138,11 +153,11 @@ and a 'composite template' file`,
138
153
compositeDecoder := yaml .NewYAMLOrJSONDecoder (compositeData , 4096 )
139
154
err = compositeDecoder .Decode (& compositeDoc )
140
155
if err != nil {
141
- log .Fatalf ("decoding composite config: %s " , err )
156
+ log .Fatalf ("decoding composite config: %v " , err )
142
157
}
143
158
err = json .Unmarshal (compositeDoc , compositeConfig )
144
159
if err != nil {
145
- log .Fatalf ("unmarshalling composite config: %s " , err )
160
+ log .Fatalf ("unmarshalling composite config: %v " , err )
146
161
}
147
162
148
163
if compositeConfig .Schema != composite .CompositeSchema {
@@ -151,7 +166,7 @@ and a 'composite template' file`,
151
166
152
167
err = template .Render (cmd .Context (), compositeConfig , validate )
153
168
if err != nil {
154
- log .Fatalf ("rendering the composite template: %s " , err )
169
+ log .Fatalf ("rendering the composite template: %v " , err )
155
170
}
156
171
},
157
172
}
0 commit comments