aboutsummaryrefslogtreecommitdiffstats
path: root/src/clm/api/clusterhandler.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/clm/api/clusterhandler.go')
-rw-r--r--src/clm/api/clusterhandler.go31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/clm/api/clusterhandler.go b/src/clm/api/clusterhandler.go
index 84dd3230..75fcc561 100644
--- a/src/clm/api/clusterhandler.go
+++ b/src/clm/api/clusterhandler.go
@@ -28,10 +28,16 @@ import (
"net/textproto"
clusterPkg "github.com/onap/multicloud-k8s/src/clm/pkg/cluster"
+ "github.com/onap/multicloud-k8s/src/orchestrator/pkg/infra/validation"
"github.com/gorilla/mux"
)
+var cpJSONFile string = "json-schemas/metadata.json"
+var ckvJSONFile string = "json-schemas/cluster-kv.json"
+var clJSONFile string = "json-schemas/cluster-label.json"
+
+
// Used to store backend implementations objects
// Also simplifies mocking for unit testing purposes
type clusterHandler struct {
@@ -55,6 +61,12 @@ func (h clusterHandler) createClusterProviderHandler(w http.ResponseWriter, r *h
return
}
+ err, httpError := validation.ValidateJsonSchemaData(cpJSONFile, p)
+ if err != nil {
+ http.Error(w, err.Error(), httpError)
+ return
+ }
+
// Name is required.
if p.Metadata.Name == "" {
http.Error(w, "Missing name in POST request", http.StatusBadRequest)
@@ -148,6 +160,12 @@ func (h clusterHandler) createClusterHandler(w http.ResponseWriter, r *http.Requ
return
}
+ err, httpError := validation.ValidateJsonSchemaData(cpJSONFile, p)
+ if err != nil {
+ http.Error(w, err.Error(), httpError)
+ return
+ }
+
//Read the file section and ignore the header
file, _, err := r.FormFile("file")
if err != nil {
@@ -333,6 +351,12 @@ func (h clusterHandler) createClusterLabelHandler(w http.ResponseWriter, r *http
err := json.NewDecoder(r.Body).Decode(&p)
+ err, httpError := validation.ValidateJsonSchemaData(clJSONFile, p)
+ if err != nil {
+ http.Error(w, err.Error(), httpError)
+ return
+ }
+
// LabelName is required.
if p.LabelName == "" {
http.Error(w, "Missing label name in POST request", http.StatusBadRequest)
@@ -413,6 +437,13 @@ func (h clusterHandler) createClusterKvPairsHandler(w http.ResponseWriter, r *ht
err := json.NewDecoder(r.Body).Decode(&p)
+ // Verify JSON Body
+ err, httpError := validation.ValidateJsonSchemaData(ckvJSONFile, p)
+ if err != nil {
+ http.Error(w, err.Error(), httpError)
+ return
+ }
+
// KvPairsName is required.
if p.Metadata.Name == "" {
http.Error(w, "Missing Key Value pair name in POST request", http.StatusBadRequest)