Beispiel #1
0
// getRawConfig gets the raw configuration data from p.configUrl.
// Supported URL schemes are:
// http://	remote resource accessed via http
// oem://	local file in /usr/share/oem or /mnt/oem
func (p *provider) getRawConfig() bool {
	url, err := url.Parse(p.configUrl)
	if err != nil {
		p.logger.Err("failed to parse url: %v", err)
		return false
	}

	data, err := util.FetchResource(p.logger, *url)
	if err != nil {
		p.logger.Err("failed to fetch %v: %v", url, err)
		return false
	}

	p.rawConfig = data
	return true
}
Beispiel #2
0
// 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)
}
Beispiel #3
0
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,
	}
}