// fetchReferencedConfig fetches, renders, and attempts to verify the requested // config. func (e Engine) fetchReferencedConfig(cfgRef types.ConfigReference) (types.Config, error) { rawCfg, err := util.FetchResource(e.Logger, url.URL(cfgRef.Source)) if err != nil { return types.Config{}, err } if err := util.AssertValid(cfgRef.Verification, rawCfg); err != nil { return types.Config{}, err } cfg, err := config.Parse(rawCfg) if err != nil { return types.Config{}, err } return e.renderConfig(cfg) }
func RenderFile(l *log.Logger, f types.File) *File { var contents []byte var err error fetch := func() error { contents, err = util.FetchResource(l, url.URL(f.Contents.Source)) return err } validate := func() error { return util.AssertValid(f.Contents.Verification, contents) } decompress := func() error { contents, err = decompressFile(l, f, contents) return err } if l.LogOp(fetch, "fetching file %q", f.Path) != nil { return nil } if l.LogOp(validate, "validating file contents") != nil { return nil } if l.LogOp(decompress, "decompressing file contents") != nil { return nil } return &File{ Path: f.Path, Contents: []byte(contents), Mode: os.FileMode(f.Mode), Uid: f.User.Id, Gid: f.Group.Id, } }
// fetchReferencedConfig fetches, renders, and attempts to verify the requested // config. func (e Engine) fetchReferencedConfig(cfgRef types.ConfigReference) (types.Config, error) { var rawCfg []byte switch cfgRef.Source.Scheme { case "http": rawCfg = util.NewHttpClient(e.Logger). FetchConfig(cfgRef.Source.String(), http.StatusOK, http.StatusNoContent) if rawCfg == nil { return types.Config{}, ErrNetworkFailure } default: return types.Config{}, ErrSchemeUnsupported } if err := util.AssertValid(cfgRef.Verification, rawCfg); err != nil { return types.Config{}, err } cfg, err := config.Parse(rawCfg) if err != nil { return types.Config{}, err } return e.renderConfig(cfg) }