summaryrefslogtreecommitdiffstats
path: root/src/k8splugin/api
diff options
context:
space:
mode:
authorLukasz Rajewski <lukasz.rajewski@orange.com>2022-02-03 19:18:07 +0100
committerLukasz Rajewski <lukasz.rajewski@orange.com>2022-02-23 14:27:01 +0100
commit88ecb1f9dfeded36e7fd74c776daefcaf67f8ae2 (patch)
tree321eb34967dd32a43d7e3ac62b5fd664e5b2231b /src/k8splugin/api
parent1f92a0ec4ea037089b82e3f80bb030f34fab64f0 (diff)
ConfigAPI and Query API improvements
- Config Template create from the definition content - Missing CRUD Config handlers added - Improved Rollback and Config delete - Query API name filtering improved Issue-ID: MULTICLOUD-1437 Signed-off-by: Lukasz Rajewski <lukasz.rajewski@orange.com> Change-Id: Iec8ec6d03746085f294d9318a252f1ae45d3b9c8
Diffstat (limited to 'src/k8splugin/api')
-rw-r--r--src/k8splugin/api/api.go4
-rw-r--r--src/k8splugin/api/confighandler.go120
-rw-r--r--src/k8splugin/api/instancehandler.go8
-rw-r--r--src/k8splugin/api/queryhandler.go12
4 files changed, 127 insertions, 17 deletions
diff --git a/src/k8splugin/api/api.go b/src/k8splugin/api/api.go
index a3e53dc8..4e84de70 100644
--- a/src/k8splugin/api/api.go
+++ b/src/k8splugin/api/api.go
@@ -143,6 +143,10 @@ func NewRouter(defClient rb.DefinitionManager,
instRouter.HandleFunc("/instance/{instID}/config/{cfgname}", configHandler.deleteAllHandler).Methods("DELETE")
instRouter.HandleFunc("/instance/{instID}/config/{cfgname}/delete", configHandler.deleteHandler).Methods("POST")
instRouter.HandleFunc("/instance/{instID}/config/{cfgname}/rollback", configHandler.rollbackHandler).Methods("POST")
+ instRouter.HandleFunc("/instance/{instID}/config/{cfgname}/tag", configHandler.tagListHandler).Methods("GET")
+ instRouter.HandleFunc("/instance/{instID}/config/{cfgname}/tag/{tagname}", configHandler.getTagHandler).Methods("GET")
+ instRouter.HandleFunc("/instance/{instID}/config/{cfgname}/version", configHandler.versionListHandler).Methods("GET")
+ instRouter.HandleFunc("/instance/{instID}/config/{cfgname}/version/{cfgversion}", configHandler.getVersionHandler).Methods("GET")
instRouter.HandleFunc("/instance/{instID}/config/{cfgname}/tagit", configHandler.tagitHandler).Methods("POST")
// Instance Healthcheck API
diff --git a/src/k8splugin/api/confighandler.go b/src/k8splugin/api/confighandler.go
index a4f08131..e3988064 100644
--- a/src/k8splugin/api/confighandler.go
+++ b/src/k8splugin/api/confighandler.go
@@ -74,7 +74,7 @@ func (h rbConfigHandler) createHandler(w http.ResponseWriter, r *http.Request) {
}
// getHandler handles GET operations on a particular config
-// Returns a app.Definition
+// Returns a config
func (h rbConfigHandler) getHandler(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
instanceID := vars["instID"]
@@ -95,8 +95,76 @@ func (h rbConfigHandler) getHandler(w http.ResponseWriter, r *http.Request) {
}
}
-// listHandler handles GET operations for all configs of instance
+// getVersionHandler handles GET operations on a particular config
+// Returns a config
+func (h rbConfigHandler) getVersionHandler(w http.ResponseWriter, r *http.Request) {
+ vars := mux.Vars(r)
+ instanceID := vars["instID"]
+ cfgName := vars["cfgname"]
+ cfgVersion := vars["cfgversion"]
+
+ ret, err := h.client.GetVersion(instanceID, cfgName, cfgVersion)
+ if err != nil {
+ http.Error(w, err.Error(), http.StatusInternalServerError)
+ return
+ }
+
+ w.Header().Set("Content-Type", "application/json")
+ w.WriteHeader(http.StatusOK)
+ err = json.NewEncoder(w).Encode(ret)
+ if err != nil {
+ http.Error(w, err.Error(), http.StatusInternalServerError)
+ return
+ }
+}
+
+// getTagHandler handles GET operations on a particular config
+// Returns a config
+func (h rbConfigHandler) getTagHandler(w http.ResponseWriter, r *http.Request) {
+ vars := mux.Vars(r)
+ instanceID := vars["instID"]
+ cfgName := vars["cfgname"]
+ tagName := vars["tagname"]
+
+ ret, err := h.client.GetTag(instanceID, cfgName, tagName)
+ if err != nil {
+ http.Error(w, err.Error(), http.StatusInternalServerError)
+ return
+ }
+
+ w.Header().Set("Content-Type", "application/json")
+ w.WriteHeader(http.StatusOK)
+ err = json.NewEncoder(w).Encode(ret)
+ if err != nil {
+ http.Error(w, err.Error(), http.StatusInternalServerError)
+ return
+ }
+}
+
+// getTagListHandler handles GET tag list operations on a particular config
// Returns a app.Definition
+func (h rbConfigHandler) tagListHandler(w http.ResponseWriter, r *http.Request) {
+ vars := mux.Vars(r)
+ instanceID := vars["instID"]
+ cfgName := vars["cfgname"]
+
+ ret, err := h.client.TagList(instanceID, cfgName)
+ if err != nil {
+ http.Error(w, err.Error(), http.StatusInternalServerError)
+ return
+ }
+
+ w.Header().Set("Content-Type", "application/json")
+ w.WriteHeader(http.StatusOK)
+ err = json.NewEncoder(w).Encode(ret)
+ if err != nil {
+ http.Error(w, err.Error(), http.StatusInternalServerError)
+ return
+ }
+}
+
+// listHandler handles GET operations for all configs of instance
+// Returns a config list
func (h rbConfigHandler) listHandler(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
instanceID := vars["instID"]
@@ -116,13 +184,41 @@ func (h rbConfigHandler) listHandler(w http.ResponseWriter, r *http.Request) {
}
}
+// listHandler handles GET operations for all configs of instance
+// Returns a config list
+func (h rbConfigHandler) versionListHandler(w http.ResponseWriter, r *http.Request) {
+ vars := mux.Vars(r)
+ instanceID := vars["instID"]
+ cfgName := vars["cfgname"]
+
+ ret, err := h.client.VersionList(instanceID, cfgName)
+ if err != nil {
+ http.Error(w, err.Error(), http.StatusInternalServerError)
+ return
+ }
+
+ w.Header().Set("Content-Type", "application/json")
+ w.WriteHeader(http.StatusOK)
+ err = json.NewEncoder(w).Encode(ret)
+ if err != nil {
+ http.Error(w, err.Error(), http.StatusInternalServerError)
+ return
+ }
+}
+
// deleteHandler handles DELETE operations on a config
func (h rbConfigHandler) deleteAllHandler(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
instanceID := vars["instID"]
cfgName := vars["cfgname"]
+ var err error
+
+ if r.URL.Query().Get("deleteConfigOnly") == "true" {
+ err = h.client.DeleteAll(instanceID, cfgName, true)
+ } else {
+ err = h.client.DeleteAll(instanceID, cfgName, false)
+ }
- err := h.client.DeleteAll(instanceID, cfgName)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
@@ -205,13 +301,18 @@ func (h rbConfigHandler) rollbackHandler(w http.ResponseWriter, r *http.Request)
http.Error(w, err.Error(), http.StatusUnprocessableEntity)
return
}
- err = h.client.Rollback(instanceID, cfgName, p)
+ ret, err := h.client.Rollback(instanceID, cfgName, p, false)
//err = h.client.Cleanup(instanceID)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
- w.WriteHeader(http.StatusNoContent)
+ w.WriteHeader(http.StatusOK)
+ err = json.NewEncoder(w).Encode(ret)
+ if err != nil {
+ http.Error(w, err.Error(), http.StatusInternalServerError)
+ return
+ }
}
// tagitHandler handles TAGIT operation
@@ -232,10 +333,15 @@ func (h rbConfigHandler) tagitHandler(w http.ResponseWriter, r *http.Request) {
return
}
- err = h.client.Tagit(instanceID, cfgName, p)
+ ret, err := h.client.Tagit(instanceID, cfgName, p)
+ if err != nil {
+ http.Error(w, err.Error(), http.StatusInternalServerError)
+ return
+ }
+ w.WriteHeader(http.StatusOK)
+ err = json.NewEncoder(w).Encode(ret)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
- w.WriteHeader(http.StatusNoContent)
}
diff --git a/src/k8splugin/api/instancehandler.go b/src/k8splugin/api/instancehandler.go
index 3fc514cd..e07bfcb0 100644
--- a/src/k8splugin/api/instancehandler.go
+++ b/src/k8splugin/api/instancehandler.go
@@ -184,10 +184,10 @@ func (i instanceHandler) statusHandler(w http.ResponseWriter, r *http.Request) {
func (i instanceHandler) queryHandler(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
id := vars["instID"]
- apiVersion := r.FormValue("ApiVersion")
- kind := r.FormValue("Kind")
- name := r.FormValue("Name")
- labels := r.FormValue("Labels")
+ apiVersion := r.URL.Query().Get("ApiVersion")
+ kind := r.URL.Query().Get("Kind")
+ name := r.URL.Query().Get("Name")
+ labels := r.URL.Query().Get("Labels")
if apiVersion == "" {
http.Error(w, "Missing ApiVersion mandatory parameter", http.StatusBadRequest)
return
diff --git a/src/k8splugin/api/queryhandler.go b/src/k8splugin/api/queryhandler.go
index f5950cdf..497767b0 100644
--- a/src/k8splugin/api/queryhandler.go
+++ b/src/k8splugin/api/queryhandler.go
@@ -33,12 +33,12 @@ type queryHandler struct {
// queryHandler retrieves information about specified resources for instance
func (i queryHandler) queryHandler(w http.ResponseWriter, r *http.Request) {
- namespace := r.FormValue("Namespace")
- cloudRegion := r.FormValue("CloudRegion")
- apiVersion := r.FormValue("ApiVersion")
- kind := r.FormValue("Kind")
- name := r.FormValue("Name")
- labels := r.FormValue("Labels")
+ namespace := r.URL.Query().Get("Namespace")
+ cloudRegion := r.URL.Query().Get("CloudRegion")
+ apiVersion := r.URL.Query().Get("ApiVersion")
+ kind := r.URL.Query().Get("Kind")
+ name := r.URL.Query().Get("Name")
+ labels := r.URL.Query().Get("Labels")
if cloudRegion == "" {
http.Error(w, "Missing CloudRegion mandatory parameter", http.StatusBadRequest)
return