Move schema validation to load schema 03/7503/9
authorsubhash kumar singh <subhash.kumar.singh@huawei.com>
Fri, 18 Aug 2017 06:39:45 +0000 (12:09 +0530)
committersubhash kumar singh <subhash.kumar.singh@huawei.com>
Fri, 18 Aug 2017 07:05:17 +0000 (07:05 +0000)
Move schema validation to load schema.

Issue-Id: CLI-25
Change-Id: I68855caf80cf1b55b41916e124a53b53e7af93d3
Signed-off-by: Subhash Kumar Singh <Subhash.Kumar.Singh@huawei.com>
.gitignore
framework/src/main/java/org/onap/cli/fw/conf/Constants.java
framework/src/main/java/org/onap/cli/fw/conf/OnapCommandConfg.java
framework/src/main/java/org/onap/cli/fw/error/OnapCommandHttpInvalidResultMap.java [new file with mode: 0644]
framework/src/main/resources/onap.properties
framework/src/test/resources/onap.properties

index 97767e1..9b8e81a 100644 (file)
@@ -6,3 +6,6 @@ coverage-report/
 .classpath
 .class
 .checkstyle
+*.iml
+*.log
+.idea
index f6a4193..d559f7a 100644 (file)
@@ -22,6 +22,25 @@ package org.onap.cli.fw.conf;
  */
 public class Constants {
 
+    // schema validation
+    public static final String TOP_LEVEL_PARAMS_LIST ="cli.schema.top_level_params_list";
+    public static final String TOP_LEVEL_MANDATORY_LIST ="cli.schema.top_level_mandatory_list";
+    public static final String SERVICE_PARAMS_LIST ="cli.schema.service_params_list";
+    public static final String SERVICE_PARAMS_MANDATORY_LIST ="cli.schema.service_params_mandatory_list";
+    public static final String INPUT_PARAMS_LIST ="cli.schema.input_params_list";
+    public static final String INPUT_PARAMS_MANDATORY_LIST ="cli.schema.input_params_mandatory_list";
+    public static final String RESULT_PARAMS_LIST ="cli.schema.result_params_list";
+    public static final String RESULT_PARAMS_MANDATORY_LIST ="cli.schema.result_params_mandatory_list";
+    public static final String HTTP_SECTIONS ="cli.schema.http_sections";
+    public static final String HTTP_MANDATORY_SECTIONS ="cli.schema.http_mandatory_sections";
+    public static final String HTTP_REQUEST_PARAMS ="cli.schema.http_request_params";
+    public static final String HTTP_REQUEST_MANDATORY_PARAMS ="cli.schema.http_request_mandatory_params";
+    public static final String HTTP_METHODS ="cli.schema.http_methods";
+    public static final String BOOLEAN_VALUE ="cli.schema.boolean_values";
+    public static final String AUTH_VALUES="cli.schema.auth_values";
+    public static final String MODE_VALUES="cli.schema.mode_values";
+
+
     public static final String SSLCONTEST_TLS = "TLSV1.2";
     public static final String APPLICATION_JSON = "application/json";
     public static final String X_AUTH_TOKEN = "x-auth-token";
index acb2c2b..1dfd345 100644 (file)
@@ -19,6 +19,7 @@ package org.onap.cli.fw.conf;
 import java.io.IOException;
 import java.util.Arrays;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 import java.util.Properties;
 import java.util.Set;
@@ -133,4 +134,9 @@ public final class OnapCommandConfg {
         return Arrays.stream(prps.getProperty(Constants.NO_AUTH_ENABLE_INCLUDE_PARAMS_EXTERNAL_CMD)
                 .split(",")).map(String::trim).collect(Collectors.toSet());
     }
+
+    public static List<String> getSchemaAttrInfo(String key) {
+        return Arrays.stream(prps.getProperty(key).split(",")).map(String::trim).collect(Collectors.toList());
+    }
+
 }
diff --git a/framework/src/main/java/org/onap/cli/fw/error/OnapCommandHttpInvalidResultMap.java b/framework/src/main/java/org/onap/cli/fw/error/OnapCommandHttpInvalidResultMap.java
new file mode 100644 (file)
index 0000000..491f18c
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.cli.fw.error;
+
+import java.util.List;
+
+/**
+ * Invalid result map in HTTP section.
+ *
+ */
+public class OnapCommandHttpInvalidResultMap extends OnapCommandException {
+
+    private static final long serialVersionUID = 6676137916023457963L;
+
+    public OnapCommandHttpInvalidResultMap(List<String> invalidParams) {
+        super("0x0028", "Invalide result map parameters : " + invalidParams.toString());
+    }
+}
index 84a86e8..8a2756e 100644 (file)
@@ -21,4 +21,29 @@ cli.http.basic.common_headers.x-app-id=X-FromAppId
 cli.http.basic.common_headers.x-app-id.value=onap-cli
 
 #TODO mrkanag add support for aaf like defined above for basic
-#cli.service.auth=aaf
\ No newline at end of file
+#cli.service.auth=aaf
+
+#schema validation
+cli.schema.top_level_params_list=onap_cmd_schema_version,name,description,service,parameters,results,http
+cli.schema.top_level_mandatory_list=onap_cmd_schema_version
+
+cli.schema.service_params_list=name,version,auth,mode
+cli.schema.service_params_mandatory_list=name,version
+
+cli.schema.input_params_list=name,description,type,short_option,long_option, is_optional,default_value,is_secured
+cli.schema.input_params_mandatory_list=name,description,type
+
+cli.schema.result_params_list=name,description,scope,type,is_secured
+cli.schema.result_params_mandatory_list=name, description, type
+
+cli.schema.http_sections=request,success_codes,result_map,sample_response
+cli.schema.http_mandatory_sections=equest, success_codes
+
+cli.schema.http_request_params=uri,method,body,headers,queries
+cli.schema.http_request_mandatory_params=uri,method
+
+cli.schema.http_methods=post,get,delete,put,head
+
+cli.schema.boolean_values=true,false
+cli.schema.auth_values=none,basic
+cli.schema.mode_values=direct,catalog
\ No newline at end of file
index 84a86e8..8a2756e 100644 (file)
@@ -21,4 +21,29 @@ cli.http.basic.common_headers.x-app-id=X-FromAppId
 cli.http.basic.common_headers.x-app-id.value=onap-cli
 
 #TODO mrkanag add support for aaf like defined above for basic
-#cli.service.auth=aaf
\ No newline at end of file
+#cli.service.auth=aaf
+
+#schema validation
+cli.schema.top_level_params_list=onap_cmd_schema_version,name,description,service,parameters,results,http
+cli.schema.top_level_mandatory_list=onap_cmd_schema_version
+
+cli.schema.service_params_list=name,version,auth,mode
+cli.schema.service_params_mandatory_list=name,version
+
+cli.schema.input_params_list=name,description,type,short_option,long_option, is_optional,default_value,is_secured
+cli.schema.input_params_mandatory_list=name,description,type
+
+cli.schema.result_params_list=name,description,scope,type,is_secured
+cli.schema.result_params_mandatory_list=name, description, type
+
+cli.schema.http_sections=request,success_codes,result_map,sample_response
+cli.schema.http_mandatory_sections=equest, success_codes
+
+cli.schema.http_request_params=uri,method,body,headers,queries
+cli.schema.http_request_mandatory_params=uri,method
+
+cli.schema.http_methods=post,get,delete,put,head
+
+cli.schema.boolean_values=true,false
+cli.schema.auth_values=none,basic
+cli.schema.mode_values=direct,catalog
\ No newline at end of file