Ejemplo n.º 1
0
func deployInfo(w http.ResponseWriter, r *http.Request, t auth.Token) error {
	u, err := t.User()
	if err != nil {
		return err
	}
	depId := r.URL.Query().Get(":deploy")
	deploy, err := app.GetDeploy(depId, u)
	if err != nil {
		return &errors.HTTP{Code: http.StatusNotFound, Message: err.Error()}
	}
	var data interface{}
	if deploy.Origin == "git" {
		data = &app.DiffDeployData{DeployData: *deploy}
	} else {
		data = deploy
	}
	return json.NewEncoder(w).Encode(data)
}
Ejemplo n.º 2
0
// title: deploy info
// path: /deploys/{deploy}
// method: GET
// produce: application/json
// responses:
//   200: OK
//   401: Unauthorized
//   404: Not found
func deployInfo(w http.ResponseWriter, r *http.Request, t auth.Token) error {
	depID := r.URL.Query().Get(":deploy")
	deploy, err := app.GetDeploy(depID)
	if err != nil {
		if err == event.ErrEventNotFound {
			return &tsuruErrors.HTTP{Code: http.StatusNotFound, Message: "Deploy not found."}
		}
		return err
	}
	dbApp, err := app.GetByName(deploy.App)
	if err != nil {
		return err
	}
	canGet := permission.Check(t, permission.PermAppReadDeploy, contextsForApp(dbApp)...)
	if !canGet {
		return &tsuruErrors.HTTP{Code: http.StatusNotFound, Message: "Deploy not found."}
	}
	w.Header().Add("Content-Type", "application/json")
	return json.NewEncoder(w).Encode(deploy)
}
Ejemplo n.º 3
0
func deployInfo(w http.ResponseWriter, r *http.Request, t auth.Token) error {
	depId := r.URL.Query().Get(":deploy")
	deploy, err := app.GetDeploy(depId)
	if err != nil {
		return &errors.HTTP{Code: http.StatusNotFound, Message: err.Error()}
	}
	diff, err := app.GetDiffInDeploys(deploy)
	if err != nil {
		return err
	}
	data := map[string]interface{}{
		"Id":        deploy.ID.Hex(),
		"App":       deploy.App,
		"Timestamp": deploy.Timestamp.Format(time.RFC3339),
		"Duration":  deploy.Duration.Seconds(),
		"Commit":    deploy.Commit,
		"Error":     deploy.Error,
		"Diff":      diff,
	}
	return json.NewEncoder(w).Encode(data)
}
Ejemplo n.º 4
0
func deployInfo(w http.ResponseWriter, r *http.Request, t auth.Token) error {
	depId := r.URL.Query().Get(":deploy")
	deploy, err := app.GetDeploy(depId)
	if err != nil {
		return err
	}
	dbApp, err := app.GetByName(deploy.App)
	if err != nil {
		return err
	}
	canGet := permission.Check(t, permission.PermAppReadDeploy,
		append(permission.Contexts(permission.CtxTeam, dbApp.Teams),
			permission.Context(permission.CtxApp, dbApp.Name),
			permission.Context(permission.CtxPool, dbApp.Pool),
		)...,
	)
	if !canGet {
		return &errors.HTTP{Code: http.StatusNotFound, Message: "Deploy not found."}
	}
	var data interface{}
	data = deploy
	return json.NewEncoder(w).Encode(data)
}