Exemple #1
0
func (uis *UIServer) projectPage(w http.ResponseWriter, r *http.Request) {

	_ = MustHaveProjectContext(r)
	_ = MustHaveUser(r)

	vars := mux.Vars(r)
	id := vars["project_id"]
	projRef, err := model.FindOneProjectRef(id)

	if err != nil {
		uis.LoggedError(w, r, http.StatusInternalServerError, err)
		return
	}
	projVars, err := model.FindOneProjectVars(id)

	if err != nil {
		uis.LoggedError(w, r, http.StatusInternalServerError, err)
		return
	}

	data := struct {
		ProjectRef  *model.ProjectRef
		ProjectVars *model.ProjectVars
	}{projRef, projVars}

	// the project context has all projects so make the ui list using all projects
	uis.WriteJSON(w, http.StatusOK, data)
}
Exemple #2
0
// FetchProjectVars is an API hook for returning the project variables
// associated with a task's project.
func (as *APIServer) FetchProjectVars(w http.ResponseWriter, r *http.Request) {
	task := MustHaveTask(r)
	projectVars, err := model.FindOneProjectVars(task.Project)
	if err != nil {
		as.LoggedError(w, r, http.StatusInternalServerError, err)
		return
	}
	if projectVars == nil {
		as.WriteJSON(w, http.StatusOK, apimodels.ExpansionVars{})
		return
	}

	as.WriteJSON(w, http.StatusOK, projectVars.Vars)
}
// FetchVarsHandler is an API hook for returning the project variables
// associated with a task's project.
func FetchVarsHandler(w http.ResponseWriter, r *http.Request) {
	task := plugin.GetTask(r)
	if task == nil {
		http.Error(w, "task not found", http.StatusNotFound)
		return
	}
	projectVars, err := model.FindOneProjectVars(task.Project)
	if err != nil {
		message := fmt.Sprintf("Failed to fetch vars for task %v: %v", task.Id, err)
		evergreen.Logger.Logf(slogger.ERROR, message)
		http.Error(w, message, http.StatusInternalServerError)
		return
	}
	if projectVars == nil {
		plugin.WriteJSON(w, http.StatusOK, ExpansionVars{})
		return
	}

	plugin.WriteJSON(w, http.StatusOK, projectVars.Vars)
	return
}