diff options
author | Kanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com> | 2017-10-04 23:04:34 +0530 |
---|---|---|
committer | Kanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com> | 2017-11-20 12:24:22 +0530 |
commit | c521118e69aaa589d631f95f34dcf88e7a8bd1b6 (patch) | |
tree | 0fd1b0c92b95747bb30c6873c43ed63c707e42f6 /framework/src/main | |
parent | 863a720fec2abf3fec87cff154df390e29ee5187 (diff) |
Add overriding concept to Parameters
Issue-Id: CLI-66
Change-Id: I90b69da1b4235bfa12d4eaffd3f73538fd12a443
Signed-off-by: Kanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>
Diffstat (limited to 'framework/src/main')
6 files changed, 59 insertions, 99 deletions
diff --git a/framework/src/main/java/org/onap/cli/fw/OnapCommand.java b/framework/src/main/java/org/onap/cli/fw/OnapCommand.java index 69e45bd2..ec7e1338 100644 --- a/framework/src/main/java/org/onap/cli/fw/OnapCommand.java +++ b/framework/src/main/java/org/onap/cli/fw/OnapCommand.java @@ -177,7 +177,9 @@ public abstract class OnapCommand { */ protected void validate() throws OnapCommandException { for (OnapCommandParameter param : this.getParameters()) { - param.validate(); + if (param.isInclude()) { + param.validate(); + } } } diff --git a/framework/src/main/java/org/onap/cli/fw/OnapCommandRegistrar.java b/framework/src/main/java/org/onap/cli/fw/OnapCommandRegistrar.java index 0f5c9058..49919f43 100644 --- a/framework/src/main/java/org/onap/cli/fw/OnapCommandRegistrar.java +++ b/framework/src/main/java/org/onap/cli/fw/OnapCommandRegistrar.java @@ -199,7 +199,7 @@ public class OnapCommandRegistrar { //don't expose the auth type and catalog type commands if (cls == null) { - throw new OnapCommandNotFound(cmdName, version); + throw new OnapCommandNotFound(cmdName, version); } OnapCommand cmd; diff --git a/framework/src/main/java/org/onap/cli/fw/ad/OnapCredentials.java b/framework/src/main/java/org/onap/cli/fw/ad/OnapCredentials.java deleted file mode 100644 index 02cbef7b..00000000 --- a/framework/src/main/java/org/onap/cli/fw/ad/OnapCredentials.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * 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.ad; - -/** - * Onap Service credentials. - */ -//mrkanag deprecate it -public class OnapCredentials { - - /* - * Onap Service username. - */ - private String username; - - /* - * Onap Service password - */ - private String password; - - /* - * Onap Service host-url - */ - private String hostUrl; - - /** - * Onap credentials with username and password. - * - * @param username - * user name - * @param password - * password - * @param hostUrl - * host url - */ - public OnapCredentials(String username, String password, String hostUrl) { - super(); - this.username = username; - this.password = password; - this.hostUrl = hostUrl; - } - - public String getUsername() { - return username; - } - - public String getPassword() { - return password; - } - - public String getHostUrl() { - return hostUrl; - } -} diff --git a/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandUtils.java b/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandUtils.java index 08ee8fed..e056456a 100644 --- a/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandUtils.java +++ b/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandUtils.java @@ -255,21 +255,19 @@ public class OnapCommandUtils { public static List<String> loadSchema(OnapCommand cmd, String schemaName, boolean includeDefault, boolean validateSchema) throws OnapCommandException { try { - Map<String, ?> defaultParameterMap = includeDefault ? - validateSchemaVersion(DEFAULT_PARAMETER_FILE_NAME, cmd.getSchemaVersion()) : new HashMap<>(); + List<String> errors = new ArrayList<>(); + if (includeDefault) { + Map<String, ?> defaultParameterMap = includeDefault ? + validateSchemaVersion(DEFAULT_PARAMETER_FILE_NAME, cmd.getSchemaVersion()) : new HashMap<>(); + errors.addAll(parseSchema(cmd, defaultParameterMap, validateSchema)); + } Map<String, List<Map<String, String>>> commandYamlMap = (Map<String, List<Map<String, String>>>)validateSchemaVersion(schemaName, cmd.getSchemaVersion()); - if (includeDefault) { - if (commandYamlMap.get(PARAMETERS) == null) { - commandYamlMap.put(PARAMETERS, (List<Map<String, String>>) defaultParameterMap.get(PARAMETERS)); - } else { - commandYamlMap.get(PARAMETERS).addAll((List<Map<String, String>>) defaultParameterMap.get(PARAMETERS)); - } - } + errors.addAll(parseSchema(cmd, commandYamlMap, validateSchema)); - return parseSchema(cmd, commandYamlMap, validateSchema); + return errors; } catch (OnapCommandException e) { throw e; } catch (Exception e) { @@ -281,19 +279,18 @@ public class OnapCommandUtils { public static List<String> loadHttpSchema(OnapHttpCommand cmd, String schemaName, boolean includeDefault, boolean validateSchema) throws OnapCommandException { try { - Map<String, ?> defaultParameterMap = includeDefault ? - validateSchemaVersion(DEFAULT_PARAMETER_HTTP_FILE_NAME, cmd.getSchemaVersion()) : new HashMap<>(); - Map<String, List<Map<String, String>>> commandYamlMap = (Map<String, List<Map<String, String>>>)validateSchemaVersion(schemaName, cmd.getSchemaVersion()); - + List<String> errors = new ArrayList<>(); if (includeDefault) { - if (commandYamlMap.get(PARAMETERS) == null) { - commandYamlMap.put(PARAMETERS, (List<Map<String, String>>) defaultParameterMap.get(PARAMETERS)); - } else { - commandYamlMap.get(PARAMETERS).addAll((List<Map<String, String>>) defaultParameterMap.get(PARAMETERS)); - } - } - List<String> errors = parseSchema(cmd, commandYamlMap, validateSchema); + Map<String, ?> defaultParameterMap = includeDefault ? + validateSchemaVersion(DEFAULT_PARAMETER_HTTP_FILE_NAME, cmd.getSchemaVersion()) : new HashMap<>(); + errors.addAll(parseSchema(cmd, defaultParameterMap, validateSchema)); + } + + Map<String, List<Map<String, String>>> commandYamlMap = + (Map<String, List<Map<String, String>>>)validateSchemaVersion(schemaName, cmd.getSchemaVersion()); + errors.addAll(parseHttpSchema(cmd, commandYamlMap, validateSchema)); + return errors; } catch (OnapCommandException e) { @@ -315,6 +312,7 @@ public class OnapCommandUtils { private static void validateTags(List<String> schemaErrors, Map<String, ?> yamlMap, List<String> totalParams, List<String> mandatoryParams, String section) { + //mrkanag capture invalid entries as well for (String param : totalParams) { boolean isMandatory = mandatoryParams.contains(param); boolean isYamlContains = yamlMap.containsKey(param); @@ -441,12 +439,19 @@ public class OnapCommandUtils { if (parameters != null) { Set<String> names = new HashSet<>(); + //To support overriding of the parameters, if command is already + //having the same named parameters, means same parameter is + //Overridden from included template into current template + Set<String> existingParamNames = cmd.getParametersMap().keySet(); + for (Map<String, String> parameter : parameters) { + boolean isOverriding = false; OnapCommandParameter param = new OnapCommandParameter(); //Override the parameters from its base such as default parameters list - if (cmd.getParametersMap().containsKey(param.getName())) { - param = cmd.getParametersMap().get(param.getName()); + if (existingParamNames.contains(parameter.getOrDefault(NAME, ""))) { + param = cmd.getParametersMap().get(parameter.getOrDefault(NAME, "")); + isOverriding = true; } if (validate) { @@ -461,8 +466,10 @@ public class OnapCommandUtils { case NAME: if (names.contains(parameter.get(key2))) { throwOrCollect(new OnapCommandParameterNameConflict(parameter.get(key2)), exceptionList, validate); + } else { + names.add(parameter.get(key2)); } - names.add(parameter.get(key2)); + param.setName(parameter.get(key2)); break; @@ -545,8 +552,10 @@ public class OnapCommandUtils { } } - if ( !cmd.getParametersMap().containsKey(param.getName()) ) { + if ( !isOverriding) { cmd.getParameters().add(param); + } else { + cmd.getParametersMap().replace(param.getName(), param); } } } @@ -938,9 +947,9 @@ public class OnapCommandUtils { //On None type, username, password and no_auth are invalid if (srv.isNoAuth()) { - cmd.getParametersMap().remove(DEAFULT_PARAMETER_USERNAME); - cmd.getParametersMap().remove(DEAFULT_PARAMETER_PASSWORD); - cmd.getParametersMap().remove(DEFAULT_PARAMETER_NO_AUTH); + cmd.getParametersMap().get(DEAFULT_PARAMETER_USERNAME).setInclude(false); + cmd.getParametersMap().get(DEAFULT_PARAMETER_PASSWORD).setInclude(false); + cmd.getParametersMap().get(DEFAULT_PARAMETER_NO_AUTH).setInclude(false); } break; @@ -1104,6 +1113,10 @@ public class OnapCommandUtils { int newLineOptions = 0; for (OnapCommandParameter param : cmd.getParameters()) { + if (!param.isInclude()) { + continue; + } + // First column Option or positional args String optFirstCol; if (newLineOptions == 3) { diff --git a/framework/src/main/resources/open-cli-schema/basic-logout.yaml b/framework/src/main/resources/open-cli-schema/basic-logout.yaml index 088fe7df..ef60006c 100644 --- a/framework/src/main/resources/open-cli-schema/basic-logout.yaml +++ b/framework/src/main/resources/open-cli-schema/basic-logout.yaml @@ -9,3 +9,11 @@ info: service: basic-auth type: auth author: Kanagaraj Manickam mkr1481@gmail.com + +parameters: + - name: host-username + is_include: false + - name: host-password + is_include: false + - name: no-auth + is_include: false
\ No newline at end of file diff --git a/framework/src/main/resources/open-cli-schema/catalog.yaml b/framework/src/main/resources/open-cli-schema/catalog.yaml index 4fafec4c..d3ee9992 100644 --- a/framework/src/main/resources/open-cli-schema/catalog.yaml +++ b/framework/src/main/resources/open-cli-schema/catalog.yaml @@ -23,7 +23,12 @@ parameters: short_option: i long_option: catalog-service-version is_optional: false - + - name: host-username + is_include: false + - name: host-password + is_include: false + - name: no-auth + is_include: false results: direction: portrait attributes: |