@@ -3,7 +3,10 @@ package template
33import (
44 "encoding/json"
55 "fmt"
6+ "io"
67 "log"
8+ "net/http"
9+ "net/url"
710 "os"
811
912 "github.com/spf13/cobra"
@@ -31,23 +34,35 @@ and a 'composite template' file`,
3134 Args : cobra .MaximumNArgs (0 ),
3235 Run : func (cmd * cobra.Command , args []string ) {
3336 containerTool = "docker"
34- catalogData , err := os .Open (catalogFile )
37+ var tempCatalog io.ReadCloser
38+ catalogURI , err := url .ParseRequestURI (catalogFile )
3539 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 ()
3752 }
38- defer catalogData . Close ()
53+ catalogData := tempCatalog
3954
4055 // get catalog configurations
4156 catalogConfig := & composite.CatalogConfig {}
4257 catalogDoc := json.RawMessage {}
4358 catalogDecoder := yaml .NewYAMLOrJSONDecoder (catalogData , 4096 )
4459 err = catalogDecoder .Decode (& catalogDoc )
4560 if err != nil {
46- log .Fatalf ("decoding catalog config: %s " , err )
61+ log .Fatalf ("decoding catalog config: %v " , err )
4762 }
4863 err = json .Unmarshal (catalogDoc , catalogConfig )
4964 if err != nil {
50- log .Fatalf ("unmarshalling catalog config: %s " , err )
65+ log .Fatalf ("unmarshalling catalog config: %v " , err )
5166 }
5267
5368 if catalogConfig .Schema != composite .CatalogSchema {
@@ -58,7 +73,7 @@ and a 'composite template' file`,
5873
5974 wd , err := os .Getwd ()
6075 if err != nil {
61- log .Fatalf ("getting current working directory: %s " , err )
76+ log .Fatalf ("getting current working directory: %v " , err )
6277 }
6378
6479 // setup the builders for each catalog
@@ -95,7 +110,7 @@ and a 'composite template' file`,
95110 InputDirectory : wd ,
96111 })
97112 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 )
99114 }
100115 builderMap [schema ] = builder
101116 }
@@ -108,9 +123,9 @@ and a 'composite template' file`,
108123 //build the error message
109124 var errMsg string
110125 for cat , errs := range setupErrors {
111- errMsg += fmt .Sprintf ("\n Catalog %s :\n " , cat )
126+ errMsg += fmt .Sprintf ("\n Catalog %v :\n " , cat )
112127 for _ , err := range errs {
113- errMsg += fmt .Sprintf (" - %s \n " , err )
128+ errMsg += fmt .Sprintf (" - %v \n " , err )
114129 }
115130 }
116131 log .Fatalf ("catalog configuration file field validation failed: %s" , errMsg )
@@ -128,7 +143,7 @@ and a 'composite template' file`,
128143
129144 compositeData , err := os .Open (compositeFile )
130145 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 )
132147 }
133148 defer compositeData .Close ()
134149
@@ -138,11 +153,11 @@ and a 'composite template' file`,
138153 compositeDecoder := yaml .NewYAMLOrJSONDecoder (compositeData , 4096 )
139154 err = compositeDecoder .Decode (& compositeDoc )
140155 if err != nil {
141- log .Fatalf ("decoding composite config: %s " , err )
156+ log .Fatalf ("decoding composite config: %v " , err )
142157 }
143158 err = json .Unmarshal (compositeDoc , compositeConfig )
144159 if err != nil {
145- log .Fatalf ("unmarshalling composite config: %s " , err )
160+ log .Fatalf ("unmarshalling composite config: %v " , err )
146161 }
147162
148163 if compositeConfig .Schema != composite .CompositeSchema {
@@ -151,7 +166,7 @@ and a 'composite template' file`,
151166
152167 err = template .Render (cmd .Context (), compositeConfig , validate )
153168 if err != nil {
154- log .Fatalf ("rendering the composite template: %s " , err )
169+ log .Fatalf ("rendering the composite template: %v " , err )
155170 }
156171 },
157172 }
0 commit comments