diff options
author | Ritu Sood <Ritu.Sood@intel.com> | 2020-09-11 00:04:32 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2020-09-11 00:04:32 +0000 |
commit | b9e5d308a5e357d987758005e928f825d773ccca (patch) | |
tree | e8eb4213cce343ea8b2eeec1d8c7eb98f4608eb5 /src/clm/api/clusterhandler.go | |
parent | 172bebb96ce3ef47f5514c5f7a9a2b70d583f31c (diff) | |
parent | b2c9f4c61d00bf18e7a253c410479f8124640106 (diff) |
Merge "Adding validations for all JSON data across modules"
Diffstat (limited to 'src/clm/api/clusterhandler.go')
-rw-r--r-- | src/clm/api/clusterhandler.go | 31 |
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) |