summaryrefslogtreecommitdiffstats
path: root/framework/src/main
diff options
context:
space:
mode:
authorKanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>2017-10-04 18:25:24 +0530
committerKanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>2017-11-20 12:22:36 +0530
commit864eafac295bb9cc4c0b4315aa7c262eb214ccc6 (patch)
tree287aa928fa718059199164f6a7019d23642b79ba /framework/src/main
parent3387ffb892b85a20ae44ec58a41e1f3f2cb084f0 (diff)
Remove default_parameter section and use is_includ
Issue-Id: CLI-66 Change-Id: I24a3bc4d133d4d69fd6522091f20f88edd6c2f19 Signed-off-by: Kanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>
Diffstat (limited to 'framework/src/main')
-rw-r--r--framework/src/main/java/org/onap/cli/fw/OnapCommand.java63
-rw-r--r--framework/src/main/java/org/onap/cli/fw/OnapCommandRegistrar.java14
-rw-r--r--framework/src/main/java/org/onap/cli/fw/ad/OnapAuthClient.java17
-rw-r--r--framework/src/main/java/org/onap/cli/fw/cmd/BasicAuthLoginCommand.java7
-rw-r--r--framework/src/main/java/org/onap/cli/fw/cmd/BasicAuthLogoutCommand.java5
-rw-r--r--framework/src/main/java/org/onap/cli/fw/cmd/CatalogCommand.java5
-rw-r--r--framework/src/main/java/org/onap/cli/fw/cmd/OnapHttpCommand.java53
-rw-r--r--framework/src/main/java/org/onap/cli/fw/cmd/OnapSchemaRefreshCommand.java6
-rw-r--r--framework/src/main/java/org/onap/cli/fw/cmd/OnapSchemaValidateCommand.java6
-rw-r--r--framework/src/main/java/org/onap/cli/fw/conf/Constants.java19
-rw-r--r--framework/src/main/java/org/onap/cli/fw/conf/OnapCommandConfg.java28
-rw-r--r--framework/src/main/java/org/onap/cli/fw/error/OnapCommandRegistrationProductInfoMissing.java (renamed from framework/src/main/java/org/onap/cli/fw/error/OnapCommandRegistrationVersionMissing.java)6
-rw-r--r--framework/src/main/java/org/onap/cli/fw/info/OnapCommandInfo.java2
-rw-r--r--framework/src/main/java/org/onap/cli/fw/input/OnapCommandParameter.java1
-rw-r--r--framework/src/main/java/org/onap/cli/fw/utils/OnapCommandUtils.java325
-rw-r--r--framework/src/main/resources/default_input_parameters.yaml28
-rw-r--r--framework/src/main/resources/default_input_parameters_http.yaml30
-rw-r--r--framework/src/main/resources/log4j.properties4
-rw-r--r--framework/src/main/resources/open-cli-schema/basic-login.yaml13
-rw-r--r--framework/src/main/resources/open-cli-schema/basic-logout.yaml13
-rw-r--r--framework/src/main/resources/open-cli-schema/catalog.yaml19
-rw-r--r--framework/src/main/resources/open-cli-schema/schema-refresh.yaml18
-rw-r--r--framework/src/main/resources/open-cli-schema/schema-validate.yaml19
-rw-r--r--framework/src/main/resources/open-cli.properties25
24 files changed, 274 insertions, 452 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 8ef8a3c5..69e45bd2 100644
--- a/framework/src/main/java/org/onap/cli/fw/OnapCommand.java
+++ b/framework/src/main/java/org/onap/cli/fw/OnapCommand.java
@@ -58,11 +58,7 @@ public abstract class OnapCommand {
private String cmdSchemaName;
- private OnapCommandInfo info;
-
- private String productVersion;
-
- private OnapService onapService = new OnapService();
+ private OnapCommandInfo info = new OnapCommandInfo();
private List<OnapCommandParameter> cmdParameters = new ArrayList<>();
@@ -70,8 +66,6 @@ public abstract class OnapCommand {
protected boolean isInitialzied = false;
- protected CommandType type = CommandType.CMD;
-
public String getSchemaVersion() {
return Constants.OPEN_CLI_SCHEMA_VERSION_VALUE;
}
@@ -106,23 +100,6 @@ public abstract class OnapCommand {
this.info = info;
}
- public boolean isCommandInternal() {
- return onapService.getName() != null
- && onapService.getName().equalsIgnoreCase(OnapCommandConfg.getInternalCmd())
- && this.type.equals(CommandType.CMD);
- }
-
- /*
- * Onap service, this command uses to execute it. , defined by derived command
- */
- public OnapService getService() {
- return this.onapService;
- }
-
- public void setService(OnapService service) {
- this.onapService = service;
- }
-
public void setParameters(List<OnapCommandParameter> parameters) {
this.cmdParameters = parameters;
}
@@ -160,14 +137,6 @@ public abstract class OnapCommand {
this.cmdSchemaName = schemaName;
}
- public CommandType getType() {
- return this.type;
- }
-
- public void setType(CommandType type) {
- this.type = type;
- }
-
/**
* Initialize this command from command schema.
*
@@ -208,23 +177,8 @@ public abstract class OnapCommand {
*/
protected void validate() throws OnapCommandException {
for (OnapCommandParameter param : this.getParameters()) {
- try {
- param.validate();
- } catch (OnapCommandParameterMissing e) {
- if (OnapCommandConfg.getExcludeParamsForNoAuthEnableExternalCmd().contains(param.getName())) {
- Optional<OnapCommandParameter> noAuthParamOpt = this.getParameters().stream().filter(p -> p.getName()
- .equalsIgnoreCase(Constants.DEFAULT_PARAMETER_OUTPUT_NO_AUTH)).findFirst();
-
- if (noAuthParamOpt.isPresent() && "true".equalsIgnoreCase(noAuthParamOpt.get().getValue().toString())) {
- continue;
- }
- }
- throw e;
- } catch (OnapCommandException e) {
- throw e;
- }
-
- }
+ param.validate();
+ }
}
/**
@@ -302,7 +256,7 @@ public abstract class OnapCommand {
* @return version
*/
public String printVersion() {
- return this.getService().toString();
+ return this.getInfo().getService();
}
/**
@@ -315,13 +269,6 @@ public abstract class OnapCommand {
public String printHelp() throws OnapCommandHelpFailed {
return OnapCommandUtils.help(this);
}
- // (mrkanag) Add toString for all command, parameter, result, etc objects in JSON format
-
- public void setVersion(String version) {
- this.productVersion = version;
- }
- public String getVersion() {
- return this.productVersion;
- }
+ // (mrkanag) Add toString for all command, parameter, result, etc objects in JSON format
}
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 37ed81a5..0f5c9058 100644
--- a/framework/src/main/java/org/onap/cli/fw/OnapCommandRegistrar.java
+++ b/framework/src/main/java/org/onap/cli/fw/OnapCommandRegistrar.java
@@ -34,7 +34,7 @@ import org.onap.cli.fw.error.OnapCommandInvalidRegistration;
import org.onap.cli.fw.error.OnapCommandNotFound;
import org.onap.cli.fw.error.OnapCommandProductVersionInvalid;
import org.onap.cli.fw.error.OnapCommandRegistrationFailed;
-import org.onap.cli.fw.error.OnapCommandRegistrationVersionMissing;
+import org.onap.cli.fw.error.OnapCommandRegistrationProductInfoMissing;
import org.onap.cli.fw.input.cache.OnapCommandParameterCache;
import org.onap.cli.fw.output.OnapCommandResult;
import org.onap.cli.fw.output.OnapCommandResultAttribute;
@@ -52,8 +52,6 @@ import org.onap.cli.fw.utils.OnapCommandUtils;
public class OnapCommandRegistrar {
private Map<String, Class<? extends OnapCommand>> registry = new HashMap<>();
- private Map<String, String> authCmds = new HashMap<>();
-
private Set<String> availableProductVersions = new HashSet<>();
private String enabledProductVersion = OnapCommandConfg.getEnabledProductVersion();
@@ -97,11 +95,11 @@ public class OnapCommandRegistrar {
* Command Class
* @throws OnapCommandInvalidRegistration
* Invalid registration exception
- * @throws OnapCommandRegistrationVersionMissing
+ * @throws OnapCommandRegistrationProductInfoMissing
*/
- public void register(String name, String version, Class<? extends OnapCommand> cmd) throws OnapCommandInvalidRegistration, OnapCommandRegistrationVersionMissing {
+ public void register(String name, String version, Class<? extends OnapCommand> cmd) throws OnapCommandInvalidRegistration, OnapCommandRegistrationProductInfoMissing {
if (version == null || version.isEmpty()) {
- throw new OnapCommandRegistrationVersionMissing(name);
+ throw new OnapCommandRegistrationProductInfoMissing(name);
}
this.registry.put(name + ":" + version, cmd);
@@ -224,7 +222,7 @@ public class OnapCommandRegistrar {
return cmd;
}
- private void autoDiscover() throws OnapCommandInvalidRegistration, OnapCommandRegistrationVersionMissing {
+ private void autoDiscover() throws OnapCommandInvalidRegistration, OnapCommandRegistrationProductInfoMissing {
List<Class<OnapCommand>> cmds = OnapCommandUtils.findOnapCommands();
for (Class<OnapCommand> cmd : cmds) {
@@ -264,7 +262,7 @@ public class OnapCommandRegistrar {
String errorNote = "";
String usageNote = "\n\nTo enable a product version, use one of following methods:"
- + "\n 1. set env variable CLI_PRODUCT_VERSION"
+ + "\n 1. set env variable OPEN_CLI_PRODUCT_VERSION"
+ "\n 2. set cli.product.version in open-cli.properties"
+ "\n 3. in interactive mode, use the directive 'use <product version>'\n";
diff --git a/framework/src/main/java/org/onap/cli/fw/ad/OnapAuthClient.java b/framework/src/main/java/org/onap/cli/fw/ad/OnapAuthClient.java
index 40db8841..362360a3 100644
--- a/framework/src/main/java/org/onap/cli/fw/ad/OnapAuthClient.java
+++ b/framework/src/main/java/org/onap/cli/fw/ad/OnapAuthClient.java
@@ -65,7 +65,6 @@ public class OnapAuthClient {
OnapCommand login = this.findAuthCommand("login");
OnapCommandUtils.copyParamsFrom(this.cmd, login);
- login.getParametersMap().get(Constants.DEAFULT_PARAMETER_HOST_URL).setValue(this.getServiceUrl(login));
login.execute();
//It is safely assumed that all outputs are considered as common http headers.
@@ -111,7 +110,7 @@ public class OnapAuthClient {
return this.getServiceUrl(this.cmd);
}
- private String getServiceUrl(OnapCommand cmd) throws OnapCommandException {
+ private String getServiceUrl(OnapHttpCommand cmd) throws OnapCommandException {
if (cmd.getService().isModeDirect()){
return cmd.getParametersMap().get(Constants.DEAFULT_PARAMETER_HOST_URL).getValue().toString();
} else { //Catalog mode
@@ -166,20 +165,12 @@ public class OnapAuthClient {
try {
//Find the auth command for the given service and version under current enabled product
auth = OnapCommandRegistrar.getRegistrar().get(
- this.cmd.getService().getName() + "-" +
- this.cmd.getService().getVersion() + "-" +
+ this.cmd.getInfo().getService() + "-" +
this.cmd.getService().getAuthType() + "-" + authAction);
} catch (OnapCommandNotFound e) {
- try {
- //Find the auth command for the given service under current enabled product
- auth = OnapCommandRegistrar.getRegistrar().get(
- this.cmd.getService().getName() + "-" +
+ //Find the auth command for current enabled product
+ auth = OnapCommandRegistrar.getRegistrar().get(
this.cmd.getService().getAuthType() + "-" + authAction);
- } catch (OnapCommandNotFound e1) {
- //Find the auth command for current enabled product
- auth = OnapCommandRegistrar.getRegistrar().get(
- this.cmd.getService().getAuthType() + "-" + authAction);
- }
}
return auth;
diff --git a/framework/src/main/java/org/onap/cli/fw/cmd/BasicAuthLoginCommand.java b/framework/src/main/java/org/onap/cli/fw/cmd/BasicAuthLoginCommand.java
index df1892fb..e4c89a7a 100644
--- a/framework/src/main/java/org/onap/cli/fw/cmd/BasicAuthLoginCommand.java
+++ b/framework/src/main/java/org/onap/cli/fw/cmd/BasicAuthLoginCommand.java
@@ -20,14 +20,13 @@ import java.util.Map;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.impl.auth.BasicScheme;
-import org.onap.cli.fw.OnapCommand;
import org.onap.cli.fw.OnapCommandSchema;
import org.onap.cli.fw.conf.Constants;
import org.onap.cli.fw.error.OnapCommandException;
import org.onap.cli.fw.input.OnapCommandParameter;
-@OnapCommandSchema(name = "basic-login", version = "cli-1.0", type = "auth", schema = "basic-login.yaml")
-public class BasicAuthLoginCommand extends OnapCommand {
+@OnapCommandSchema(name = "basic-login", version = "open-cli", type = "auth", schema = "basic-login.yaml")
+public class BasicAuthLoginCommand extends OnapHttpCommand {
@Override
protected void run() throws OnapCommandException {
@@ -36,7 +35,7 @@ public class BasicAuthLoginCommand extends OnapCommand {
Map<String, OnapCommandParameter> paramMap = getParametersMap();
OnapCommandParameter usernameParam = paramMap.get(Constants.DEAFULT_PARAMETER_USERNAME);
String username = usernameParam.getValue().toString();
- OnapCommandParameter usernamePassword = paramMap.get(Constants.DEAFULT_PARAMETER_PASS_WORD);
+ OnapCommandParameter usernamePassword = paramMap.get(Constants.DEAFULT_PARAMETER_PASSWORD);
String password = usernamePassword.getValue().toString();
//Execute the command to get token
diff --git a/framework/src/main/java/org/onap/cli/fw/cmd/BasicAuthLogoutCommand.java b/framework/src/main/java/org/onap/cli/fw/cmd/BasicAuthLogoutCommand.java
index a6d22944..085f93c8 100644
--- a/framework/src/main/java/org/onap/cli/fw/cmd/BasicAuthLogoutCommand.java
+++ b/framework/src/main/java/org/onap/cli/fw/cmd/BasicAuthLogoutCommand.java
@@ -16,12 +16,11 @@
package org.onap.cli.fw.cmd;
-import org.onap.cli.fw.OnapCommand;
import org.onap.cli.fw.OnapCommandSchema;
import org.onap.cli.fw.error.OnapCommandException;
-@OnapCommandSchema(name = "basic-logout", version = "cli-1.0", type = "auth", schema = "basic-logout.yaml")
-public class BasicAuthLogoutCommand extends OnapCommand {
+@OnapCommandSchema(name = "basic-logout", version = "open-cli", type = "auth", schema = "basic-logout.yaml")
+public class BasicAuthLogoutCommand extends OnapHttpCommand {
@Override
protected void run() throws OnapCommandException {
diff --git a/framework/src/main/java/org/onap/cli/fw/cmd/CatalogCommand.java b/framework/src/main/java/org/onap/cli/fw/cmd/CatalogCommand.java
index b17fbe3d..d377b78d 100644
--- a/framework/src/main/java/org/onap/cli/fw/cmd/CatalogCommand.java
+++ b/framework/src/main/java/org/onap/cli/fw/cmd/CatalogCommand.java
@@ -16,12 +16,11 @@
package org.onap.cli.fw.cmd;
-import org.onap.cli.fw.OnapCommand;
import org.onap.cli.fw.OnapCommandSchema;
import org.onap.cli.fw.error.OnapCommandException;
-@OnapCommandSchema(name = "catalog", version = "cli-1.0", type = "catalog", schema = "catalog.yaml")
-public class CatalogCommand extends OnapCommand {
+@OnapCommandSchema(name = "catalog", version = "open-cli", type = "catalog", schema = "catalog.yaml")
+public class CatalogCommand extends OnapHttpCommand {
@Override
protected void run() throws OnapCommandException {
diff --git a/framework/src/main/java/org/onap/cli/fw/cmd/OnapHttpCommand.java b/framework/src/main/java/org/onap/cli/fw/cmd/OnapHttpCommand.java
index b541181e..3edcee40 100644
--- a/framework/src/main/java/org/onap/cli/fw/cmd/OnapHttpCommand.java
+++ b/framework/src/main/java/org/onap/cli/fw/cmd/OnapHttpCommand.java
@@ -24,6 +24,7 @@ import java.util.Map;
import org.onap.cli.fw.OnapCommand;
import org.onap.cli.fw.ad.OnapAuthClient;
+import org.onap.cli.fw.ad.OnapService;
import org.onap.cli.fw.conf.Constants;
import org.onap.cli.fw.conf.OnapCommandConfg;
import org.onap.cli.fw.error.OnapCommandException;
@@ -31,6 +32,7 @@ import org.onap.cli.fw.error.OnapCommandExecutionFailed;
import org.onap.cli.fw.error.OnapCommandFailedMocoGenerate;
import org.onap.cli.fw.http.HttpInput;
import org.onap.cli.fw.http.HttpResult;
+import org.onap.cli.fw.input.OnapCommandParameter;
import org.onap.cli.fw.output.OnapCommandResultAttribute;
import org.onap.cli.fw.utils.OnapCommandUtils;
import org.onap.cli.http.mock.MockJsonGenerator;
@@ -51,6 +53,8 @@ public class OnapHttpCommand extends OnapCommand {
protected OnapAuthClient authClient;
+ private OnapService onapService = new OnapService();
+
public void setInput(HttpInput input) {
this.input = input;
}
@@ -80,24 +84,51 @@ public class OnapHttpCommand extends OnapCommand {
return resultMap;
}
+ /*
+ * Onap service, this command uses to execute it.
+ */
+ public OnapService getService() {
+ return this.onapService;
+ }
+
+ public void setService(OnapService service) {
+ this.onapService = service;
+ }
+
@Override
protected void initializeProfileSchema() throws OnapCommandException {
- OnapCommandUtils.loadHTTPSchemaSection(this, this.getSchemaName(), false);
+ OnapCommandUtils.loadHttpSchema(this, this.getSchemaName(), true, false);
+ }
+
+ @Override
+ protected void validate() throws OnapCommandException {
+ if (! this.isAuthRequired()) {
+ if (this.getParametersMap().containsKey(Constants.DEAFULT_PARAMETER_USERNAME)) {
+ this.getParametersMap().get(Constants.DEAFULT_PARAMETER_USERNAME).setOptional(true);
+ }
+ if (this.getParametersMap().containsKey(Constants.DEAFULT_PARAMETER_PASSWORD)) {
+ this.getParametersMap().get(Constants.DEAFULT_PARAMETER_PASSWORD).setOptional(true);
+ }
+ }
+
+ super.validate();
+ }
+
+ private boolean isAuthRequired() {
+ return !this.getService().isNoAuth()
+ && "false".equals(this.getParametersMap().get(Constants.DEFAULT_PARAMETER_NO_AUTH).getValue())
+ && this.getInfo().getCommandType().equals(CommandType.CMD);
}
@Override
protected void run() throws OnapCommandException {
try {
- // For auth type commands, login and logout logic is not required
- boolean isAuthRequired = !this.getService().isNoAuth()
- && "false".equals(this.getParametersMap().get(Constants.DEFAULT_PARAMETER_OUTPUT_NO_AUTH).getValue())
- && this.getType().equals(CommandType.CMD);
-
- if (!isCommandInternal()) {
- this.authClient = new OnapAuthClient(
- this,
- this.getResult().isDebug());
- }
+ // For auth/catalog type commands, login and logout logic is not required
+ boolean isAuthRequired = this.isAuthRequired();
+
+ this.authClient = new OnapAuthClient(
+ this,
+ this.getResult().isDebug());
if (isAuthRequired) {
this.authClient.login();
diff --git a/framework/src/main/java/org/onap/cli/fw/cmd/OnapSchemaRefreshCommand.java b/framework/src/main/java/org/onap/cli/fw/cmd/OnapSchemaRefreshCommand.java
index 823f0d77..a6e2e2b0 100644
--- a/framework/src/main/java/org/onap/cli/fw/cmd/OnapSchemaRefreshCommand.java
+++ b/framework/src/main/java/org/onap/cli/fw/cmd/OnapSchemaRefreshCommand.java
@@ -30,7 +30,7 @@ import java.util.List;
* Refresh external schema.
*
*/
-@OnapCommandSchema(name = "schema-refresh", version = "cli-1.0", schema = "schema-refresh.yaml")
+@OnapCommandSchema(name = "schema-refresh", version = "open-cli", schema = "schema-refresh.yaml")
public class OnapSchemaRefreshCommand extends OnapCommand {
@Override
@@ -59,11 +59,11 @@ public class OnapSchemaRefreshCommand extends OnapCommand {
attribute.setValues(slNumbers);
} else if ("command".equals(attribute.getName())) {
attribute.setValues(cmdNames);
- } else if ("product-version".equals(attribute.getName())) {
+ } else if ("product".equals(attribute.getName())) {
attribute.setValues(cmdVersions);
} else if ("schema".equals(attribute.getName())) {
attribute.setValues(cmdFiles);
- } else if ("version".equals(attribute.getName())) {
+ } else if ("ocs-version".equals(attribute.getName())) {
attribute.setValues(versions);
}
}
diff --git a/framework/src/main/java/org/onap/cli/fw/cmd/OnapSchemaValidateCommand.java b/framework/src/main/java/org/onap/cli/fw/cmd/OnapSchemaValidateCommand.java
index 4028cc94..3366cf65 100644
--- a/framework/src/main/java/org/onap/cli/fw/cmd/OnapSchemaValidateCommand.java
+++ b/framework/src/main/java/org/onap/cli/fw/cmd/OnapSchemaValidateCommand.java
@@ -29,7 +29,7 @@ import java.util.Map;
/**
* Validate schema command.
*/
-@OnapCommandSchema(name = "schema-validate", version = "cli-1.0", schema = "schema-validate.yaml")
+@OnapCommandSchema(name = "schema-validate", version = "open-cli", schema = "schema-validate.yaml")
public class OnapSchemaValidateCommand extends OnapCommand {
@Override
@@ -50,8 +50,8 @@ public class OnapSchemaValidateCommand extends OnapCommand {
}, location, true, true);
- error.addAll(OnapCommandUtils.loadHTTPSchemaSection(new OnapHttpCommand(),
- location, true));
+ error.addAll(OnapCommandUtils.loadHttpSchema(new OnapHttpCommand(),
+ location, true, true));
List<String> slNumber = new ArrayList<>();
for (int i = 1; i <= error.size(); i++) {
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 c379a879..7e580b4a 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
@@ -46,7 +46,8 @@ public class Constants {
public static final String SSLCONTEST_TLS = "TLSV1.2";
public static final String APPLICATION_JSON = "application/json";
- public static final String SERVICE_NAME = "cli.service_name";
+ public static final String OPEN_CLI_PRODUCT_NAME = "cli.product_name";
+
//http
public static final String URI = "uri";
@@ -86,9 +87,6 @@ public class Constants {
public static final String COMMAND_TYPE = "type";
public static final String SERVICE = "service";
public static final String PARAMETERS = "parameters";
- public static final String DEFAULT_PARAMETERS = "default_parameters";
- public static final String DEFAULT_PARAMETERS_INCLUDE = "include";
- public static final String DEFAULT_PARAMETERS_EXCLUDE = "exclude";
public static final String RESULTS = "results";
@@ -115,10 +113,11 @@ public class Constants {
public static final String ATTRIBUTES = "attributes";
public static final String DEFAULT_PARAMETER_FILE_NAME = "default_input_parameters.yaml";
+ public static final String DEFAULT_PARAMETER_HTTP_FILE_NAME = "default_input_parameters_http.yaml";
// Common parameters used across all commands.
public static final String DEAFULT_PARAMETER_USERNAME = "host-username";
- public static final String DEAFULT_PARAMETER_PASS_WORD = "host-password";
+ public static final String DEAFULT_PARAMETER_PASSWORD = "host-password";
public static final String DEAFULT_PARAMETER_HOST_URL = "host-url";
public static final String DEFAULT_PARAMETER_HELP = "help";
public static final String DEFAULT_PARAMETER_VERSION = "version";
@@ -126,19 +125,15 @@ public class Constants {
public static final String DEFAULT_PARAMETER_OUTPUT_FORMAT = "format";
public static final String DEFAULT_PARAMETER_OUTPUT_ATTR_LONG = "long";
public static final String DEFAULT_PARAMETER_OUTPUT_NO_TITLE = "no-title";
- public static final String DEFAULT_PARAMETER_OUTPUT_NO_AUTH = "no-auth";
+ public static final String DEFAULT_PARAMETER_NO_AUTH = "no-auth";
// Configuration properties
public static final String CONF = "open-cli.properties";
public static final String OPEN_IGNORE_AUTH = "cli.ignore_auth";
public static final String OPEN_CLI_VERSION = "cli.version";
- public static final String OPEN_CLI_PRODUCT_VERSION = "cli.product.version";
- public static final String OPEN_CLI_PRODUCT_VERSION_ENV_NAME = "CLI_PRODUCT_VERSION";
+ public static final String OPEN_OPEN_CLI_PRODUCT_VERSION_ENV_NAME = "OPEN_CLI_PRODUCT_VERSION";
public static final String HTTP_API_KEY_USE_COOKIES = "cli.http.api_key_use_cookies";
- 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";
+
public static final String SERVICE_AUTH = "cli.service.auth";
public static final String SERVICE_AUTH_BASIC_HTTP_HEADERS = "cli.http.basic.common_headers";
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 64e54335..8f45d883 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
@@ -80,9 +80,9 @@ public final class OnapCommandConfg {
}
public static String getEnabledProductVersion() {
- String version = System.getenv(Constants.OPEN_CLI_PRODUCT_VERSION_ENV_NAME);
+ String version = System.getenv(Constants.OPEN_OPEN_CLI_PRODUCT_VERSION_ENV_NAME);
if (version == null) {
- version = prps.getProperty(Constants.OPEN_CLI_PRODUCT_VERSION);
+ version = prps.getProperty(Constants.OPEN_CLI_PRODUCT_NAME);
}
return version;
}
@@ -100,8 +100,8 @@ public final class OnapCommandConfg {
return false;
}
- public static String getInternalCmd() {
- return prps.getProperty(Constants.SERVICE_NAME);
+ public static String getProductName() {
+ return prps.getProperty(Constants.OPEN_CLI_PRODUCT_NAME);
}
public static String getAuthType() {
@@ -138,26 +138,6 @@ public final class OnapCommandConfg {
return getHeaderValues(serviceHeader, paramMap);
}
- public static Set<String> getExcludeParamsForInternalCmd() {
- return Arrays.stream(prps.getProperty(Constants.EXCLUDE_PARAMS_INTERNAL_CMD) // NOSONAR
- .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) // NOSONAR
- .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) // NOSONAR
- .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) // NOSONAR
- .split(",")).map(String::trim).collect(Collectors.toSet());
- }
-
//mrkanag move this utils class
public static List<String> getSchemaAttrInfo(String key) {
return Arrays.stream(prps.getProperty(key).split(",")).map(String::trim).collect(Collectors.toList()); // NOSONAR
diff --git a/framework/src/main/java/org/onap/cli/fw/error/OnapCommandRegistrationVersionMissing.java b/framework/src/main/java/org/onap/cli/fw/error/OnapCommandRegistrationProductInfoMissing.java
index 6155d274..7584feca 100644
--- a/framework/src/main/java/org/onap/cli/fw/error/OnapCommandRegistrationVersionMissing.java
+++ b/framework/src/main/java/org/onap/cli/fw/error/OnapCommandRegistrationProductInfoMissing.java
@@ -20,11 +20,11 @@ package org.onap.cli.fw.error;
* Command Not registered in Onap Command Registrar as version missing.
*
*/
-public class OnapCommandRegistrationVersionMissing extends OnapCommandException {
+public class OnapCommandRegistrationProductInfoMissing extends OnapCommandException {
private static final long serialVersionUID = 5513297861129088463L;
- public OnapCommandRegistrationVersionMissing(String cmdName) {
- super("0x2003", "Command " + cmdName + " version is missing");
+ public OnapCommandRegistrationProductInfoMissing(String cmdName) {
+ super("0x2003", "Command " + cmdName + "'s product info is missing");
}
}
diff --git a/framework/src/main/java/org/onap/cli/fw/info/OnapCommandInfo.java b/framework/src/main/java/org/onap/cli/fw/info/OnapCommandInfo.java
index a747f681..b127ad35 100644
--- a/framework/src/main/java/org/onap/cli/fw/info/OnapCommandInfo.java
+++ b/framework/src/main/java/org/onap/cli/fw/info/OnapCommandInfo.java
@@ -29,7 +29,7 @@ public class OnapCommandInfo {
private String author;
- private CommandType type;
+ private CommandType type = CommandType.CMD;
public String getProduct() {
return product;
diff --git a/framework/src/main/java/org/onap/cli/fw/input/OnapCommandParameter.java b/framework/src/main/java/org/onap/cli/fw/input/OnapCommandParameter.java
index 2a91f8d9..09071f11 100644
--- a/framework/src/main/java/org/onap/cli/fw/input/OnapCommandParameter.java
+++ b/framework/src/main/java/org/onap/cli/fw/input/OnapCommandParameter.java
@@ -186,6 +186,7 @@ public class OnapCommandParameter {
* @throws OnapCommandInvalidParameterValue
* exception
*/
+ //mrkanag return value in the type format instead of string format
public Object getValue() {
if (value != null) {
return value;
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 29e00b0f..08ee8fed 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
@@ -23,17 +23,14 @@ import static org.onap.cli.fw.conf.Constants.AUTH_VALUES;
import static org.onap.cli.fw.conf.Constants.BODY;
import static org.onap.cli.fw.conf.Constants.BOOLEAN_VALUE;
import static org.onap.cli.fw.conf.Constants.CLIENT;
-import static org.onap.cli.fw.conf.Constants.COMMAND_TYPE;
import static org.onap.cli.fw.conf.Constants.COMMAND_TYPE_VALUES;
import static org.onap.cli.fw.conf.Constants.DATA_DIRECTORY;
import static org.onap.cli.fw.conf.Constants.DATA_DIRECTORY_JSON_PATTERN;
-import static org.onap.cli.fw.conf.Constants.DEAFULT_PARAMETER_HOST_URL;
-import static org.onap.cli.fw.conf.Constants.DEAFULT_PARAMETER_PASS_WORD;
+import static org.onap.cli.fw.conf.Constants.DEAFULT_PARAMETER_PASSWORD;
import static org.onap.cli.fw.conf.Constants.DEAFULT_PARAMETER_USERNAME;
-import static org.onap.cli.fw.conf.Constants.DEFAULT_PARAMETERS;
-import static org.onap.cli.fw.conf.Constants.DEFAULT_PARAMETERS_EXCLUDE;
-import static org.onap.cli.fw.conf.Constants.DEFAULT_PARAMETERS_INCLUDE;
import static org.onap.cli.fw.conf.Constants.DEFAULT_PARAMETER_FILE_NAME;
+import static org.onap.cli.fw.conf.Constants.DEFAULT_PARAMETER_HTTP_FILE_NAME;
+import static org.onap.cli.fw.conf.Constants.DEFAULT_PARAMETER_NO_AUTH;
import static org.onap.cli.fw.conf.Constants.DEFAULT_VALUE;
import static org.onap.cli.fw.conf.Constants.DESCRIPTION;
import static org.onap.cli.fw.conf.Constants.DIRECTION;
@@ -62,9 +59,9 @@ import static org.onap.cli.fw.conf.Constants.INFO_SERVICE;
import static org.onap.cli.fw.conf.Constants.INFO_TYPE;
import static org.onap.cli.fw.conf.Constants.INPUT_PARAMS_LIST;
import static org.onap.cli.fw.conf.Constants.INPUT_PARAMS_MANDATORY_LIST;
+import static org.onap.cli.fw.conf.Constants.IS_INCLUDE;
import static org.onap.cli.fw.conf.Constants.IS_OPTIONAL;
import static org.onap.cli.fw.conf.Constants.IS_SECURED;
-import static org.onap.cli.fw.conf.Constants.IS_INCLUDE;
import static org.onap.cli.fw.conf.Constants.LONG_OPTION;
import static org.onap.cli.fw.conf.Constants.METHOD;
import static org.onap.cli.fw.conf.Constants.METHOD_TYPE;
@@ -83,7 +80,6 @@ import static org.onap.cli.fw.conf.Constants.RESULT_PARAMS_MANDATORY_LIST;
import static org.onap.cli.fw.conf.Constants.SAMPLE_RESPONSE;
import static org.onap.cli.fw.conf.Constants.SCHEMA_FILE_NOT_EXIST;
import static org.onap.cli.fw.conf.Constants.SCHEMA_FILE_WRONG_EXTN;
-import static org.onap.cli.fw.conf.Constants.SCHEMA_INVALID_DEFAULT_PARAMS_SECTION;
import static org.onap.cli.fw.conf.Constants.SCOPE;
import static org.onap.cli.fw.conf.Constants.SERVICE;
import static org.onap.cli.fw.conf.Constants.SERVICE_PARAMS_LIST;
@@ -113,11 +109,8 @@ import java.util.ServiceLoader;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
-import java.util.stream.Stream;
import org.onap.cli.fw.OnapCommand;
-import org.onap.cli.fw.OnapCommandRegistrar;
-import org.onap.cli.fw.ad.OnapCredentials;
import org.onap.cli.fw.ad.OnapService;
import org.onap.cli.fw.cmd.CommandType;
import org.onap.cli.fw.cmd.OnapHttpCommand;
@@ -130,7 +123,6 @@ import org.onap.cli.fw.error.OnapCommandHelpFailed;
import org.onap.cli.fw.error.OnapCommandHttpHeaderNotFound;
import org.onap.cli.fw.error.OnapCommandHttpInvalidResponseBody;
import org.onap.cli.fw.error.OnapCommandHttpInvalidResultMap;
-import org.onap.cli.fw.error.OnapCommandInvalidDefaultParameter;
import org.onap.cli.fw.error.OnapCommandInvalidParameterType;
import org.onap.cli.fw.error.OnapCommandInvalidParameterValue;
import org.onap.cli.fw.error.OnapCommandInvalidPrintDirection;
@@ -265,9 +257,9 @@ public class OnapCommandUtils {
try {
Map<String, ?> defaultParameterMap = includeDefault ?
validateSchemaVersion(DEFAULT_PARAMETER_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> defParams = new ArrayList<>();
+ Map<String, List<Map<String, String>>> commandYamlMap =
+ (Map<String, List<Map<String, String>>>)validateSchemaVersion(schemaName, cmd.getSchemaVersion());
if (includeDefault) {
if (commandYamlMap.get(PARAMETERS) == null) {
@@ -275,11 +267,9 @@ public class OnapCommandUtils {
} else {
commandYamlMap.get(PARAMETERS).addAll((List<Map<String, String>>) defaultParameterMap.get(PARAMETERS));
}
- defParams = ((List<Map<String, String>>) defaultParameterMap.get(PARAMETERS)).stream()
- .map(p -> p.get(NAME)).collect(Collectors.toList());
}
- return parseSchema(cmd, commandYamlMap, defParams, validateSchema);
+ return parseSchema(cmd, commandYamlMap, validateSchema);
} catch (OnapCommandException e) {
throw e;
} catch (Exception e) {
@@ -287,39 +277,29 @@ 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());
+ 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());
+
+ if (includeDefault) {
+ if (commandYamlMap.get(PARAMETERS) == null) {
+ commandYamlMap.put(PARAMETERS, (List<Map<String, String>>) defaultParameterMap.get(PARAMETERS));
} else {
- includeAuthParams.addAll(OnapCommandConfg.getIncludeParamsForNoAuthDisableExternalCmd());
+ commandYamlMap.get(PARAMETERS).addAll((List<Map<String, String>>) defaultParameterMap.get(PARAMETERS));
}
- }
-
- List<String> invalidExclude = excludeAuthParams.stream().filter(includeParams::contains)
- .collect(Collectors.toList());
+ }
+ List<String> errors = parseSchema(cmd, commandYamlMap, validateSchema);
+ errors.addAll(parseHttpSchema(cmd, commandYamlMap, validateSchema));
+ return errors;
- 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);
+ } catch (OnapCommandException e) {
+ throw e;
+ } catch (Exception e) {
+ throw new OnapCommandInvalidSchema(schemaName, e);
}
}
@@ -365,13 +345,11 @@ public class OnapCommandUtils {
private static List<String> parseSchema(OnapCommand cmd,
final Map<String, ?> values,
- final List<String> defaultParamNames,
boolean validate) throws OnapCommandException {
List<String> exceptionList = new ArrayList<>();
List<String> shortOptions = new ArrayList<>();
List<String> longOptions = new ArrayList<>();
- Set<String> filteredDefaultParams = new HashSet<>();
if (validate) {
validateTags(exceptionList, (Map<String, Object>) values, OnapCommandConfg.getSchemaAttrInfo(TOP_LEVEL_PARAMS_LIST),
@@ -379,8 +357,7 @@ public class OnapCommandUtils {
}
- List<String> sections = Arrays.asList(NAME, DESCRIPTION, INFO, VERSION, COMMAND_TYPE, SERVICE,
- DEFAULT_PARAMETERS, PARAMETERS, RESULTS);
+ List<String> sections = Arrays.asList(NAME, DESCRIPTION, INFO, PARAMETERS, RESULTS);
for (String key : sections) {
@@ -392,13 +369,6 @@ public class OnapCommandUtils {
}
break;
- case VERSION:
- Object version = values.get(key);
- if (version != null) {
- cmd.setVersion(version.toString());
- }
- break;
-
case DESCRIPTION:
Object description = values.get(key);
if (description != null) {
@@ -406,14 +376,6 @@ public class OnapCommandUtils {
}
break;
-
- case COMMAND_TYPE:
- Object type = values.get(key);
- if (type != null) {
- cmd.setType(CommandType.get(type.toString()));
- }
- break;
-
case INFO:
Map<String, String> infoMap = (Map<String, String>) values.get(key);
@@ -472,131 +434,21 @@ public class OnapCommandUtils {
}
break;
- case SERVICE:
- Map<String, String> serviceMap = (Map<String, String>) values.get(key);
-
- if (serviceMap != null) {
- if (validate) {
- validateTags(exceptionList, (Map<String, Object>) values.get(key),
- OnapCommandConfg.getSchemaAttrInfo(SERVICE_PARAMS_LIST),
- OnapCommandConfg.getSchemaAttrInfo(SERVICE_PARAMS_MANDATORY_LIST), SERVICE);
-
- HashMap<String, String> validationMap = new HashMap<>();
- validationMap.put(AUTH, AUTH_VALUES);
- validationMap.put(MODE, MODE_VALUES);
-
- for (String secKey : validationMap.keySet()) {
- if (serviceMap.containsKey(secKey)) {
- Object obj = serviceMap.get(secKey);
- if (obj == null) {
- exceptionList.add("Attribute '" + secKey + "' under '" + SERVICE + "' is empty");
- } else {
- String value = String.valueOf(obj);
- if (!OnapCommandConfg.getSchemaAttrInfo(validationMap.get(secKey)).contains(value)) {
- exceptionList.add("Attribute '" + secKey + "' contains invalid value. Valide values are "
- + OnapCommandConfg.getSchemaAttrInfo(validationMap.get(key))); //
- }
- }
- }
- }
- }
-
- OnapService srv = new OnapService();
-
- for (Map.Entry<String, String> entry1 : serviceMap.entrySet()) {
- String key1 = entry1.getKey();
-
- switch (key1) {
- case NAME:
- srv.setName(serviceMap.get(key1));
- break;
-
- case VERSION:
- srv.setVersion(serviceMap.get(key1).toString());
- break;
-
- case AUTH:
- Object obj = serviceMap.get(key1);
- srv.setAuthType(obj.toString());
- break;
-
- case MODE:
- Object mode = serviceMap.get(key1);
- srv.setMode(mode.toString());
- break;
- }
- }
- cmd.setService(srv);
- }
- break;
-
- case DEFAULT_PARAMETERS:
- Map<String, List<String>> defParameters = (Map) values.get(DEFAULT_PARAMETERS);
- List<String> includeParams = new ArrayList<>();
- List<String> excludeParams = new ArrayList<>();
-
- if (values.containsKey(DEFAULT_PARAMETERS) && defParameters == null) {
- // if default parameter section is available then it must have either include
- // or exclude sub-section.
- throwOrCollect(new OnapCommandInvalidSchema(SCHEMA_INVALID_DEFAULT_PARAMS_SECTION),
- exceptionList, validate);
- }
-
-
- if (defParameters != null) {
- // validate default parameters
- if (defParameters.containsKey(DEFAULT_PARAMETERS_INCLUDE)) {
- includeParams = defParameters.get(DEFAULT_PARAMETERS_INCLUDE);
- }
-
- List<String> invInclude = includeParams.stream()
- .filter(p -> !defaultParamNames.contains(p))
- .collect(Collectors.toList());
-
- if (defParameters.containsKey(DEFAULT_PARAMETERS_EXCLUDE)) {
- excludeParams = defParameters.get(DEFAULT_PARAMETERS_EXCLUDE);
- }
-
- List<String> invExclude = excludeParams.stream().filter(p -> !defaultParamNames.contains(p))
- .collect(Collectors.toList());
-
-
- if (!invExclude.isEmpty() || !invInclude.isEmpty()) {
-
- throwOrCollect(new OnapCommandInvalidDefaultParameter(Stream.concat(invInclude.stream(),
- invExclude.stream()).collect(Collectors.toList())),
- exceptionList, validate);
- }
-
- if (!includeParams.isEmpty()) {
- filteredDefaultParams.addAll(includeParams);
- } else if (!excludeParams.isEmpty()) {
- List<String> finalExcludeParams = excludeParams;
- defaultParamNames.stream().filter(p -> !finalExcludeParams.contains(p))
- .forEach(filteredDefaultParams::add);
- }
- } else {
- filteredDefaultParams.addAll(defaultParamNames);
- }
- try {
- processNoAuth(filteredDefaultParams, cmd, includeParams, excludeParams);
- } catch (OnapCommandException e) {
- throwOrCollect(e, exceptionList, validate);
- }
- break;
-
case PARAMETERS:
List<Map<String, String>> parameters = (List) values.get(key);
if (parameters != null) {
Set<String> names = new HashSet<>();
- Set<String> inputShortOptions = new HashSet<>();
- Set<String> inputLongOptions = new HashSet<>();
for (Map<String, String> parameter : parameters) {
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 (validate) {
validateTags(exceptionList, parameter, OnapCommandConfg.getSchemaAttrInfo(INPUT_PARAMS_LIST),
OnapCommandConfg.getSchemaAttrInfo(INPUT_PARAMS_MANDATORY_LIST), PARAMETERS);
@@ -693,10 +545,7 @@ public class OnapCommandUtils {
}
}
- // Add the element to command :
- // 1. if parameter is available in filtered parameter list.
- // 2. otherwise, parameter p is available in command yaml file.
- if (filteredDefaultParams.contains(param.getName()) || !defaultParamNames.contains(param.getName())) {
+ if ( !cmd.getParametersMap().containsKey(param.getName()) ) {
cmd.getParameters().add(param);
}
}
@@ -983,11 +832,11 @@ public class OnapCommandUtils {
* @throws OnapCommandInvalidSchemaVersion
* invalid schema version
*/
- public static ArrayList<String> loadHTTPSchemaSection(OnapHttpCommand cmd, String schemaName,
- boolean validate) throws OnapCommandException {
+ private static ArrayList<String> parseHttpSchema(OnapHttpCommand cmd,
+ final Map<String, ?> values,
+ boolean validate) throws OnapCommandException {
ArrayList<String> errorList = new ArrayList<>();
try {
- Map<String, ?> values = (Map<String, ?>) validateSchemaVersion(schemaName, cmd.getSchemaVersion());
Map<String, ?> valMap = (Map<String, ?>) values.get(HTTP);
if (valMap != null) {
@@ -1035,11 +884,76 @@ public class OnapCommandUtils {
break;
}
}catch (Exception ex) {
- throwOrCollect(new OnapCommandInvalidSchema(schemaName, ex), errorList, validate);
+ throwOrCollect(new OnapCommandInvalidSchema(cmd.getSchemaName(), ex), errorList, validate);
}
}
break;
+ case SERVICE:
+ Map<String, String> serviceMap = (Map<String, String>) valMap.get(key1);
+
+ if (serviceMap != null) {
+ if (validate) {
+ validateTags(errorList, (Map<String, Object>) valMap.get(key1),
+ OnapCommandConfg.getSchemaAttrInfo(SERVICE_PARAMS_LIST),
+ OnapCommandConfg.getSchemaAttrInfo(SERVICE_PARAMS_MANDATORY_LIST), SERVICE);
+
+ HashMap<String, String> validationMap = new HashMap<>();
+ validationMap.put(AUTH, AUTH_VALUES);
+ validationMap.put(MODE, MODE_VALUES);
+
+ for (String secKey : validationMap.keySet()) {
+ if (serviceMap.containsKey(secKey)) {
+ Object obj = serviceMap.get(secKey);
+ if (obj == null) {
+ errorList.add("Attribute '" + secKey + "' under '" + SERVICE + "' is empty");
+ } else {
+ String value = String.valueOf(obj);
+ if (!OnapCommandConfg.getSchemaAttrInfo(validationMap.get(secKey)).contains(value)) {
+ errorList.add("Attribute '" + secKey + "' contains invalid value. Valide values are "
+ + OnapCommandConfg.getSchemaAttrInfo(validationMap.get(key1))); //
+ }
+ }
+ }
+ }
+ }
+
+ OnapService srv = new OnapService();
+
+ for (Map.Entry<String, String> entry : serviceMap.entrySet()) {
+ String key = entry.getKey();
+
+ switch (key) {
+ case NAME:
+ srv.setName(serviceMap.get(key));
+ break;
+
+ case VERSION:
+ srv.setVersion(serviceMap.get(key).toString());
+ break;
+
+ case AUTH:
+ Object obj = serviceMap.get(key);
+ srv.setAuthType(obj.toString());
+
+ //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);
+ }
+ break;
+
+ case MODE:
+ Object mode = serviceMap.get(key);
+ srv.setMode(mode.toString());
+ break;
+ }
+ }
+ cmd.setService(srv);
+ }
+ break;
+
case SUCCESS_CODES:
if (validate) {
validateHttpSccessCodes(errorList, (List<Object>) valMap.get(key1));
@@ -1157,13 +1071,14 @@ public class OnapCommandUtils {
* help failed exception
*/
public static String help(OnapCommand cmd) throws OnapCommandHelpFailed {
+ //mrkanag refactor onap name into oclip
String help = "usage: onap " + cmd.getName();
// Add description
help += "\n\n" + cmd.getDescription();
// Add service
- help += "\n\nOnap service: " + cmd.getService();
+ help += "\n\nService: " + cmd.getInfo().getService();
// Add whole command
String commandOptions = "";
@@ -1279,27 +1194,6 @@ public class OnapCommandUtils {
}
/**
- * Helps to create OnapCredentials from default params.
- *
- * @param params
- * list of parameters
- * @return OnapCredentials
- * @throws OnapCommandInvalidParameterValue
- * exception
- */
- public static OnapCredentials fromParameters(List<OnapCommandParameter> params)
- throws OnapCommandInvalidParameterValue {
- Map<String, String> paramMap = new HashMap<>();
-
- for (OnapCommandParameter param : params) {
- paramMap.put(param.getName(), param.getValue().toString());
- }
- return new OnapCredentials(paramMap.get(DEAFULT_PARAMETER_USERNAME),
- paramMap.get(DEAFULT_PARAMETER_PASS_WORD),
- paramMap.get(DEAFULT_PARAMETER_HOST_URL));
- }
-
- /**
* Create Dict from list of Parameters.
*
* @param inputs
@@ -1728,10 +1622,13 @@ public class OnapCommandUtils {
schema.setCmdName((String) resourceMap.get(NAME));
Object obj = resourceMap.get(OPEN_CLI_SCHEMA_VERSION);
schema.setVersion(obj.toString());
- schema.setCmdVersion(resourceMap.get(Constants.VERSION).toString());
- if (resourceMap.get(Constants.COMMAND_TYPE) != null) {
- schema.setType(resourceMap.get(Constants.COMMAND_TYPE).toString());
+ Map<String, ?> infoMap = (Map<String, ?>) resourceMap.get(Constants.INFO);
+ if (infoMap != null && infoMap.get(Constants.COMMAND_TYPE) != null) {
+ schema.setType(infoMap.get(Constants.COMMAND_TYPE).toString());
+ }
+ if (infoMap != null && infoMap.get(Constants.INFO_PRODUCT) != null) {
+ schema.setCmdVersion(infoMap.get(Constants.INFO_PRODUCT).toString());
}
if (resourceMap.get(Constants.HTTP) != null) {
@@ -1952,7 +1849,7 @@ public class OnapCommandUtils {
*
* @throws OnapCommandInvalidParameterValue
*/
- public static void copyParamsFrom(OnapCommand from, OnapCommand to) throws OnapCommandInvalidParameterValue {
+ public static void copyParamsFrom(OnapHttpCommand from, OnapCommand to) throws OnapCommandInvalidParameterValue {
for (OnapCommandParameter param: to.getParameters()) {
OnapCommandParameter fromParam = from.getParametersMap().get(param.getName());
diff --git a/framework/src/main/resources/default_input_parameters.yaml b/framework/src/main/resources/default_input_parameters.yaml
index 7f06e2bd..a8d35eee 100644
--- a/framework/src/main/resources/default_input_parameters.yaml
+++ b/framework/src/main/resources/default_input_parameters.yaml
@@ -1,27 +1,5 @@
open_cli_schema_version: 1.0
parameters:
- - name: host-username
- type: string
- description: Host user name
- short_option: u
- long_option: host-username
- default_value: $s{env:HOST_USERNAME}
- is_optional: false
- - name: host-password
- type: string
- description: Host user password
- short_option: p
- long_option: host-password
- default_value: $s{env:HOST_PASSWORD}
- is_secured: true
- is_optional: false
- - name: host-url
- type: url
- description: host url in http(s)
- short_option: m
- long_option: host-url
- is_optional: false
- default_value: $s{env:HOST_URL}
- name: help
type: string
description: print help message
@@ -57,10 +35,4 @@ parameters:
description: whether to print title or not
short_option: t
long_option: no-title
- default_value: false
- - name: no-auth
- type: bool
- description: whether to authenticate user or not
- short_option: a
- long_option: no-auth
default_value: false \ No newline at end of file
diff --git a/framework/src/main/resources/default_input_parameters_http.yaml b/framework/src/main/resources/default_input_parameters_http.yaml
new file mode 100644
index 00000000..529053d0
--- /dev/null
+++ b/framework/src/main/resources/default_input_parameters_http.yaml
@@ -0,0 +1,30 @@
+open_cli_schema_version: 1.0
+parameters:
+ - name: host-username
+ type: string
+ description: Host user name
+ short_option: u
+ long_option: host-username
+ default_value: $s{env:HOST_USERNAME}
+ is_optional: false
+ - name: host-password
+ type: string
+ description: Host user password
+ short_option: p
+ long_option: host-password
+ default_value: $s{env:HOST_PASSWORD}
+ is_secured: true
+ is_optional: false
+ - name: host-url
+ type: url
+ description: host url in http(s)
+ short_option: m
+ long_option: host-url
+ is_optional: false
+ default_value: $s{env:HOST_URL}
+ - name: no-auth
+ type: bool
+ description: whether to authenticate user or not
+ short_option: a
+ long_option: no-auth
+ default_value: false \ No newline at end of file
diff --git a/framework/src/main/resources/log4j.properties b/framework/src/main/resources/log4j.properties
index 1b352b5b..f117ef6e 100644
--- a/framework/src/main/resources/log4j.properties
+++ b/framework/src/main/resources/log4j.properties
@@ -2,8 +2,8 @@ log4j.rootLogger=ERROR, file
# Redirect log messages to a log file, support file rolling.
log4j.appender.file=org.apache.log4j.RollingFileAppender
-log4j.appender.file.File=${ONAP_CLI_HOME}/logs/onap-cli.log
+log4j.appender.file.File=${OPEN_CLI_HOME}/logs/oclip.log
log4j.appender.file.MaxFileSize=5MB
log4j.appender.file.MaxBackupIndex=10
log4j.appender.file.layout=org.apache.log4j.PatternLayout
-log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n \ No newline at end of file
+log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
diff --git a/framework/src/main/resources/open-cli-schema/basic-login.yaml b/framework/src/main/resources/open-cli-schema/basic-login.yaml
index a7f3b6ed..dab9652e 100644
--- a/framework/src/main/resources/open-cli-schema/basic-login.yaml
+++ b/framework/src/main/resources/open-cli-schema/basic-login.yaml
@@ -4,14 +4,11 @@ name: basic-login
description: basic login auth command
-version: cli-1.0
-
-type: auth
-
-service:
- name: open-cli
- version: 1.0.0
- mode: direct
+info:
+ product: open-cli
+ service: basic-auth
+ type: auth
+ author: Kanagaraj Manickam mkr1481@gmail.com
results:
direction: portrait
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 80255dd5..088fe7df 100644
--- a/framework/src/main/resources/open-cli-schema/basic-logout.yaml
+++ b/framework/src/main/resources/open-cli-schema/basic-logout.yaml
@@ -4,11 +4,8 @@ name: basic-logout
description: basic logout auth command
-version: cli-1.0
-
-type: auth
-
-service:
- name: open-cli
- version: 1.0.0
- mode: direct \ No newline at end of file
+info:
+ product: open-cli
+ service: basic-auth
+ type: auth
+ author: Kanagaraj Manickam mkr1481@gmail.com
diff --git a/framework/src/main/resources/open-cli-schema/catalog.yaml b/framework/src/main/resources/open-cli-schema/catalog.yaml
index 160ff1d4..4fafec4c 100644
--- a/framework/src/main/resources/open-cli-schema/catalog.yaml
+++ b/framework/src/main/resources/open-cli-schema/catalog.yaml
@@ -2,18 +2,14 @@ open_cli_schema_version: 1.0
name: catalog
-description: cli catalog command to find the base path for service.
+description: cli catalog command to find the base path for service.
-version: cli-1.0
+info:
+ product: open-cli
+ service: catalog
+ type: catalog
+ author: Kanagaraj Manickam mkr1481@gmail.com
-type: catalog
-
-service:
- auth: none
- name: open-cli
- version: 1.0.0
- mode: direct
-
parameters:
- name: catalog-service-name
type: string
@@ -27,6 +23,7 @@ parameters:
short_option: i
long_option: catalog-service-version
is_optional: false
+
results:
direction: portrait
attributes:
@@ -39,4 +36,4 @@ results:
description: service base path, to append with host-url for connecting the service.
scope: short
type: string
- default_value: / \ No newline at end of file
+ default_value: / \ No newline at end of file
diff --git a/framework/src/main/resources/open-cli-schema/schema-refresh.yaml b/framework/src/main/resources/open-cli-schema/schema-refresh.yaml
index 5f1cb50e..136bc1cd 100644
--- a/framework/src/main/resources/open-cli-schema/schema-refresh.yaml
+++ b/framework/src/main/resources/open-cli-schema/schema-refresh.yaml
@@ -1,11 +1,13 @@
open_cli_schema_version: 1.0
name: schema-refresh
-description: Onap command to refresh schemas stored in OPEN_cli_schema folders.
-version: cli-1.0
-service:
- auth: none
- name: open-cli
- version: 1.0.0
+description: Onap command to refresh schemas stored in open_cli_schema folders.
+
+info:
+ product: open-cli
+ service: schema
+ type: auth
+ author: Kanagaraj Manickam mkr1481@gmail.com
+
results:
direction: landscape
attributes:
@@ -17,7 +19,7 @@ results:
description: Command name
scope: short
type: string
- - name: product-version
+ - name: product
description: Command product version
scope: short
type: string
@@ -25,7 +27,7 @@ results:
description: Schema name
scope: short
type: string
- - name: version
+ - name: ocs-version
description: Schema version
scope: short
type: string \ No newline at end of file
diff --git a/framework/src/main/resources/open-cli-schema/schema-validate.yaml b/framework/src/main/resources/open-cli-schema/schema-validate.yaml
index 8c777666..e5b22bbf 100644
--- a/framework/src/main/resources/open-cli-schema/schema-validate.yaml
+++ b/framework/src/main/resources/open-cli-schema/schema-validate.yaml
@@ -1,17 +1,13 @@
open_cli_schema_version: 1.0
name: schema-validate
description: Onap command to validate schema
-version: cli-1.0
-service:
- auth: none
- name: open-cli
- version: 1.0.0
-default_parameters:
- exclude:
- - host-username
- - host-password
- - host-url
- - no-auth
+
+info:
+ product: open-cli
+ service: schema
+ type: auth
+ author: Kanagaraj Manickam mkr1481@gmail.com
+
parameters:
- name: schema-location
type: url
@@ -25,6 +21,7 @@ parameters:
short_option: i
long_option: internal-schema
is_optional: false
+
results:
direction: landscape
attributes:
diff --git a/framework/src/main/resources/open-cli.properties b/framework/src/main/resources/open-cli.properties
index 6ee08900..84a4736e 100644
--- a/framework/src/main/resources/open-cli.properties
+++ b/framework/src/main/resources/open-cli.properties
@@ -1,38 +1,31 @@
cli.ignore_auth=false
cli.http.api_key_use_cookies=true
cli.discover_always=false
-
-cli.service_name=open-cli
-cli.product.version=cli-1.0
+cli.product_name=open-cli
cli.version=1.0
-# service section
-cli.exclude_params_internal_cmd=host-username,host-password,host-url,no-auth
-cli.no_auth_disable_include_params_external_cmd=host-username,host-password,host-url,no-auth
-cli.no_auth_enable_exclude_params_external_cmd=host-username,host-password,no-auth
-cli.no_auth_enable_include_params_external_cmd=host-url
-
#schema validation
-cli.schema.top_level_params_list=open_cli_schema_version,name,version,description,service,parameters,results,http,type,info
+cli.schema.top_level_params_list=open_cli_schema_version,name,description,parameters,results,http,info
cli.schema.top_level_mandatory_list=open_cli_schema_version
-cli.schema.service_params_list=name,version,auth,mode
-cli.schema.service_params_mandatory_list=name,version
+cli.schema.info_params_list=product,service,type,author
+cli.schema.info_params_mandatory_list=product,service
-cli.schema.input_params_list=name,description,type,short_option,long_option, is_optional,default_value,is_secured
+cli.schema.input_params_list=name,description,type,short_option,long_option, is_optional,default_value,is_secured,is_include
cli.schema.input_params_mandatory_list=name,description,type
cli.schema.result_params_list=name,description,scope,type,is_secured, default_value
cli.schema.result_params_mandatory_list=name, description, type, scope
-cli.schema.http_sections=request,success_codes,result_map,sample_response
+#http
+cli.schema.http_sections=request,service,success_codes,result_map,sample_response
cli.schema.http_mandatory_sections=request, success_codes
cli.schema.http_request_params=uri,method,body,headers,queries,multipart_entity_name
cli.schema.http_request_mandatory_params=uri,method
-cli.schema.info_params_list=product,service,type,author
-cli.schema.info_params_mandatory_list=product,service
+cli.schema.service_params_list=name,version,auth,mode
+cli.schema.service_params_mandatory_list=auth,mode
cli.schema.http_methods=post,get,delete,put,head