-
Notifications
You must be signed in to change notification settings - Fork 0
/
buildstatus_controller.go
71 lines (60 loc) · 1.92 KB
/
buildstatus_controller.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package buildstatus
import (
"net/http"
build_models "github.com/equinor/radix-api/api/buildstatus/models"
"github.com/equinor/radix-api/api/utils"
"github.com/equinor/radix-api/models"
"github.com/gorilla/mux"
)
const rootPath = "/applications/{appName}/environments/{envName}"
type buildStatusController struct {
*models.DefaultController
build_models.Status
}
// NewBuildStatusController Constructor
func NewBuildStatusController(status build_models.Status) models.Controller {
return &buildStatusController{Status: status}
}
// GetRoutes List the supported routes of this handler
func (bsc *buildStatusController) GetRoutes() models.Routes {
routes := models.Routes{
models.Route{
Path: rootPath + "/buildstatus",
Method: "GET",
HandlerFunc: bsc.GetBuildStatus,
AllowUnauthenticatedUsers: true,
},
}
return routes
}
// GetBuildStatus reveals build status for selected environment
func (bsc *buildStatusController) GetBuildStatus(accounts models.Accounts, w http.ResponseWriter, r *http.Request) {
// swagger:operation GET /applications/{appName}/environments/{envName}/buildstatus buildstatus getBuildStatus
// ---
// summary: Show the application buildStatus
// parameters:
// - name: appName
// in: path
// description: name of Radix application
// type: string
// required: true
// - name: envName
// in: path
// description: name of the environment
// type: string
// required: true
// responses:
// "200":
// description: "Successful operation"
// "404":
// description: "Not found"
appName := mux.Vars(r)["appName"]
env := mux.Vars(r)["envName"]
buildStatusHandler := Init(accounts, bsc.Status)
buildStatus, err := buildStatusHandler.GetBuildStatusForApplication(appName, env)
if err != nil {
utils.ErrorResponse(w, r, err)
return
}
utils.ByteArrayResponse(w, r, "image/svg+xml; charset=utf-8", *buildStatus)
}