diff options
author | 2018-03-23 08:52:18 +0000 | |
---|---|---|
committer | 2018-03-23 08:52:18 +0000 | |
commit | 5c094b10096c629804b9e266d05b74e90512ad8b (patch) | |
tree | a40773b5b64133725b52e0213cc0fb9fa8e9e282 /framework | |
parent | e42245a43617bea27d817d8a53151b284fb84cea (diff) | |
parent | 7247c4f691efcb104fea7287ac9df541125655ee (diff) |
Merge changes I748662f8,Ie8684832,I8fbe6c64
* changes:
Add validation for sample file schema
Ignore invalid schemas
Ignore null on console
Diffstat (limited to 'framework')
-rw-r--r-- | framework/src/main/java/org/onap/cli/fw/conf/OnapCommandConstants.java | 3 | ||||
-rw-r--r-- | framework/src/main/java/org/onap/cli/fw/utils/OnapCommandDiscoveryUtils.java | 21 |
2 files changed, 24 insertions, 0 deletions
diff --git a/framework/src/main/java/org/onap/cli/fw/conf/OnapCommandConstants.java b/framework/src/main/java/org/onap/cli/fw/conf/OnapCommandConstants.java index c2bfc1d5..6f1741e5 100644 --- a/framework/src/main/java/org/onap/cli/fw/conf/OnapCommandConstants.java +++ b/framework/src/main/java/org/onap/cli/fw/conf/OnapCommandConstants.java @@ -45,6 +45,7 @@ public class OnapCommandConstants { //schema public static final String OPEN_CLI_SCHEMA_VERSION = "open_cli_schema_version"; public static final String OPEN_CLI_SCHEMA_VERSION_VALUE_1_0 = "1.0"; + public static final String NAME = "name"; public static final String DESCRIPTION = "description"; @@ -148,6 +149,8 @@ public class OnapCommandConstants { public static final String SAMPLE_GEN_ENABLED = "cli.sample.gen.enable"; public static final String SAMPLE_GEN_TARGET_FOLDER = "cli.sample.gen.target"; + public static final String OPEN_CLI_SAMPLE_VERSION = "open_cli_sample_version"; + public static final String OPEN_CLI_SAMPLE_VERSION_VALUE_1_0 = "1.0"; public static final String VERIFY_SAMPLES_DIRECTORY = "open-cli-sample"; public static final String VERIFY_SAMPLES_FILE_PATTERN = VERIFY_SAMPLES_DIRECTORY + YAML_PATTERN; public static final String VERIFY_SAMPLES_MOCK_PATTERN = VERIFY_SAMPLES_DIRECTORY + JSON_PATTERN; diff --git a/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandDiscoveryUtils.java b/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandDiscoveryUtils.java index 2b3cf941..d0789d74 100644 --- a/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandDiscoveryUtils.java +++ b/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandDiscoveryUtils.java @@ -246,6 +246,11 @@ public class OnapCommandDiscoveryUtils { schema.setSchemaURI(resource.getURI().toString()); Object obj = resourceMap.get(OPEN_CLI_SCHEMA_VERSION); + if (obj == null) { + OnapCommandUtils.LOG.info("Invalid Schema yaml " + schema.getSchemaURI()); + continue; + } + schema.setVersion(obj.toString()); if (!schema.getVersion().equalsIgnoreCase(OnapCommandConstants.OPEN_CLI_SCHEMA_VERSION_VALUE_1_0)) { @@ -298,6 +303,22 @@ public class OnapCommandDiscoveryUtils { private static void updateSchemaInfoWithSample(Resource sampleResourse, List<OnapCommandSchemaInfo> schemaInfos) throws OnapCommandInvalidSchema, IOException { Map<String, ?> infoMap = loadSchema(sampleResourse); + + if (infoMap == null) { + return; + } + + Object sampleVersion = infoMap.get(OPEN_CLI_SAMPLE_VERSION); + if (sampleVersion == null) { + OnapCommandUtils.LOG.info("Invalid Sample yaml " + sampleResourse.getURI().toString()); + return; + } + + if (!sampleVersion.toString().equalsIgnoreCase(OnapCommandConstants.OPEN_CLI_SAMPLE_VERSION_VALUE_1_0)) { + OnapCommandUtils.LOG.info("Unsupported Sample version found " + sampleResourse.getURI().toString()); + return; + } + String cmdName = (String) infoMap.get(OnapCommandConstants.VERIFY_CMD_NAME); String version = (String) infoMap.get(OnapCommandConstants.VERIFY_CMD_VERSION); |