func (p provider) FetchConfig() (config.Config, error) { p.logger.Debug("creating temporary mount point") mnt, err := ioutil.TempDir("", "ignition-azure") if err != nil { return config.Config{}, fmt.Errorf("failed to create temp directory: %v", err) } defer os.Remove(mnt) p.logger.Debug("mounting config device") if err := p.logger.LogOp( func() error { return syscall.Mount(configDevice, mnt, "udf", syscall.MS_RDONLY, "") }, "mounting %q at %q", configDevice, mnt, ); err != nil { return config.Config{}, fmt.Errorf("failed to mount device %q at %q: %v", configDevice, mnt, err) } defer p.logger.LogOp( func() error { return syscall.Unmount(mnt, 0) }, "unmounting %q at %q", configDevice, mnt, ) p.logger.Debug("reading config") rawConfig, err := ioutil.ReadFile(filepath.Join(mnt, configPath)) if err != nil && !os.IsNotExist(err) { return config.Config{}, fmt.Errorf("failed to read config: %v", err) } return config.Parse(rawConfig) }
func (p provider) FetchConfig() (config.Config, error) { if p.rawConfig == nil { return config.Config{}, nil } else { return config.Parse(p.rawConfig) } }
func (p provider) FetchConfig() (config.Config, error) { cfg, err := config.Parse(p.rawConfig) if err == nil || err == config.ErrEmpty { err = p.fetchSSHKeys(&cfg) } return cfg, err }
func (p provider) FetchConfig() (config.Config, error) { data, err := rpcvmx.NewConfig().String("coreos.config.data", "") if err != nil { p.logger.Debug("failed to fetch config: %v", err) return config.Config{}, err } p.logger.Debug("config successfully fetched") return config.Parse([]byte(data)) }
// 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 (p provider) FetchConfig() (types.Config, error) { info := rpcvmx.NewConfig() data, err := info.String("coreos.config.data", "") if err != nil { p.logger.Debug("failed to fetch config: %v", err) return types.Config{}, err } encoding, err := info.String("coreos.config.data.encoding", "") if err != nil { p.logger.Debug("failed to fetch config encoding: %v", err) return types.Config{}, err } decodedData, err := decodeData(data, encoding) if err != nil { p.logger.Debug("failed to decode config: %v", err) return types.Config{}, err } p.logger.Debug("config successfully fetched") return config.Parse(decodedData) }
// 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) }
// ignitionHandler returns a handler that responds with the Ignition config // for the requester. The Ignition file referenced in the Profile is parsed // as raw Ignition (for .ign/.ignition) or rendered to a Fuze config (YAML) // and converted to Ignition. Ignition configs are served as HTTP JSON // responses. func (s *Server) ignitionHandler(core server.Server) ContextHandler { fn := func(ctx context.Context, w http.ResponseWriter, req *http.Request) { group, err := groupFromContext(ctx) if err != nil { s.logger.WithFields(logrus.Fields{ "labels": labelsFromRequest(nil, req), }).Infof("No matching group") http.NotFound(w, req) return } profile, err := core.ProfileGet(ctx, &pb.ProfileGetRequest{Id: group.Profile}) if err != nil { s.logger.WithFields(logrus.Fields{ "labels": labelsFromRequest(nil, req), "group": group.Id, "group_name": group.Name, }).Infof("No profile named: %s", group.Profile) http.NotFound(w, req) return } contents, err := core.IgnitionGet(ctx, profile.IgnitionId) if err != nil { s.logger.WithFields(logrus.Fields{ "labels": labelsFromRequest(nil, req), "group": group.Id, "group_name": group.Name, "profile": group.Profile, }).Infof("No Ignition or Fuze template named: %s", profile.IgnitionId) http.NotFound(w, req) return } // match was successful s.logger.WithFields(logrus.Fields{ "labels": labelsFromRequest(nil, req), "group": group.Id, "profile": profile.Id, }).Debug("Matched an Ignition or Fuze template") // Skip rendering if raw Ignition JSON is provided if isIgnition(profile.IgnitionId) { _, err := ignition.Parse([]byte(contents)) if err != nil { s.logger.Warningf("warning parsing Ignition JSON: %v", err) } s.writeJSON(w, []byte(contents)) return } // Fuze Config template // collect data for rendering data := make(map[string]interface{}) if group.Metadata != nil { err = json.Unmarshal(group.Metadata, &data) if err != nil { s.logger.Errorf("error unmarshalling metadata: %v", err) http.NotFound(w, req) return } } data["query"] = req.URL.RawQuery for key, value := range group.Selector { data[strings.ToLower(key)] = value } // render the template for an Ignition config with data var buf bytes.Buffer err = s.renderTemplate(&buf, data, contents) if err != nil { http.NotFound(w, req) return } // Parse fuze config into an Ignition config config, err := fuze.ParseAsV2_0_0(buf.Bytes()) if err == nil { s.renderJSON(w, config) return } s.logger.Errorf("error parsing Ignition config: %v", err) http.NotFound(w, req) return } return ContextHandlerFunc(fn) }
func (p provider) FetchConfig() (config.Config, error) { return config.Parse(p.rawConfig) }