summaryrefslogtreecommitdiffstats
path: root/framework/src/main/java/org/onap
diff options
context:
space:
mode:
authorsubhash kumar singh <subhash.kumar.singh@huawei.com>2017-08-01 19:56:00 +0530
committerKanagaraj Manickam <kanagaraj.manickam@huawei.com>2017-08-10 05:33:38 +0000
commit2741f49b3b5e92c5c31f44133fd458c4f15b5479 (patch)
treee232e671e11d664787802144532407cae3e08d06 /framework/src/main/java/org/onap
parent4e2d92bc6c5ae4499f8a583f9b80a1a9172e0c17 (diff)
Populate default param based on no-auth
Based on no-auth customise the default parameter for onap-command. e.g. If "no-auth = true" then command should not add default parameter "onap-username, onap-password, msb-url and no-auth". Issue-Id: CLI-22 Change-Id: Ic9228feb1deb7e6f24eb9b9f0c8f15fd45364e94 Signed-off-by: subhash kumar singh <subhash.kumar.singh@huawei.com>
Diffstat (limited to 'framework/src/main/java/org/onap')
-rw-r--r--framework/src/main/java/org/onap/cli/fw/OnapCommand.java19
-rw-r--r--framework/src/main/java/org/onap/cli/fw/conf/Constants.java6
-rw-r--r--framework/src/main/java/org/onap/cli/fw/conf/OnapCommandConfg.java22
-rw-r--r--framework/src/main/java/org/onap/cli/fw/error/OnapCommandInvalidDefaultParameter.java2
-rw-r--r--framework/src/main/java/org/onap/cli/fw/utils/OnapCommandUtils.java62
5 files changed, 98 insertions, 13 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 6cee09de..13e67fc6 100644
--- a/framework/src/main/java/org/onap/cli/fw/OnapCommand.java
+++ b/framework/src/main/java/org/onap/cli/fw/OnapCommand.java
@@ -29,6 +29,7 @@ import org.onap.cli.fw.error.OnapCommandInvalidResultAttributeScope;
import org.onap.cli.fw.error.OnapCommandInvalidSchema;
import org.onap.cli.fw.error.OnapCommandInvalidSchemaVersion;
import org.onap.cli.fw.error.OnapCommandNotInitialized;
+import org.onap.cli.fw.error.OnapCommandParameterMissing;
import org.onap.cli.fw.error.OnapCommandParameterNameConflict;
import org.onap.cli.fw.error.OnapCommandParameterOptionConflict;
import org.onap.cli.fw.error.OnapCommandRegistrationFailed;
@@ -42,6 +43,7 @@ import org.onap.cli.fw.utils.OnapCommandUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
+import java.util.Set;
/**
* Onap Command.
@@ -184,7 +186,22 @@ public abstract class OnapCommand {
*/
protected void validate() throws OnapCommandException {
for (OnapCommandParameter param : this.getParameters()) {
- param.validate();
+ try {
+ param.validate();
+ } catch (OnapCommandParameterMissing e) {
+ if (OnapCommandConfg.getExcludeParamsForNoAuthEnableExternalCmd().contains(param.getName())) {
+ OnapCommandParameter noAuthParam = this.getParameters().stream().filter(p -> p.getName()
+ .equalsIgnoreCase(Constants.DEFAULT_PARAMETER_OUTPUT_NO_AUTH)).findFirst().get();
+
+ if ("true".equalsIgnoreCase(noAuthParam.getValue().toString())) {
+ continue;
+ }
+ }
+ throw e;
+ } catch (OnapCommandException e) {
+ throw e;
+ }
+
}
}
diff --git a/framework/src/main/java/org/onap/cli/fw/conf/Constants.java b/framework/src/main/java/org/onap/cli/fw/conf/Constants.java
index 8886de55..5f95518c 100644
--- a/framework/src/main/java/org/onap/cli/fw/conf/Constants.java
+++ b/framework/src/main/java/org/onap/cli/fw/conf/Constants.java
@@ -106,6 +106,10 @@ public class Constants {
public static final String ONAP_CLI_VERSION = "cli.version";
public static final String HTTP_API_KEY_USE_COOKIES = "http.api_key_use_cookies";
public static final String HTTP_X_AUTH_TOKEN = "http.x_auth_token";
+ public static final String EXCLUDE_PARAMS_INTERNAL_CMD = "cli.exclude_params_internal_cmd";
+ public static final String NO_AUTH_DISABLE_INCLUDE_PARAMS_EXTERNAL_CMD = "cli.no_auth_disable_include_params_external_cmd";
+ public static final String NO_AUTH_ENABLE_EXCLUDE_PARAMS_EXTERNAL_CMD = "cli.no_auth_enable_exclude_params_external_cmd";
+ public static final String NO_AUTH_ENABLE_INCLUDE_PARAMS_EXTERNAL_CMD = "cli.no_auth_enable_include_params_external_cmd";
// Used while printing the column name during PORTRAIT mode print
public static final String PORTRAINT_COLUMN_NAME_PROPERTY = "property";
@@ -148,7 +152,7 @@ public class Constants {
public static final String DEFAULT_SCHEMA_FILE_NAME = "default_input_parameters.yaml";
// Error message
- public static final String SCHEMA_INVALID_DEFAULT_PARAMS_SECTION = "Invalid default parameter section";
+ public static final String SCHEMA_INVALID_DEFAULT_PARAMS_SECTION = "Invalid default_parameter section";
public static final String SCHEMA_FILE_EMPTY = "The schema file cann't be null or empty";
public static final String SCHEMA_FILE_WRONG_EXTN = "Schema file should be '.yaml' extension";
public static final String SCHEMA_FILE_NOT_EXIST = "Schema file doesn't exist";
diff --git a/framework/src/main/java/org/onap/cli/fw/conf/OnapCommandConfg.java b/framework/src/main/java/org/onap/cli/fw/conf/OnapCommandConfg.java
index bcfd6dfb..c2682cae 100644
--- a/framework/src/main/java/org/onap/cli/fw/conf/OnapCommandConfg.java
+++ b/framework/src/main/java/org/onap/cli/fw/conf/OnapCommandConfg.java
@@ -17,7 +17,10 @@
package org.onap.cli.fw.conf;
import java.io.IOException;
+import java.util.Arrays;
import java.util.Properties;
+import java.util.Set;
+import java.util.stream.Collectors;
/**
* Onap command constants.
@@ -88,4 +91,23 @@ public final class OnapCommandConfg {
return prps.getProperty(Constants.AUTH_SERVICE);
}
+ public static Set<String> getExcludeParamsForInternalCmd() {
+ return Arrays.stream(prps.getProperty(Constants.EXCLUDE_PARAMS_INTERNAL_CMD)
+ .split(",")).map(String::trim).collect(Collectors.toSet());
+ }
+
+ public static Set<String> getIncludeParamsForNoAuthDisableExternalCmd() {
+ return Arrays.stream(prps.getProperty(Constants.NO_AUTH_DISABLE_INCLUDE_PARAMS_EXTERNAL_CMD)
+ .split(",")).map(String::trim).collect(Collectors.toSet());
+ }
+
+ public static Set<String> getExcludeParamsForNoAuthEnableExternalCmd() {
+ return Arrays.stream(prps.getProperty(Constants.NO_AUTH_ENABLE_EXCLUDE_PARAMS_EXTERNAL_CMD)
+ .split(",")).map(String::trim).collect(Collectors.toSet());
+ }
+
+ public static Set<String> getIncludeParamsForNoAuthEnableExternalCmd() {
+ return Arrays.stream(prps.getProperty(Constants.NO_AUTH_ENABLE_INCLUDE_PARAMS_EXTERNAL_CMD)
+ .split(",")).map(String::trim).collect(Collectors.toSet());
+ }
}
diff --git a/framework/src/main/java/org/onap/cli/fw/error/OnapCommandInvalidDefaultParameter.java b/framework/src/main/java/org/onap/cli/fw/error/OnapCommandInvalidDefaultParameter.java
index 4ebf04d3..7dc4374e 100644
--- a/framework/src/main/java/org/onap/cli/fw/error/OnapCommandInvalidDefaultParameter.java
+++ b/framework/src/main/java/org/onap/cli/fw/error/OnapCommandInvalidDefaultParameter.java
@@ -30,6 +30,6 @@ public class OnapCommandInvalidDefaultParameter extends OnapCommandException {
* @param invalidParamsList message
*/
public OnapCommandInvalidDefaultParameter(List<String> invalidParamsList) {
- super("0x0024", "Invalid default parameter: " + invalidParamsList.toString());
+ super("0x0024", "Invalid default_parameter: " + invalidParamsList.toString());
}
}
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 1ad588de..1a5aba0f 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
@@ -25,6 +25,7 @@ import org.onap.cli.fw.ad.OnapService;
import org.onap.cli.fw.cmd.OnapHttpCommand;
import org.onap.cli.fw.cmd.OnapSwaggerCommand;
import org.onap.cli.fw.conf.Constants;
+import org.onap.cli.fw.conf.OnapCommandConfg;
import org.onap.cli.fw.error.OnapCommandDiscoveryFailed;
import org.onap.cli.fw.error.OnapCommandException;
import org.onap.cli.fw.error.OnapCommandHelpFailed;
@@ -175,6 +176,42 @@ public class OnapCommandUtils {
}
}
+ private static void processNoAuth(Set<String> parameterSet, final OnapCommand cmd, final List<String> includeParams,
+ final List<String> excludeParams) throws OnapCommandInvalidDefaultParameter {
+ // processing for no-auth type
+ if (cmd.getService() != null) {
+ List<String> includeAuthParams = new ArrayList();
+ List<String> excludeAuthParams = new ArrayList<>();
+ boolean noAuth = cmd.getService().isNoAuth();
+
+ if (cmd.isCommandInternal()) {
+ excludeAuthParams.addAll(OnapCommandConfg.getExcludeParamsForInternalCmd());
+ } else {
+ if (noAuth) {
+ includeAuthParams.addAll(OnapCommandConfg.getIncludeParamsForNoAuthEnableExternalCmd());
+ excludeAuthParams.addAll(OnapCommandConfg.getExcludeParamsForNoAuthEnableExternalCmd());
+ } else {
+ includeAuthParams.addAll(OnapCommandConfg.getIncludeParamsForNoAuthDisableExternalCmd());
+ }
+ }
+
+ List<String> invalidExclude = excludeAuthParams.stream().filter(includeParams::contains)
+ .collect(Collectors.toList());
+
+ List<String> invalidInclude = includeAuthParams.stream().filter(excludeParams::contains)
+ .filter(p->!includeParams.contains(p)).collect(Collectors.toList());
+
+ if (!invalidExclude.isEmpty() || !invalidInclude.isEmpty()) {
+ throw new OnapCommandInvalidDefaultParameter(Stream.concat(invalidExclude.stream(), invalidInclude.stream())
+ .collect(Collectors.toList()));
+ }
+
+
+ parameterSet.addAll(includeAuthParams);
+ parameterSet.removeAll(excludeAuthParams);
+ }
+ }
+
private static void parseSchema(OnapCommand cmd,
final Map<String, ?> values,
final List<String> defaultParamNames) throws OnapCommandException {
@@ -222,6 +259,8 @@ public class OnapCommandUtils {
} else if (Constants.DEFAULT_PARAMETERS.equals(key)) {
Map<String, List<String>> defParameters = (Map) values.get(Constants.DEFAULT_PARAMETERS);
+ List<String> includeParams = new ArrayList<>();
+ List<String> excludeParams = new ArrayList<>();
if (values.containsKey(Constants.DEFAULT_PARAMETERS) && defParameters == null) {
// if default parameter section is available then it must have either include
@@ -229,22 +268,25 @@ public class OnapCommandUtils {
throw new OnapCommandInvalidSchema(Constants.SCHEMA_INVALID_DEFAULT_PARAMS_SECTION);
}
+
if (defParameters != null) {
// validate default parameters
- List<String> includeParams = defParameters.containsKey(Constants.DEFAULT_PARAMETERS_INCLUDE) ?
- defParameters.get(Constants.DEFAULT_PARAMETERS_INCLUDE) : new ArrayList<>();
+ if (defParameters.containsKey(Constants.DEFAULT_PARAMETERS_INCLUDE)) {
+ includeParams = defParameters.get(Constants.DEFAULT_PARAMETERS_INCLUDE);
+ }
List<String> invInclude = includeParams.stream()
.filter(p -> !defaultParamNames.contains(p))
.collect(Collectors.toList());
- List<String> excludeParams = defParameters.containsKey(Constants.DEFAULT_PARAMETERS_EXCLUDE) ?
- defParameters.get(Constants.DEFAULT_PARAMETERS_EXCLUDE) : new ArrayList<>();
+ if (defParameters.containsKey(Constants.DEFAULT_PARAMETERS_EXCLUDE)) {
+ excludeParams = defParameters.get(Constants.DEFAULT_PARAMETERS_EXCLUDE);
+ }
- List<String> invExclude = excludeParams.stream()
- .filter(p -> !defaultParamNames.contains(p))
+ List<String> invExclude = excludeParams.stream().filter(p -> !defaultParamNames.contains(p))
.collect(Collectors.toList());
+
if (!invExclude.isEmpty() || !invInclude.isEmpty()) {
throw new OnapCommandInvalidDefaultParameter(Stream.concat(invInclude.stream(), invExclude.stream())
.collect(Collectors.toList()));
@@ -253,14 +295,14 @@ public class OnapCommandUtils {
if (!includeParams.isEmpty()) {
filteredDefaultParams.addAll(includeParams);
} else if (!excludeParams.isEmpty()) {
- defaultParamNames.stream().filter(p -> !excludeParams.contains(p))
+ List<String> finalExcludeParams = excludeParams;
+ defaultParamNames.stream().filter(p -> !finalExcludeParams.contains(p))
.forEach(filteredDefaultParams::add);
}
} else {
filteredDefaultParams.addAll(defaultParamNames);
-
}
-
+ processNoAuth(filteredDefaultParams, cmd, includeParams, excludeParams);
} else if (Constants.PARAMETERS.equals(key)) {
List<Map<String, String>> parameters = (List) values.get(key);
@@ -570,7 +612,7 @@ public class OnapCommandUtils {
if (param.isDefaultValueAnEnv()) {
optSecondCol += defaultMsg + "read from environment variable " + param.getEnvVarNameFromDefaultValue()
+ ".";
- } else if (param.getDefaultValue() != null && !param.getDefaultValue().isEmpty()) {
+ } else if (param.getDefaultValue() != null && !((String)param.getDefaultValue()).isEmpty()) {
optSecondCol += defaultMsg + param.getDefaultValue() + ".";
}