예제 #1
0
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
}
예제 #2
0
파일: server.go 프로젝트: grepory/awsthingy
// 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
}
예제 #3
0
파일: api.go 프로젝트: grepory/awsthingy
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)
	}
}
예제 #4
0
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
}
예제 #5
0
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)
}
예제 #6
0
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})
}