Example #1
0
// LoadLocalConfig loads the local project config into a project
func loadLocalConfig(filepath string) (*model.Project, error) {
	f, err := os.Open(filepath)
	if err != nil {
		return nil, err
	}
	project := &model.Project{}
	err = util.ReadYAMLInto(f, project)
	if err != nil {
		return nil, err
	}
	return project, nil
}
Example #2
0
// GetVersionConfig fetches the config requests project details from the API server for a given project ID.
func (ac *APIClient) GetConfig(versionId string) (*model.Project, error) {
	resp, err := ac.get(fmt.Sprintf("versions/%v/config", versionId), nil)
	if err != nil {
		return nil, err
	}
	if resp.StatusCode != http.StatusOK {
		return nil, NewAPIError(resp)
	}
	ref := &model.Project{}
	if err := util.ReadYAMLInto(resp.Body, ref); err != nil {
		return nil, err
	}
	return ref, nil
}
Example #3
0
// validateProjectConfig returns a slice containing a list of any errors
// found in validating the given project configuration
func (as *APIServer) validateProjectConfig(w http.ResponseWriter, r *http.Request) {
	project := &model.Project{}
	validationErr := validator.ValidationError{}
	if err := util.ReadYAMLInto(r.Body, project); err != nil {
		validationErr.Message = err.Error()
		as.WriteJSON(w, http.StatusBadRequest, []validator.ValidationError{validationErr})
		return
	}
	syntaxErrs := validator.CheckProjectSyntax(project)
	semanticErrs := validator.CheckProjectSemantics(project)
	if len(syntaxErrs)+len(semanticErrs) != 0 {
		as.WriteJSON(w, http.StatusBadRequest, append(syntaxErrs, semanticErrs...))
		return
	}
	as.WriteJSON(w, http.StatusOK, []validator.ValidationError{})
}
Example #4
0
// loadSettings attempts to load the settings file
func loadSettings(opts *Options) (*Settings, error) {
	confPath := opts.ConfFile
	if confPath == "" {
		u, err := user.Current()
		if err != nil {
			return nil, err
		}
		confPath = filepath.Join(u.HomeDir, ".evergreen.yml")
	}
	f, err := os.Open(confPath)
	if err != nil {
		return nil, err
	}
	settings := &Settings{}
	err = util.ReadYAMLInto(f, settings)
	if err != nil {
		return nil, err
	}
	return settings, nil
}
Example #5
0
// LoadSettings attempts to load the settings file
func LoadSettings(opts *Options) (*model.CLISettings, error) {
	confPath := opts.ConfFile
	if confPath == "" {
		userHome, err := homedir.Dir()
		if err != nil {
			// workaround for cygwin if we're on windows but couldn't get a homedir
			if runtime.GOOS == "windows" && len(os.Getenv("HOME")) > 0 {
				userHome = os.Getenv("HOME")
			} else {
				return nil, err
			}
		}
		confPath = filepath.Join(userHome, ".evergreen.yml")
	}
	var f io.ReadCloser
	var err, extErr, extOpenErr error
	f, err = os.Open(confPath)
	if err != nil {
		// if we can't find the yml file in the home directory,
		// try to find it in the same directory as where the binary is being run from.
		// If we fail to determine that location, just return the first (outer) error.
		var currentBinPath string
		currentBinPath, extErr = osext.Executable()
		if extErr != nil {
			return nil, err
		}
		f, extOpenErr = os.Open(filepath.Join(filepath.Dir(currentBinPath), ".evergreen.yml"))
		if extOpenErr != nil {
			return nil, err
		}
	}

	settings := &model.CLISettings{}
	err = util.ReadYAMLInto(f, settings)
	if err != nil {
		return nil, err
	}
	settings.LoadedFrom = confPath
	return settings, nil
}