func GetJobIdsFrom(request *web.Request) (jobIds []string, err error) { jobIdsString := request.FormValue("jobIds") if jobIdsString == "" { err = &ServerError{"Missing path parameter 'jobIds', e.g. ?jobIds=id1,id2,my-big-job"} return } jobIds = strings.Split(jobIdsString, ",") return }
// FIXME: combine presence validation of path params and form value // FIXME: this is case sensitive which is wrong func validatePresenceRequest(r *web.Request, keys ...string) bool { ok := true for _, k := range keys { if r.FormValue(k) == "" { ok = false break } } return ok }
func (c *ApiContext) ValidateAwsCredentials(rw web.ResponseWriter, r *web.Request, next web.NextMiddlewareFunc) { if ok := validatePresenceRequest(r, "AWS_ACCESS_KEY_ID", "AWS_SECRET_ACCESS_KEY"); !ok { rw.WriteHeader(http.StatusUnauthorized) writeJson(rw, map[string]string{ "error": "missing credentials", }) } else { creds := credentials.NewStaticCredentials(r.FormValue("AWS_ACCESS_KEY_ID"), r.FormValue("AWS_SECRET_ACCESS_KEY"), "") c.AwsCredentials = creds next(rw, r) } }
func (this *RequestHandler) writeSendingFailuresToFile(response web.ResponseWriter, request *web.Request) (err error) { targetFile := request.FormValue("targetFile") if targetFile == "" { return &ServerError{"targetFile must not be empty"} } jobIds, err := GetJobIdsFrom(request) if err != nil { return } err = this.Repository.WriteSendingFailuresToFile(targetFile, jobIds) return }
func (c *context) parseRequest(rw web.ResponseWriter, req *web.Request, next web.NextMiddlewareFunc) { // GET /v2/token/?service=registry.docker.com&scope=repository:samalba/my-app:push&account=jlhawn HTTP/1.1 c.authReq.Account = req.FormValue("account") c.authReq.Service = req.FormValue("service") scope := req.FormValue("scope") if scope != "" { parts := strings.Split(scope, ":") if len(parts) != 3 { http.Error(rw, fmt.Sprintf("invalid scope: %q", scope), http.StatusBadRequest) return } c.authReq.Type = parts[0] c.authReq.Name = parts[1] if strings.Contains(parts[1], "/") { nr := strings.SplitN(parts[1], "/", 2) c.namespace = nr[0] c.repo = nr[1] } else { c.namespace = "library" c.repo = parts[1] } c.permsWant = strings.Split(parts[2], ",") } next(rw, req) }
func (ctx *Context) SignupPost(w web.ResponseWriter, r *web.Request) { user := &models.User{ Name: r.FormValue("name"), Email: r.FormValue("email"), Password: r.FormValue("password"), } Render.HTML(w, http.StatusOK, "signup", PageData{"Title": "Sign up right NOW!!!", "User": user}) }