diff options
Diffstat (limited to 'framework/src')
53 files changed, 457 insertions, 586 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 diff --git a/framework/src/test/java/org/onap/cli/cmd/sample/OnapCommandSample.java b/framework/src/test/java/org/onap/cli/cmd/sample/OnapCommandSample.java index 16c92185..87527f07 100644 --- a/framework/src/test/java/org/onap/cli/cmd/sample/OnapCommandSample.java +++ b/framework/src/test/java/org/onap/cli/cmd/sample/OnapCommandSample.java @@ -25,7 +25,7 @@ import org.onap.cli.fw.error.OnapCommandExecutionFailed; * This command helps to test the Command functionalities. * */ -@OnapCommandSchema(name = "sample-test", version="cli-1.0", schema = "sample-test-schema.yaml") +@OnapCommandSchema(name = "sample-test", version="open-cli", schema = "sample-test-schema.yaml") public class OnapCommandSample extends OnapCommand { public OnapCommandSample() { diff --git a/framework/src/test/java/org/onap/cli/cmd/sample/OnapCommandSampleTest.java b/framework/src/test/java/org/onap/cli/cmd/sample/OnapCommandSampleTest.java index fc3e772d..51ed776f 100644 --- a/framework/src/test/java/org/onap/cli/cmd/sample/OnapCommandSampleTest.java +++ b/framework/src/test/java/org/onap/cli/cmd/sample/OnapCommandSampleTest.java @@ -37,10 +37,10 @@ import org.onap.cli.fw.output.OnapCommandResultAttribute; public class OnapCommandSampleTest { @Test public void sampleTestVersion() { - + try { - - OnapCommand sample = OnapCommandRegistrar.getRegistrar().get("sample-test"); + + OnapCommand sample = OnapCommandRegistrar.getRegistrar().get("sample-test"); List<OnapCommandParameter> parameters = new ArrayList(); OnapCommandParameter v = new OnapCommandParameter(); @@ -75,9 +75,9 @@ public class OnapCommandSampleTest { @Test public void sampleTest() { - + try { - OnapCommand sample = OnapCommandRegistrar.getRegistrar().get("sample-test"); + OnapCommand sample = OnapCommandRegistrar.getRegistrar().get("sample-test"); List<OnapCommandParameter> parameters = new ArrayList(); OnapCommandParameter v = new OnapCommandParameter(); v.setName(Constants.DEFAULT_PARAMETER_VERSION); @@ -100,7 +100,7 @@ public class OnapCommandSampleTest { t.setValue("true"); parameters.add(t); OnapCommandParameter a = new OnapCommandParameter(); - a.setName(Constants.DEFAULT_PARAMETER_OUTPUT_NO_AUTH); + a.setName(Constants.DEFAULT_PARAMETER_NO_AUTH); a.setValue("true"); parameters.add(a); OnapCommandParameter d = new OnapCommandParameter(); @@ -113,7 +113,7 @@ public class OnapCommandSampleTest { parameters.add(m); sample.setParameters(parameters); sample.execute(); - + //validate whether output attributes default value got initialized as part of execute() OnapCommandResultAttribute attr = sample.getResult().getRecordsMap().get("output-1"); String attrValue = attr.getValues().get(0); @@ -122,8 +122,8 @@ public class OnapCommandSampleTest { attrValue = attr.getValues().get(0); assertEquals(attrValue, "test"); } catch (IllegalArgumentException e){ - fail("Failed to replace the output default value on output-1"); - } catch (OnapCommandException e) { + fail("Failed to replace the output default value on output-1"); + } catch (OnapCommandException e) { } } @@ -154,7 +154,7 @@ public class OnapCommandSampleTest { t.setValue("true"); parameters.add(t); OnapCommandParameter a = new OnapCommandParameter(); - a.setName(Constants.DEFAULT_PARAMETER_OUTPUT_NO_AUTH); + a.setName(Constants.DEFAULT_PARAMETER_NO_AUTH); a.setValue("true"); parameters.add(a); OnapCommandParameter d = new OnapCommandParameter(); diff --git a/framework/src/test/java/org/onap/cli/fw/OnapCommandRegistrarTest.java b/framework/src/test/java/org/onap/cli/fw/OnapCommandRegistrarTest.java index d34f89c2..af9cc524 100644 --- a/framework/src/test/java/org/onap/cli/fw/OnapCommandRegistrarTest.java +++ b/framework/src/test/java/org/onap/cli/fw/OnapCommandRegistrarTest.java @@ -60,8 +60,8 @@ public class OnapCommandRegistrarTest { public void registerTest() throws OnapCommandException { OnapCommand test = new OnapCommandTest(); Class<OnapCommand> cmd = (Class<OnapCommand>) test.getClass(); - registerar.register("test", "cli-1.0", cmd); - OnapCommand cc = registerar.get("test"); + registerar.register("Test", "open-cli", cmd); + OnapCommand cc = registerar.get("Test"); assertTrue(cmd == cc.getClass()); } @@ -70,8 +70,8 @@ public class OnapCommandRegistrarTest { public void cmdTestSchema() throws OnapCommandException { OnapCommand test = new OnapCommandTest(); Class<OnapCommand> cmd = (Class<OnapCommand>) test.getClass(); - registerar.register("test", "cli-1.0", cmd); - OnapCommand cc = registerar.get("test"); + registerar.register("Test", "open-cli", cmd); + OnapCommand cc = registerar.get("Test"); } @Test @@ -90,7 +90,7 @@ public class OnapCommandRegistrarTest { @Test public void onapCommandRegistrationFailedTest() throws OnapCommandException { - @OnapCommandSchema(name = "Test2", version= "cli-1.0", schema = "sample-test-schema.yaml") + @OnapCommandSchema(name = "Test2", version= "open-cli", schema = "sample-test-schema.yaml") class Test extends OnapCommand { @Override @@ -103,7 +103,7 @@ public class OnapCommandRegistrarTest { OnapCommand com = new Test(); Class<OnapCommand> cmd = (Class<OnapCommand>) com.getClass(); try { - registerar.register("Test2", "cli-1.0", cmd); + registerar.register("Test2", "open-cli", cmd); registerar.get("Test2"); fail("This should have thrown an exception"); } catch (OnapCommandRegistrationFailed e) { @@ -116,7 +116,7 @@ public class OnapCommandRegistrarTest { OnapCommand test = new OnapCommandTest1(); Class<OnapCommand> cmd = (Class<OnapCommand>) test.getClass(); registerar = new OnapCommandRegistrar(); - registerar.register("test1", "cli-1.0", cmd); + registerar.register("test1", "open-cli", cmd); String help = registerar.getHelp(); assertNotNull(help); } @@ -149,8 +149,8 @@ public class OnapCommandRegistrarTest { OnapCommandRegistrar.getRegistrar().setInteractiveMode(false); assertTrue(!OnapCommandRegistrar.getRegistrar().isInteractiveMode()); - OnapCommandRegistrar.getRegistrar().setEnabledProductVersion("cli-1.0"); - assertEquals("cli-1.0", OnapCommandRegistrar.getRegistrar().getEnabledProductVersion()); + OnapCommandRegistrar.getRegistrar().setEnabledProductVersion("open-cli"); + assertEquals("open-cli", OnapCommandRegistrar.getRegistrar().getEnabledProductVersion()); OnapCommandRegistrar.getRegistrar().getAvailableProductVersions(); assertTrue(OnapCommandRegistrar.getRegistrar().listCommandsForEnabledProductVersion().contains("schema-refresh")); @@ -161,7 +161,7 @@ public class OnapCommandRegistrarTest { } } -@OnapCommandSchema(name = OnapCommandTest.CMD_NAME, version = "cli-1.0", schema = "sample-test-schema.yaml") +@OnapCommandSchema(name = OnapCommandTest.CMD_NAME, version = "open-cli", schema = "sample-test-schema.yaml") class OnapCommandTest extends OnapCommand { public OnapCommandTest() { @@ -176,7 +176,7 @@ class OnapCommandTest extends OnapCommand { } -@OnapCommandSchema(name = OnapCommandTest1.CMD_NAME, version = "cli-1.0", schema = "test-schema.yaml") +@OnapCommandSchema(name = OnapCommandTest1.CMD_NAME, version = "open-cli", schema = "test-schema.yaml") class OnapCommandTest1 extends OnapCommand { public OnapCommandTest1() { diff --git a/framework/src/test/java/org/onap/cli/fw/ad/OnapAuthClientCommandBasedTest.java b/framework/src/test/java/org/onap/cli/fw/ad/OnapAuthClientCommandBasedTest.java index e6054127..a2a25bc2 100644 --- a/framework/src/test/java/org/onap/cli/fw/ad/OnapAuthClientCommandBasedTest.java +++ b/framework/src/test/java/org/onap/cli/fw/ad/OnapAuthClientCommandBasedTest.java @@ -32,7 +32,7 @@ public class OnapAuthClientCommandBasedTest { public void internalCommandTest() { try { OnapCommand cmd = OnapCommandRegistrar.getRegistrar().get("sample-test"); - cmd.getService().setName(OnapCommandConfg.getInternalCmd()); + cmd.getInfo().setService(OnapCommandConfg.getProductName()); cmd.execute(); } catch (OnapCommandException e) { @@ -47,7 +47,7 @@ public class OnapAuthClientCommandBasedTest { OnapHttpCommand cmd = getCommand("sample-test-schema-yes-auth-yes-catalog.yaml"); cmd.getParametersMap().get(Constants.DEAFULT_PARAMETER_HOST_URL).setValue("http://localhost:8080"); cmd.getParametersMap().get(Constants.DEAFULT_PARAMETER_USERNAME).setValue("test"); - cmd.getParametersMap().get(Constants.DEAFULT_PARAMETER_PASS_WORD).setValue("password"); + cmd.getParametersMap().get(Constants.DEAFULT_PARAMETER_PASSWORD).setValue("password"); cmd.execute(); } catch (OnapCommandException e) { @@ -75,7 +75,7 @@ public class OnapAuthClientCommandBasedTest { OnapHttpCommand cmd = getCommand("sample-test-schema-yes-auth-no-catalog.yaml"); cmd.getParametersMap().get(Constants.DEAFULT_PARAMETER_HOST_URL).setValue("http://localhost:8080"); cmd.getParametersMap().get(Constants.DEAFULT_PARAMETER_USERNAME).setValue("test"); - cmd.getParametersMap().get(Constants.DEAFULT_PARAMETER_PASS_WORD).setValue("password"); + cmd.getParametersMap().get(Constants.DEAFULT_PARAMETER_PASSWORD).setValue("password"); cmd.execute(); } catch (OnapCommandException e) { diff --git a/framework/src/test/java/org/onap/cli/fw/cmd/OnapHttpCommandTest.java b/framework/src/test/java/org/onap/cli/fw/cmd/OnapHttpCommandTest.java index 7552cacb..3fced8ab 100644 --- a/framework/src/test/java/org/onap/cli/fw/cmd/OnapHttpCommandTest.java +++ b/framework/src/test/java/org/onap/cli/fw/cmd/OnapHttpCommandTest.java @@ -16,18 +16,20 @@ package org.onap.cli.fw.cmd; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +import org.junit.Ignore; import org.junit.Test; import org.onap.cli.fw.error.OnapCommandException; import org.onap.cli.fw.http.HttpInput; import org.onap.cli.fw.input.OnapCommandParameter; import org.onap.cli.fw.input.ParameterType; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; - public class OnapHttpCommandTest { + @Ignore @Test(expected = OnapCommandException.class) public void runTest() throws OnapCommandException { OnapCommandParameter param1 = new OnapCommandParameter(); diff --git a/framework/src/test/java/org/onap/cli/fw/cmd/OnapSchemaRefreshCommandTest.java b/framework/src/test/java/org/onap/cli/fw/cmd/OnapSchemaRefreshCommandTest.java index b0aa2119..8c96facd 100644 --- a/framework/src/test/java/org/onap/cli/fw/cmd/OnapSchemaRefreshCommandTest.java +++ b/framework/src/test/java/org/onap/cli/fw/cmd/OnapSchemaRefreshCommandTest.java @@ -45,7 +45,7 @@ public class OnapSchemaRefreshCommandTest { assertTrue(cmdName.equalsIgnoreCase("sample-test1")); assertTrue(cmdFile.equalsIgnoreCase("sample-test1-schema-http.yaml")); assertTrue(version.equalsIgnoreCase("1.0")); - assertTrue(cmdVer.equalsIgnoreCase("cli-1.0")); + assertTrue(cmdVer.equalsIgnoreCase("open-cli")); } } diff --git a/framework/src/test/java/org/onap/cli/fw/schema/ValidateSchemaTest.java b/framework/src/test/java/org/onap/cli/fw/schema/ValidateSchemaTest.java index d8745989..62a61d86 100644 --- a/framework/src/test/java/org/onap/cli/fw/schema/ValidateSchemaTest.java +++ b/framework/src/test/java/org/onap/cli/fw/schema/ValidateSchemaTest.java @@ -118,8 +118,8 @@ public class ValidateSchemaTest { List<String> errorList4 = OnapCommandUtils.loadSchema(cmd2, "schema-validate-invalid.yaml", true, true); OnapHttpCommand onapHttpCommand = new OnapHttpCommand(); - errorList4.addAll(OnapCommandUtils.loadHTTPSchemaSection(onapHttpCommand, - "schema-validate-invalid.yaml", true)); + errorList4.addAll(OnapCommandUtils.loadHttpSchema(onapHttpCommand, + "schema-validate-invalid.yaml", true, true)); assertTrue(errorList4.size() > 0); OnapCommand cmd5 = new OnapCommand() { diff --git a/framework/src/test/java/org/onap/cli/fw/utils/OnapCommandUtilsTest.java b/framework/src/test/java/org/onap/cli/fw/utils/OnapCommandUtilsTest.java index 096c6ff3..faf8394a 100644 --- a/framework/src/test/java/org/onap/cli/fw/utils/OnapCommandUtilsTest.java +++ b/framework/src/test/java/org/onap/cli/fw/utils/OnapCommandUtilsTest.java @@ -176,10 +176,8 @@ public class OnapCommandUtilsTest { com.setValue("value"); } - OnapCredentials cre = OnapCommandUtils.fromParameters(cmd.getParameters()); - assertTrue(cre != null); Map<String, OnapCommandParameter> map = OnapCommandUtils.getInputMap(cmd.getParameters()); - assertTrue(map.size() == 16); + assertTrue(map.size() == 15); } @Test @@ -189,7 +187,7 @@ public class OnapCommandUtilsTest { assertTrue("sample-test".equals(cmd.getName())); Map<String, OnapCommandParameter> map = OnapCommandUtils.getInputMap(cmd.getParameters()); - assertTrue(map.size() == 11); + assertTrue(map.size() == 7); } @Test @@ -219,7 +217,7 @@ public class OnapCommandUtilsTest { OnapHttpCommand cmd = new OnapHttpCommandSample(); cmd.setName("sample-test-http"); try { - OnapCommandUtils.loadHTTPSchemaSection(cmd, "sample-test-schema.yaml", false); + OnapCommandUtils.loadHttpSchema(cmd, "sample-test-schema.yaml", true, false); } catch (OnapCommandParameterNameConflict | OnapCommandParameterOptionConflict | OnapCommandInvalidParameterType | OnapCommandInvalidPrintDirection | OnapCommandInvalidResultAttributeScope | OnapCommandSchemaNotFound | OnapCommandInvalidSchema @@ -233,7 +231,7 @@ public class OnapCommandUtilsTest { OnapHttpCommand cmd = new OnapHttpCommandSample(); cmd.setName("sample-create-http"); try { - OnapCommandUtils.loadHTTPSchemaSection(cmd, "sample-test-schema-http.yaml", true); + OnapCommandUtils.loadHttpSchema(cmd, "sample-test-schema-http.yaml", true, true); assertTrue(cmd.getSuccessStatusCodes().size() == 2); } catch (OnapCommandParameterNameConflict | OnapCommandParameterOptionConflict | OnapCommandInvalidParameterType | OnapCommandInvalidPrintDirection @@ -251,6 +249,8 @@ public class OnapCommandUtilsTest { String actualResult = OnapCommandUtils.help(cmd); String expectedHelp = FileUtil.loadResource("sample-cmd-test-help.txt"); + + //mrkanag compare the result } @Test @@ -443,21 +443,21 @@ public class OnapCommandUtilsTest { assert info != null; } - @OnapCommandSchema(name = "sample-test-info", version = "cli-1.0", schema = "sample-test-info.yaml") + @OnapCommandSchema(name = "sample-test-info", version = "open-cli", schema = "sample-test-info.yaml") class OnapCommandSampleInfo extends OnapCommand { @Override protected void run() throws OnapCommandException { } } - @OnapCommandSchema(name = "sample-test", version = "cli-1.0", schema = "sample-test-schema.yaml") + @OnapCommandSchema(name = "sample-test", version = "open-cli", schema = "sample-test-schema.yaml") class OnapCommandSample extends OnapCommand { @Override protected void run() throws OnapCommandException { } } - @OnapCommandSchema(name = "sample-swagger-test", version = "cli-1.0", schema = "sample-test-schema-swagger.yaml") + @OnapCommandSchema(name = "sample-swagger-test", version = "open-cli", schema = "sample-test-schema-swagger.yaml") class OnapSwaggerBasedCommandSample extends OnapSwaggerCommand { @Override @@ -465,7 +465,7 @@ public class OnapCommandUtilsTest { } } - @OnapCommandSchema(name = "sample-http-test", version = "cli-1.0", schema = "sample-test-schema-http.yaml") + @OnapCommandSchema(name = "sample-http-test", version = "open-cli", schema = "sample-test-schema-http.yaml") class OnapHttpCommandSample extends OnapHttpCommand { @Override diff --git a/framework/src/test/resources/onap-test-schema.yaml b/framework/src/test/resources/onap-test-schema.yaml index 814a138c..9f1bf0e2 100644 --- a/framework/src/test/resources/onap-test-schema.yaml +++ b/framework/src/test/resources/onap-test-schema.yaml @@ -1,11 +1,13 @@ open_cli_schema_version: 1.0 name: sample-test description: Onap sample command to test the command features -verion: cli-1.0 -service: - name: sample - version: v1 - auth: none + +info: + product: open-cli + service: test + type: cmd + author: Kanagaraj Manickam mkr1481@gmail.com + parameters: - name: bool-param type: bool diff --git a/framework/src/test/resources/open-cli-schema/sample-test1-schema-http.yaml b/framework/src/test/resources/open-cli-schema/sample-test1-schema-http.yaml index 21f863b6..b96a498b 100644 --- a/framework/src/test/resources/open-cli-schema/sample-test1-schema-http.yaml +++ b/framework/src/test/resources/open-cli-schema/sample-test1-schema-http.yaml @@ -1,10 +1,13 @@ open_cli_schema_version: 1.0 name: sample-test1 description: Onap sample command to test the command features -version: cli-1.0 -service: - name: sample - version: v1 + +info: + product: open-cli + service: test + type: cmd + author: Kanagaraj Manickam mkr1481@gmail.com + parameters: - name: bool-param type: bool diff --git a/framework/src/test/resources/sample-cmd-test-help.txt b/framework/src/test/resources/sample-cmd-test-help.txt index 63b5decc..2523ce9b 100644 --- a/framework/src/test/resources/sample-cmd-test-help.txt +++ b/framework/src/test/resources/sample-cmd-test-help.txt @@ -5,7 +5,6 @@ Onap sample command to test the command features Onap service: sample v1 Options: -[-u | --host-username] [-p | --host-password] [-m | --host-url] [-h | --help] [-v | --version] [-d | --debug] [-f | --format] [-s | --long] [-t | --no-title] [-a | --no-auth] [-b | --bool] [-x | --secure] @@ -13,14 +12,6 @@ Options: [-l | --long-opt] [-r | --url] [-z | --env] <positional-args> where, --u | --host-username Onap user name. It is of type STRING. By - default, it is read from environment variable - HOST_USERNAME. --p | --host-password Onap user password. It is of type STRING. By - default, it is read from environment variable - HOST_PASSWORD. Secured. --m | --host-url Onap MSB url. It is of type URL. By default, it - is read from environment variable OPEN_MSB_URL. -h | --help Onap command help message. It is of type STRING. By default, it is false. -v | --version Onap command service version. It is of type @@ -35,8 +26,6 @@ where, false. -t | --no-title whether to print title or not. It is of type BOOL. By default, it is false. --a | --no-auth whether to authenticate user or not. It is of type - BOOL. By default, it is false. -b | --bool Onap boolean param, by default its always false. It is of type BOOL. It is optional. By default, it is false. diff --git a/framework/src/test/resources/sample-test-info.yaml b/framework/src/test/resources/sample-test-info.yaml index 35e59f8e..58e7268d 100644 --- a/framework/src/test/resources/sample-test-info.yaml +++ b/framework/src/test/resources/sample-test-info.yaml @@ -1,9 +1,9 @@ open_cli_schema_version: 1.0 name: sample-test-info description: Onap sample command to test the command features -version: cli-1.0 + info: - product: cli-1.0 - service: cli + product: open-cli + service: test type: cmd author: Kanagaraj Manickam mkr1481@gmail.com diff --git a/framework/src/test/resources/sample-test-invalid-schema-duplicate-longoption.yaml b/framework/src/test/resources/sample-test-invalid-schema-duplicate-longoption.yaml index 04ec6f2d..bf2ce3f3 100644 --- a/framework/src/test/resources/sample-test-invalid-schema-duplicate-longoption.yaml +++ b/framework/src/test/resources/sample-test-invalid-schema-duplicate-longoption.yaml @@ -1,10 +1,13 @@ open_cli_schema_version: 1.0 name: sample-test description: Onap sample command to test the command features -version: cli-1.0 -service: - name: sample - version: v1 + +info: + product: open-cli + service: test + type: cmd + author: Kanagaraj Manickam mkr1481@gmail.com + parameters: - name: bool-param type: bool diff --git a/framework/src/test/resources/sample-test-invalid-schema-duplicate-name.yaml b/framework/src/test/resources/sample-test-invalid-schema-duplicate-name.yaml index c94a2387..239c5360 100644 --- a/framework/src/test/resources/sample-test-invalid-schema-duplicate-name.yaml +++ b/framework/src/test/resources/sample-test-invalid-schema-duplicate-name.yaml @@ -1,10 +1,12 @@ open_cli_schema_version: 1.0 name: sample-test description: Onap sample command to test the command features -version: cli-1.0 -service: - name: sample - version: v1 +info: + product: open-cli + service: test + type: cmd + author: Kanagaraj Manickam mkr1481@gmail.com + parameters: - name: bool-param type: bool diff --git a/framework/src/test/resources/sample-test-invalid-schema-duplicate-shortoption.yaml b/framework/src/test/resources/sample-test-invalid-schema-duplicate-shortoption.yaml index d97e585a..4c6b27e4 100644 --- a/framework/src/test/resources/sample-test-invalid-schema-duplicate-shortoption.yaml +++ b/framework/src/test/resources/sample-test-invalid-schema-duplicate-shortoption.yaml @@ -1,10 +1,11 @@ open_cli_schema_version: 1.0 name: sample-test description: Onap sample command to test the command features -version: cli-1.0 -service: - name: sample - version: v1 +info: + product: open-cli + service: test + type: cmd + author: Kanagaraj Manickam mkr1481@gmail.com parameters: - name: bool-param type: bool diff --git a/framework/src/test/resources/sample-test-invalid-schema.yaml b/framework/src/test/resources/sample-test-invalid-schema.yaml index fbe87081..05da6ce7 100644 --- a/framework/src/test/resources/sample-test-invalid-schema.yaml +++ b/framework/src/test/resources/sample-test-invalid-schema.yaml @@ -1,10 +1,11 @@ open_cli_schema_version: 1.0 name: sample-test description: Onap sample command to test the command features -version: cli-1.0 -service: - name: sample - version: v1 +info: + product: open-cli + service: test + type: cmd + author: Kanagaraj Manickam mkr1481@gmail.com parameters: - name: bool-param type: bool diff --git a/framework/src/test/resources/sample-test-schema-auth-required.yaml b/framework/src/test/resources/sample-test-schema-auth-required.yaml index 6250e1f8..e7f5419a 100644 --- a/framework/src/test/resources/sample-test-schema-auth-required.yaml +++ b/framework/src/test/resources/sample-test-schema-auth-required.yaml @@ -1,10 +1,11 @@ open_cli_schema_version: 1.0 name: sample-test description: Onap sample command to test the command features -version: cli-1.0 -service: - name: sample - version: v1 +info: + product: open-cli + service: test + type: cmd + author: Kanagaraj Manickam mkr1481@gmail.com parameters: - name: bool-param type: bool diff --git a/framework/src/test/resources/sample-test-schema-http.yaml b/framework/src/test/resources/sample-test-schema-http.yaml index 9bfa2a53..60b45e80 100644 --- a/framework/src/test/resources/sample-test-schema-http.yaml +++ b/framework/src/test/resources/sample-test-schema-http.yaml @@ -1,10 +1,11 @@ open_cli_schema_version: 1.0 name: sample-create-http description: Register microservice into Onap -version: cli-1.0 -service: - name: msb - version: v1 +info: + product: open-cli + service: test + type: cmd + author: Kanagaraj Manickam mkr1481@gmail.com parameters: - name: service-name description: Onap service name diff --git a/framework/src/test/resources/sample-test-schema-no-auth-no-catalog.yaml b/framework/src/test/resources/sample-test-schema-no-auth-no-catalog.yaml index 295a2b80..e3e48c59 100644 --- a/framework/src/test/resources/sample-test-schema-no-auth-no-catalog.yaml +++ b/framework/src/test/resources/sample-test-schema-no-auth-no-catalog.yaml @@ -4,15 +4,19 @@ name: sample-cmd-no-auth-no-catalog description: sample -version: sample-test-1.0 - -service: - name: sample - version: v1 - auth: none - mode: direct +info: + product: open-cli + service: test + type: cmd + author: Kanagaraj Manickam mkr1481@gmail.com http: + + service: + name: sample + version: v1 + auth: none + mode: direct request: uri: /test method: GET diff --git a/framework/src/test/resources/sample-test-schema-no-auth-yes-catalog.yaml b/framework/src/test/resources/sample-test-schema-no-auth-yes-catalog.yaml index ebe03d86..0cdee7fe 100644 --- a/framework/src/test/resources/sample-test-schema-no-auth-yes-catalog.yaml +++ b/framework/src/test/resources/sample-test-schema-no-auth-yes-catalog.yaml @@ -4,15 +4,21 @@ name: sample-cmd-no-auth-no-catalog description: sample -version: sample-test-1.0 -service: - name: sample - version: v1 - auth: none - mode: catalog +info: + product: open-cli + service: test + type: cmd + author: Kanagaraj Manickam mkr1481@gmail.com http: + + service: + name: sample + version: v1 + auth: none + mode: catalog + request: uri: /test method: GET diff --git a/framework/src/test/resources/sample-test-schema-swagger.yaml b/framework/src/test/resources/sample-test-schema-swagger.yaml index 7f486c2f..0c52c71c 100644 --- a/framework/src/test/resources/sample-test-schema-swagger.yaml +++ b/framework/src/test/resources/sample-test-schema-swagger.yaml @@ -1,10 +1,11 @@ open_cli_schema_version: 1.0 name: sample-test-swagger description: Sample swagger command test. -version: cli-1.0 -service: - name: sample - version: v1 +info: + product: open-cli + service: test + type: cmd + author: Kanagaraj Manickam mkr1481@gmail.com parameters: - name: user type: string diff --git a/framework/src/test/resources/sample-test-schema-yes-auth-no-catalog.yaml b/framework/src/test/resources/sample-test-schema-yes-auth-no-catalog.yaml index fada6f52..0b418462 100644 --- a/framework/src/test/resources/sample-test-schema-yes-auth-no-catalog.yaml +++ b/framework/src/test/resources/sample-test-schema-yes-auth-no-catalog.yaml @@ -4,15 +4,19 @@ name: sample-cmd-yes-auth-no-catalog description: sample -version: sample-test-1.0 - -service: - name: sample - version: v1 - auth: basic - mode: direct +info: + product: open-cli + service: test + type: cmd + author: Kanagaraj Manickam mkr1481@gmail.com http: + + service: + name: sample + version: v1 + auth: basic + mode: direct request: uri: /test method: GET diff --git a/framework/src/test/resources/sample-test-schema-yes-auth-yes-catalog.yaml b/framework/src/test/resources/sample-test-schema-yes-auth-yes-catalog.yaml index e8b814a4..ca22e1d1 100644 --- a/framework/src/test/resources/sample-test-schema-yes-auth-yes-catalog.yaml +++ b/framework/src/test/resources/sample-test-schema-yes-auth-yes-catalog.yaml @@ -4,15 +4,21 @@ name: sample-cmd-no-auth-no-catalog description: sample -version: sample-test-1.0 -service: - name: sample - version: v1 - auth: basic - mode: catalog +info: + product: open-cli + service: test + type: cmd + author: Kanagaraj Manickam mkr1481@gmail.com http: + + service: + name: sample + version: v1 + auth: basic + mode: catalog + request: uri: /test method: GET diff --git a/framework/src/test/resources/sample-test-schema.yaml b/framework/src/test/resources/sample-test-schema.yaml index 37623dde..e3b415b1 100644 --- a/framework/src/test/resources/sample-test-schema.yaml +++ b/framework/src/test/resources/sample-test-schema.yaml @@ -1,11 +1,11 @@ open_cli_schema_version: 1.0 name: sample-test description: Onap sample command to test the command features -version: cli-1.0 -service: - name: sample - version: v1 - auth: none +info: + product: open-cli + service: test + type: cmd + author: Kanagaraj Manickam mkr1481@gmail.com parameters: - name: bool-param type: bool diff --git a/framework/src/test/resources/schema-validate-basic.yaml b/framework/src/test/resources/schema-validate-basic.yaml index 7cab57b5..a4219049 100644 --- a/framework/src/test/resources/schema-validate-basic.yaml +++ b/framework/src/test/resources/schema-validate-basic.yaml @@ -1,8 +1,11 @@ open_cli_schema_version: 1.0 description: Register microservice into Onap name: schema-validate -service: - name: msb +info: + product: open-cli + service: test + type: cmd + author: Kanagaraj Manickam mkr1481@gmail.com parameters: - name: service-name1 description: Onap service name diff --git a/framework/src/test/resources/schema-validate-http.yaml b/framework/src/test/resources/schema-validate-http.yaml index 2f56ec44..544de82b 100644 --- a/framework/src/test/resources/schema-validate-http.yaml +++ b/framework/src/test/resources/schema-validate-http.yaml @@ -1,8 +1,12 @@ open_cli_schema_version: 1.0 description: Register microservice into Onap name: schema-validate -service: - name: msb +info: + product: open-cli + service: test + type: cmd + author: Kanagaraj Manickam mkr1481@gmail.com + parameters: - name: service-name1 description: Onap service name @@ -67,6 +71,11 @@ results: scope: long type: url http: + service: + name: msb + version: v1 + type: direct + auth: none request: uri: /services method: POST1 diff --git a/framework/src/test/resources/schema-validate-invalid.yaml b/framework/src/test/resources/schema-validate-invalid.yaml index 6a1a2a71..11aaaca0 100644 --- a/framework/src/test/resources/schema-validate-invalid.yaml +++ b/framework/src/test/resources/schema-validate-invalid.yaml @@ -1,9 +1,11 @@ open_cli_schema_version: 1.0 name: sdnc-create description: Register SDNC into Onap -service: - name: extsys - version: v1 +info: + product: open-cli + service: test + type: cmd + author: Kanagaraj Manickam mkr1481@gmail.com parameters: - name: name description: Onap SDNC name diff --git a/framework/src/test/resources/schema-validate-invalidschematype.yaml b/framework/src/test/resources/schema-validate-invalidschematype.yaml index 17f4abe3..25e1cb5e 100644 --- a/framework/src/test/resources/schema-validate-invalidschematype.yaml +++ b/framework/src/test/resources/schema-validate-invalidschematype.yaml @@ -1,5 +1,11 @@ open_cli_schema_version: 1.0 description: Register microservice into Onap +info: + product: open-cli + service: test + type: cmd + author: Kanagaraj Manickam mkr1481@gmail.com + name: schema-validate parameters: - name: service-name1 diff --git a/framework/src/test/resources/schema-validate-pass.yaml b/framework/src/test/resources/schema-validate-pass.yaml index f5a258c9..73795206 100644 --- a/framework/src/test/resources/schema-validate-pass.yaml +++ b/framework/src/test/resources/schema-validate-pass.yaml @@ -1,9 +1,12 @@ open_cli_schema_version: 1.0 name: sdnc-create description: Register SDNC into Onap -service: - name: extsys - version: v1 +info: + product: open-cli + service: test + type: cmd + author: Kanagaraj Manickam mkr1481@gmail.com + parameters: - name: name description: Onap SDNC name |