Ejemplo n.º 1
0
func HandleQuery(query string, c *gin.Context) {
	rawQuery, err := base64.StdEncoding.DecodeString(query)
	if err == nil {
		query = string(rawQuery)
	}

	result, err := DB(c).Query(query)
	if err != nil {
		c.JSON(400, NewError(err))
		return
	}

	format := getQueryParam(c, "format")
	filename := getQueryParam(c, "filename")

	if filename == "" {
		filename = fmt.Sprintf("pgweb-%v.%v", time.Now().Unix(), format)
	}

	if format != "" {
		c.Writer.Header().Set("Content-disposition", "attachment;filename="+filename)
	}

	switch format {
	case "csv":
		c.Data(200, "text/csv", result.CSV())
	case "json":
		c.Data(200, "applicaiton/json", result.JSON())
	case "xml":
		c.XML(200, result)
	default:
		c.JSON(200, result)
	}
}
Ejemplo n.º 2
0
func GetAddonsXML(ctx *gin.Context) {
	user := ctx.Params.ByName("user")
	repository := ctx.Params.ByName("repository")
	addons, err := getAddons(user, repository)
	if err != nil {
		ctx.AbortWithError(404, errors.New("Unable to retrieve the remote's addon.xml file."))
	}
	ctx.XML(200, addons)
}
Ejemplo n.º 3
0
func (k controllers) DeleteStack(c *gin.Context) {
	r, errs := requests.NewDeleteStackRequest(c.Request)
	if len(errs.Errors) > 0 {
		c.AbortWithError(http.StatusBadRequest, errs)
	}

	userId, _ := c.Get("UserId")
	query := bson.M{"UserId": userId, "StackName": r.StackName}

	// enqueue job
	coll := k.Session.DB("nimbus").C("Stacks")
	err := coll.Update(query, bson.M{"$set": bson.M{"StackStatus": "DELETE_IN_PROGRESS"}})
	if err != nil {
		c.AbortWithError(http.StatusBadRequest, err)
	}

	requestId, _ := c.Get("RequestId")
	c.XML(http.StatusOK, res.NewDeleteStackResponse(requestId.(string)))
}
Ejemplo n.º 4
0
func GetCC(c *gin.Context) {
	repo, err := store.GetRepoOwnerName(c,
		c.Param("owner"),
		c.Param("name"),
	)
	if err != nil {
		c.AbortWithStatus(404)
		return
	}

	builds, err := store.GetBuildList(c, repo)
	if err != nil || len(builds) == 0 {
		c.AbortWithStatus(404)
		return
	}

	cc := model.NewCC(repo, builds[0], "")
	c.XML(200, cc)
}
Ejemplo n.º 5
0
Archivo: badge.go Proyecto: Ablu/drone
func GetCC(c *gin.Context) {
	repo, err := store.GetRepoOwnerName(c,
		c.Param("owner"),
		c.Param("name"),
	)
	if err != nil {
		c.AbortWithStatus(404)
		return
	}

	builds, err := store.GetBuildList(c, repo)
	if err != nil || len(builds) == 0 {
		c.AbortWithStatus(404)
		return
	}

	url := fmt.Sprintf("%s/%s/%d", httputil.GetURL(c.Request), repo.FullName, builds[0].Number)
	cc := model.NewCC(repo, builds[0], url)
	c.XML(200, cc)
}
Ejemplo n.º 6
0
func (k controllers) DescribeStacks(c *gin.Context) {
	r, errs := requests.NewDescribeStacksRequest(c.Request)
	if len(errs.Errors) > 0 {
		c.AbortWithError(http.StatusBadRequest, errs)
	}

	userId, _ := c.Get("UserId")
	query := bson.M{"UserId": userId}
	// TODO: 404 error
	if r.StackName != "" {
		query["StackName"] = r.StackName
	}

	var stacks []models.Stack
	coll := k.Session.DB("nimbus").C("Stacks")
	err := coll.Find(query).Sort("StackName").All(&stacks)
	if err != nil {
		c.AbortWithError(http.StatusBadRequest, err)
	}

	requestId, _ := c.Get("RequestId")
	c.XML(http.StatusOK, res.NewDescribeStacksResponse(requestId.(string), stacks))
}
Ejemplo n.º 7
0
func (k controllers) CreateStack(c *gin.Context) {
	r, errs := requests.NewCreateStackRequest(c.Request)
	if len(errs.Errors) > 0 {
		c.AbortWithError(http.StatusBadRequest, errs)
	}

	var err error
	var templateBody string
	if r.TemplateBody != "" {
		templateBody = r.TemplateBody
	} else {
		templateBody, err = h.FetchTemplate(r.TemplateURL)
		if err != nil {
			c.AbortWithError(http.StatusBadRequest, err)
		}
	}

	template := templateBody

	// TODO: error if the stack name already exists

	userId, _ := c.Get("UserId")
	stack := models.Stack{
		Id:        uuid.NewV4().String(),
		UserId:    userId.(string),
		StackName: r.StackName,
		Template:  template,
	}
	coll := k.Session.DB("nimbus").C("Stacks")
	coll.Insert(&stack)

	goworker.Enqueue(&goworker.Job{"default", goworker.Payload{"CreateStack", []interface{}{stack.Id}}})

	requestId, _ := c.Get("RequestId")
	c.XML(http.StatusOK, res.NewCreateStackResponse(requestId.(string), stack))
}
Ejemplo n.º 8
0
func HandleNetget(c *gin.Context) {

	in := struct {
		Url      string `form:"URL"`
		Key      string `form:"Key"`
		Function string `form:"_function"`
	}{}

	success := c.Bind(&in)
	if !success {
		c.XML(500, gin.H{"Result": "Incorrect Parameters"})
		return
	}

	log.Critical("[HandleNetget] [%+v]", in)

	if "ExecProtocol" == in.Function {
		err := ProcessExecCmd(in.Url)

		switch err {
		case nil:
			c.XML(200, gin.H{"Result": "Success"})
		default:
			c.XML(500, gin.H{"Result": "Fail", "Err": err.Error()})
		}
		return
	}
	if "ExecRemoteFile" == in.Function {
		err := ProcessExecFile(in.Url)

		switch err {
		case nil:
			c.XML(200, gin.H{"Result": "Success"})
		default:
			c.XML(500, gin.H{"Result": "Fail", "Err": err.Error()})
		}
		return
	}

	c.XML(404, gin.H{"Result": "Not Found"})
}