-
Notifications
You must be signed in to change notification settings - Fork 474
/
namespaces.go
78 lines (66 loc) · 2.21 KB
/
namespaces.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
package handlers
import (
"io/ioutil"
"net/http"
"github.com/gorilla/mux"
"github.com/kiali/kiali/log"
"github.com/kiali/kiali/models"
)
func NamespaceList(w http.ResponseWriter, r *http.Request) {
business, err := getBusiness(r)
if err != nil {
log.Error(err)
RespondWithError(w, http.StatusInternalServerError, err.Error())
return
}
namespaces, err := business.Namespace.GetNamespaces(r.Context())
if err != nil {
log.Error(err)
RespondWithError(w, http.StatusInternalServerError, err.Error())
return
}
RespondWithJSON(w, http.StatusOK, namespaces)
}
// NamespaceValidationSummary is the API handler to fetch validations summary to be displayed.
// It is related to all the Istio Objects within the namespace
func NamespaceValidationSummary(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
namespace := vars["namespace"]
business, err := getBusiness(r)
if err != nil {
log.Error(err)
RespondWithError(w, http.StatusInternalServerError, err.Error())
return
}
var validationSummary models.IstioValidationSummary
istioConfigValidationResults, errValidations := business.Validations.GetValidations(r.Context(), namespace, "", "")
if errValidations != nil {
log.Error(errValidations)
RespondWithError(w, http.StatusInternalServerError, errValidations.Error())
} else {
validationSummary = istioConfigValidationResults.SummarizeValidation(namespace)
}
RespondWithJSON(w, http.StatusOK, validationSummary)
}
// NamespaceUpdate is the API to perform a patch on a Namespace configuration
func NamespaceUpdate(w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
business, err := getBusiness(r)
if err != nil {
RespondWithError(w, http.StatusInternalServerError, "Namespace initialization error: "+err.Error())
return
}
namespace := params["namespace"]
body, err := ioutil.ReadAll(r.Body)
if err != nil {
RespondWithError(w, http.StatusBadRequest, "Update request with bad update patch: "+err.Error())
}
jsonPatch := string(body)
ns, err := business.Namespace.UpdateNamespace(r.Context(), namespace, jsonPatch)
if err != nil {
handleErrorResponse(w, err)
return
}
audit(r, "UPDATE on Namespace: "+namespace+" Patch: "+jsonPatch)
RespondWithJSON(w, http.StatusOK, ns)
}