示例#1
0
func ViewWebhook(ctx *context.Context) {
	ctx.Data["Title"] = "View Webhook"
	ctx.Data["PageIsWebhook"] = true
	ctx.Data["RequireHighlightJS"] = true

	webhook, err := models.GetWebhookByID(ctx.ParamsInt64(":id"))
	if err != nil {
		if errors.IsWebhookNotFound(err) {
			ctx.Handle(404, "GetWebhookByID", nil)
		} else {
			ctx.Handle(500, "GetWebhookByID", err)
		}
		return
	}
	ctx.Data["Webhook"] = webhook

	// Prettify JSON in case it is not.
	buf := new(bytes.Buffer)
	if err = json.Indent(buf, []byte(webhook.Payload), "", "  "); err != nil {
		ctx.Handle(500, "json.Indent", err)
		return
	}
	webhook.Payload = buf.String()

	ctx.HTML(200, "webhook/view")
}
示例#2
0
func DeleteApplication(ctx *context.Context) {
	if err := models.DeleteApplicationByID(ctx.ParamsInt64(":id")); err != nil {
		ctx.Error(500, err.Error())
		return
	}

	ctx.Redirect("/applications")
}
示例#3
0
func RegenerateApplicationSecret(ctx *context.Context) {
	if err := models.RegenerateApplicationToken(ctx.ParamsInt64(":id")); err != nil {
		ctx.Error(500, err.Error())
		return
	}

	ctx.Redirect(fmt.Sprintf("/applications/%d", ctx.ParamsInt64(":id")))
}
示例#4
0
func DeleteCollector(ctx *context.Context) {
	if err := models.DeleteCollectorByID(ctx.ParamsInt64(":id")); err != nil {
		ctx.Error(500, err.Error())
		return
	}

	ctx.Redirect("/collectors")
}
示例#5
0
func RegenerateCollectorSecret(ctx *context.Context) {
	if err := models.RegenerateCollectorSecret(ctx.ParamsInt64(":id")); err != nil {
		ctx.Error(500, err.Error())
		return
	}

	ctx.Redirect(fmt.Sprintf("/collectors/%d", ctx.ParamsInt64(":id")))
}
示例#6
0
func parseApplicationByID(ctx *context.Context) *models.Application {
	app, err := models.GetApplicationByID(ctx.ParamsInt64(":id"))
	if err != nil {
		if errors.IsApplicationNotFound(err) {
			ctx.Handle(404, "EditApplication", nil)
		} else {
			ctx.Handle(500, "GetApplicationByID", err)
		}
		return nil
	}
	ctx.Data["Application"] = app
	return app
}
示例#7
0
func parseCollectorByID(ctx *context.Context) *models.Collector {
	collector, err := models.GetCollectorByID(ctx.ParamsInt64(":id"))
	if err != nil {
		if errors.IsCollectorNotFound(err) {
			ctx.Handle(404, "EditApplication", nil)
		} else {
			ctx.Handle(500, "GetCollectorByID", err)
		}
		return nil
	}
	ctx.Data["Collector"] = collector
	return collector
}