-
Notifications
You must be signed in to change notification settings - Fork 0
/
buildstatus_controller.go
96 lines (83 loc) · 2.83 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package buildstatus
import (
"html"
"net/http"
"time"
buildmodels "github.com/equinor/radix-api/api/buildstatus/models"
"github.com/equinor/radix-api/models"
radixhttp "github.com/equinor/radix-common/net/http"
radixv1 "github.com/equinor/radix-operator/pkg/apis/radix/v1"
"github.com/gorilla/mux"
)
const rootPath = "/applications/{appName}/environments/{envName}"
type buildStatusController struct {
*models.DefaultController
buildmodels.PipelineBadge
}
// NewBuildStatusController Constructor
func NewBuildStatusController(status buildmodels.PipelineBadge) models.Controller {
return &buildStatusController{PipelineBadge: 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
// - in: query
// name: pipeline
// description: Type of pipeline job to get status for.
// required: false
// default: build-deploy
// type: string
// enum: [build-deploy, deploy, promote]
// responses:
// "200":
// description: "Successful operation"
// "500":
// description: "Internal Server Error"
appName := mux.Vars(r)["appName"]
env := mux.Vars(r)["envName"]
pipeline := string(radixv1.BuildDeploy)
if queryPipeline := r.URL.Query().Get("pipeline"); len(queryPipeline) > 0 {
pipeline = html.EscapeString(queryPipeline)
}
buildStatusHandler := Init(accounts, bsc.PipelineBadge)
buildStatus, err := buildStatusHandler.GetBuildStatusForApplication(appName, env, pipeline)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
return
}
disableClientCaching(w)
radixhttp.ByteArrayResponse(w, r, "image/svg+xml; charset=utf-8", buildStatus)
}
func disableClientCaching(w http.ResponseWriter) {
header := w.Header()
header.Add("Cache-Control", "no-cache")
header.Add("Cache-Control", "no-store")
// Set expires to a time in the past to disable Github caching when embedding in markdown files
cacheUntil := time.Date(1984, 1, 1, 0, 0, 0, 0, time.UTC).Format(http.TimeFormat)
header.Set("Expires", cacheUntil)
}