55 "encoding/json"
66 "fmt"
77 "io"
8- "net/http"
98 "net/url"
109 "os"
1110 "path/filepath"
@@ -14,23 +13,6 @@ import (
1413 "k8s.io/apimachinery/pkg/util/yaml"
1514)
1615
17- type BuilderMap map [string ]Builder
18-
19- type CatalogBuilderMap map [string ]BuilderMap
20-
21- type builderFunc func (BuilderConfig ) Builder
22-
23- type Template struct {
24- catalogFile io.Reader
25- contributionFile io.Reader
26- validate bool
27- outputType string
28- registry image.Registry
29- registeredBuilders map [string ]builderFunc
30- }
31-
32- type TemplateOption func (t * Template )
33-
3416func WithCatalogFile (catalogFile io.Reader ) TemplateOption {
3517 return func (t * Template ) {
3618 t .catalogFile = catalogFile
@@ -79,10 +61,6 @@ func NewTemplate(opts ...TemplateOption) *Template {
7961 return temp
8062}
8163
82- type HttpGetter interface {
83- Get (url string ) (* http.Response , error )
84- }
85-
8664// FetchCatalogConfig will fetch the catalog configuration file from the given path.
8765// The path can be a local file path OR a URL that returns the raw contents of the catalog
8866// configuration file.
@@ -100,7 +78,7 @@ func FetchCatalogConfig(path string, httpGetter HttpGetter) (io.ReadCloser, erro
10078 }
10179 } else {
10280 // Evalute remote catalog config
103- // If URi is valid, execute fetch
81+ // If URI is valid, execute fetch
10482 tempResp , err := httpGetter .Get (catalogURI .String ())
10583 if err != nil {
10684 return nil , fmt .Errorf ("fetching remote catalog config file %q: %v" , path , err )
@@ -111,26 +89,37 @@ func FetchCatalogConfig(path string, httpGetter HttpGetter) (io.ReadCloser, erro
11189 return tempCatalog , nil
11290}
11391
114- // TODO(everettraven): do we need the context here? If so, how should it be used?
115- func ( t * Template ) Render ( ctx context. Context , validate bool ) error {
92+ func ( t * Template ) Parse () ( * Specs , error ) {
93+ var s Specs
11694
117- catalogFile , err := t .parseCatalogsSpec ()
95+ catalogSpec , err := t .parseCatalogsSpec ()
11896 if err != nil {
119- return err
97+ return nil , err
98+ }
99+ s .CatalogSpec = catalogSpec
100+
101+ contributionSpec , err := t .parseContributionSpec ()
102+ if err != nil {
103+ return nil , err
120104 }
105+ s .ContributionSpec = contributionSpec
106+
107+ return & s , nil
108+ }
121109
122- contributionFile , err := t .parseContributionSpec ()
110+ func (t * Template ) Render (ctx context.Context , validate bool ) error {
111+ specs , err := t .Parse ()
123112 if err != nil {
124113 return err
125114 }
126115
127- catalogBuilderMap , err := t .newCatalogBuilderMap (catalogFile .Catalogs , t .outputType )
116+ catalogBuilderMap , err := t .newCatalogBuilderMap (specs . CatalogSpec .Catalogs , t .outputType )
128117 if err != nil {
129118 return err
130119 }
131120
132121 // TODO(everettraven): should we return aggregated errors?
133- for _ , component := range contributionFile .Components {
122+ for _ , component := range specs . ContributionSpec .Components {
134123 if builderMap , ok := (* catalogBuilderMap )[component .Name ]; ok {
135124 if builder , ok := builderMap [component .Strategy .Template .Schema ]; ok {
136125 // run the builder corresponding to the schema
0 commit comments