@@ -51,6 +51,7 @@ type templateClient struct {
51
51
configClient config.Client
52
52
gitHubClientFactory func (configVariablesClient config.VariablesClient ) (* github.Client , error )
53
53
processor yaml.Processor
54
+ httpClient * http.Client
54
55
}
55
56
56
57
// ensure templateClient implements TemplateClient.
@@ -70,6 +71,7 @@ func newTemplateClient(input TemplateClientInput) *templateClient {
70
71
configClient : input .configClient ,
71
72
gitHubClientFactory : getGitHubClient ,
72
73
processor : input .processor ,
74
+ httpClient : http .DefaultClient ,
73
75
}
74
76
}
75
77
@@ -143,8 +145,11 @@ func (t *templateClient) getURLContent(templateURL string) ([]byte, error) {
143
145
return nil , errors .Wrapf (err , "failed to parse %q" , templateURL )
144
146
}
145
147
146
- if rURL .Scheme == "https" && rURL .Host == "github.com" {
147
- return t .getGitHubFileContent (rURL )
148
+ if rURL .Scheme == "https" {
149
+ if rURL .Host == "github.com" {
150
+ return t .getGitHubFileContent (rURL )
151
+ }
152
+ return t .getRawURLFileContent (templateURL )
148
153
}
149
154
150
155
if rURL .Scheme == "file" || rURL .Scheme == "" {
@@ -210,6 +215,30 @@ func (t *templateClient) getGitHubFileContent(rURL *url.URL) ([]byte, error) {
210
215
return content , nil
211
216
}
212
217
218
+ func (t * templateClient ) getRawURLFileContent (rURL string ) ([]byte , error ) {
219
+ request , err := http .NewRequestWithContext (ctx , http .MethodGet , rURL , http .NoBody )
220
+ if err != nil {
221
+ return nil , err
222
+ }
223
+
224
+ response , err := t .httpClient .Do (request )
225
+ if err != nil {
226
+ return nil , err
227
+ }
228
+ defer response .Body .Close ()
229
+
230
+ if response .StatusCode != http .StatusOK {
231
+ return nil , errors .Errorf ("failed to get file, got %d" , response .StatusCode )
232
+ }
233
+
234
+ content , err := io .ReadAll (response .Body )
235
+ if err != nil {
236
+ return nil , err
237
+ }
238
+
239
+ return content , nil
240
+ }
241
+
213
242
func getGitHubClient (configVariablesClient config.VariablesClient ) (* github.Client , error ) {
214
243
var authenticatingHTTPClient * http.Client
215
244
if token , err := configVariablesClient .Get (config .GitHubTokenVariable ); err == nil {
0 commit comments