Beispiel #1
0
func (Creator) Create(logger *log.Logger) providers.Provider {
	return &provider{
		logger:  logger,
		backoff: initialBackoff,
		client:  util.NewHttpClient(logger),
	}
}
Beispiel #2
0
func fetchFile(l *log.Logger, f types.File) ([]byte, error) {
	switch f.Contents.Source.Scheme {
	case "http":
		client := util.NewHttpClient(l)
		data, status, err := client.Get(f.Contents.Source.String())
		if err != nil {
			return nil, err
		}

		l.Debug("GET result: %s", http.StatusText(status))
		if status != http.StatusOK {
			return nil, ErrStatusBad
		}

		return data, nil
	case "data":
		url, err := dataurl.DecodeString(f.Contents.Source.String())
		if err != nil {
			return nil, err
		}

		return url.Data, nil
	default:
		return nil, ErrSchemeUnsupported
	}
}
Beispiel #3
0
// 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)
}