func (h DeployLogHandler) ServeHTTP(w http.ResponseWriter, r *http.Request, fullEnv string, environment config.Environment, projectName string) { u, err := auth.CurrentUser(r) if err != nil { glog.Errorf("Failed to get current user: %v", err) http.Error(w, err.Error(), http.StatusUnauthorized) return } d, err := readEntries(fullEnv) if err != nil { glog.Errorf("Failed to read entries: %v", err) } t, err := template.New("deploy_log.html").ParseFiles("templates/deploy_log.html", "templates/base.html") if err != nil { glog.Errorf("Failed to parse templates: %v", err) http.Error(w, err.Error(), http.StatusInternalServerError) return } for i := range d { d[i].FormattedTime = formatTime(d[i].Time) } sort.Sort(ByTime(d)) js, css := h.assets.Templates() params := map[string]interface{}{ "Javascript": js, "Stylesheet": css, "Deployments": d, "User": u, "Env": fullEnv, "Environment": environment, "ProjectName": projectName, } helpers.RespondWithTemplate(w, "text/html", t, "base", params) }
func (h deployPage) ServeHTTP(w http.ResponseWriter, r *http.Request) { user, err := auth.CurrentUser(r) if err != nil { glog.Errorf("Failed to get current user: %v", err) http.Error(w, err.Error(), http.StatusUnauthorized) return } p := r.FormValue("project") env := r.FormValue("environment") fromRevision := r.FormValue("from_revision") toRevision := r.FormValue("to_revision") repoOwner := r.FormValue("repo_owner") repoName := r.FormValue("repo_name") t, err := template.New("deploy.html").ParseFiles("templates/deploy.html", "templates/base.html") if err != nil { glog.Errorf("Failed to parse templates: %v", err) http.Error(w, err.Error(), http.StatusInternalServerError) return } js, css := h.assets.Templates() params := map[string]interface{}{ "Javascript": js, "Stylesheet": css, "Project": p, "Env": env, "User": user, "PushAddress": h.pushAddr, "RepoOwner": repoOwner, "RepoName": repoName, "ToRevision": toRevision, "FromRevision": fromRevision, } helpers.RespondWithTemplate(w, "text/html", t, "base", params) }
func (h HomeHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { c, err := config.Load(h.ecl) if err != nil { glog.Errorf("Failed to Parse to ETCD data %s", err) http.Error(w, err.Error(), http.StatusInternalServerError) return } u, err := auth.CurrentUser(r) if err != nil { glog.Errorf("Failed to get current user: %v", err) http.Error(w, err.Error(), http.StatusUnauthorized) return } t, err := template.New("index.html").ParseFiles("templates/index.html", "templates/base.html") if err != nil { glog.Errorf("Failed to parse template: %v", err) http.Error(w, err.Error(), http.StatusInternalServerError) return } projs := acl.ReadableProjects(h.ac, c.Projects, u) sort.Sort(ByName(c.Projects)) // columns maps a plugin name to a list of columns columns := make(map[string][]plugin.Column) for _, pl := range plugin.Plugins { for _, p := range c.Projects { cols, err := pl.Apply(p) if err != nil { glog.Errorf("Failed to apply plugin: %s", err) http.Error(w, err.Error(), http.StatusInternalServerError) return } columns[p.Name] = append(columns[p.Name], cols...) } } js, css := h.assets.Templates() gt := os.Getenv(gitHubAPITokenEnvVar) pt := c.Pivotal.Token params := map[string]interface{}{ "Javascript": js, "Stylesheet": css, "Projects": projs, "PluginColumns": columns, "User": u, "Page": "home", "ConfirmDeployFlag": *confirmDeployFlag, "GithubToken": gt, "PivotalToken": pt, } helpers.RespondWithTemplate(w, "text/html", t, "base", params) }