5
5
"encoding/json"
6
6
"fmt"
7
7
"io"
8
- "net/http"
9
8
"net/url"
10
9
"os"
11
10
"path/filepath"
@@ -14,23 +13,6 @@ import (
14
13
"k8s.io/apimachinery/pkg/util/yaml"
15
14
)
16
15
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
-
34
16
func WithCatalogFile (catalogFile io.Reader ) TemplateOption {
35
17
return func (t * Template ) {
36
18
t .catalogFile = catalogFile
@@ -79,10 +61,6 @@ func NewTemplate(opts ...TemplateOption) *Template {
79
61
return temp
80
62
}
81
63
82
- type HttpGetter interface {
83
- Get (url string ) (* http.Response , error )
84
- }
85
-
86
64
// FetchCatalogConfig will fetch the catalog configuration file from the given path.
87
65
// The path can be a local file path OR a URL that returns the raw contents of the catalog
88
66
// configuration file.
@@ -100,7 +78,7 @@ func FetchCatalogConfig(path string, httpGetter HttpGetter) (io.ReadCloser, erro
100
78
}
101
79
} else {
102
80
// Evalute remote catalog config
103
- // If URi is valid, execute fetch
81
+ // If URI is valid, execute fetch
104
82
tempResp , err := httpGetter .Get (catalogURI .String ())
105
83
if err != nil {
106
84
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
111
89
return tempCatalog , nil
112
90
}
113
91
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
116
94
117
- catalogFile , err := t .parseCatalogsSpec ()
95
+ catalogSpec , err := t .parseCatalogsSpec ()
118
96
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
120
104
}
105
+ s .ContributionSpec = contributionSpec
106
+
107
+ return & s , nil
108
+ }
121
109
122
- contributionFile , err := t .parseContributionSpec ()
110
+ func (t * Template ) Render (ctx context.Context , validate bool ) error {
111
+ specs , err := t .Parse ()
123
112
if err != nil {
124
113
return err
125
114
}
126
115
127
- catalogBuilderMap , err := t .newCatalogBuilderMap (catalogFile .Catalogs , t .outputType )
116
+ catalogBuilderMap , err := t .newCatalogBuilderMap (specs . CatalogSpec .Catalogs , t .outputType )
128
117
if err != nil {
129
118
return err
130
119
}
131
120
132
121
// TODO(everettraven): should we return aggregated errors?
133
- for _ , component := range contributionFile .Components {
122
+ for _ , component := range specs . ContributionSpec .Components {
134
123
if builderMap , ok := (* catalogBuilderMap )[component .Name ]; ok {
135
124
if builder , ok := builderMap [component .Strategy .Template .Schema ]; ok {
136
125
// run the builder corresponding to the schema
0 commit comments