in internal/generators/static.go [60:103]
func (sg *StaticGenerator) Install(c *core.Component) (err error) {
if strings.EqualFold(c.Method, "http") {
// validate that `Source` points to a yaml file
validSourceExtensions := []string{".yaml", ".yml"}
isValidExtension := func() bool {
sourceExt := strings.ToLower(filepath.Ext(c.Source))
for _, validExt := range validSourceExtensions {
if sourceExt == validExt {
return true
}
}
return false
}()
if !isValidExtension {
return fmt.Errorf("source for 'static' component '%s' must end in one of %v; given: '%s'", c.Name, validSourceExtensions, c.Source)
}
response, err := http.Get(c.Source)
if err != nil {
return err
}
defer response.Body.Close()
componentsPath := path.Join(c.PhysicalPath, "components", c.Name)
if err := os.MkdirAll(componentsPath, 0777); err != nil {
return err
}
// Write the downloaded resource manifest file
out, err := os.Create(path.Join(componentsPath, c.Name+".yaml"))
if err != nil {
logger.Error(emoji.Sprintf(":no_entry_sign: Error occurred in install for component '%s'\nError: %s", c.Name, err))
return err
}
defer out.Close()
if _, err = io.Copy(out, response.Body); err != nil {
logger.Error(emoji.Sprintf(":no_entry_sign: Error occurred in writing manifest file for component '%s'\nError: %s", c.Name, err))
return err
}
}
return nil
}