-
Notifications
You must be signed in to change notification settings - Fork 87
/
gitops.go
53 lines (43 loc) · 1.15 KB
/
gitops.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
package handlers
import (
"net/http"
"github.com/gorilla/mux"
"github.com/replicatedhq/kots/kotsadm/pkg/app"
"github.com/replicatedhq/kots/kotsadm/pkg/gitops"
"github.com/replicatedhq/kots/kotsadm/pkg/logger"
)
func DisableAppGitOps(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Headers", "content-type, origin, accept, authorization")
if r.Method == "OPTIONS" {
w.WriteHeader(http.StatusOK)
return
}
if err := requireValidSession(w, r); err != nil {
logger.Error(err)
return
}
appID := mux.Vars(r)["appId"]
clusterID := mux.Vars(r)["clusterId"]
a, err := app.Get(appID)
if err != nil {
logger.Error(err)
w.WriteHeader(http.StatusInternalServerError)
return
}
downstreamGitOps, err := gitops.GetDownstreamGitOps(a.ID, clusterID)
if err != nil {
logger.Error(err)
w.WriteHeader(http.StatusInternalServerError)
return
}
if downstreamGitOps != nil {
err := gitops.DisableDownstreamGitOps(a.ID, clusterID)
if err != nil {
logger.Error(err)
w.WriteHeader(http.StatusInternalServerError)
return
}
}
JSON(w, http.StatusNoContent, "")
}