aboutsummaryrefslogtreecommitdiffstats
path: root/framework
diff options
context:
space:
mode:
Diffstat (limited to 'framework')
-rw-r--r--framework/src/main/java/org/onap/cli/fw/OnapCommand.java16
-rw-r--r--framework/src/main/java/org/onap/cli/fw/OnapCommandRegistrar.java1
-rw-r--r--framework/src/main/java/org/onap/cli/fw/OnapCommandSchema.java9
-rw-r--r--framework/src/main/java/org/onap/cli/fw/cmd/CommandType.java52
-rw-r--r--framework/src/main/java/org/onap/cli/fw/conf/Constants.java1
-rw-r--r--framework/src/main/java/org/onap/cli/fw/error/OnapCommandInvalidCommandType.java32
-rw-r--r--framework/src/main/java/org/onap/cli/fw/utils/ExternalSchema.java13
-rw-r--r--framework/src/main/java/org/onap/cli/fw/utils/OnapCommandUtils.java16
-rw-r--r--framework/src/main/resources/onap.properties2
-rw-r--r--framework/src/test/java/org/onap/cli/fw/error/OnapCommandErrorTest.java7
10 files changed, 146 insertions, 3 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 61aa2cb2..9ca43fdf 100644
--- a/framework/src/main/java/org/onap/cli/fw/OnapCommand.java
+++ b/framework/src/main/java/org/onap/cli/fw/OnapCommand.java
@@ -24,6 +24,7 @@ import java.util.Optional;
import org.onap.cli.fw.ad.OnapAuthClient;
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.conf.Constants;
import org.onap.cli.fw.conf.OnapCommandConfg;
import org.onap.cli.fw.error.OnapCommandException;
@@ -69,6 +70,8 @@ public abstract class OnapCommand {
protected boolean isInitialzied = false;
+ protected CommandType type = CommandType.CMD;
+
public String getSchemaVersion() {
return Constants.OPEN_CLI_SCHEMA_VERSION_VALUE;
}
@@ -148,6 +151,14 @@ 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.
*
@@ -258,8 +269,11 @@ public abstract class OnapCommand {
try {
OnapCredentials creds = OnapCommandUtils.fromParameters(this.getParameters());
+
+ // For auth type commands, login and logout logic is not required
boolean isAuthRequired = !this.onapService.isNoAuth()
- && "false".equals(paramMap.get(Constants.DEFAULT_PARAMETER_OUTPUT_NO_AUTH).getValue());
+ && "false".equals(paramMap.get(Constants.DEFAULT_PARAMETER_OUTPUT_NO_AUTH).getValue())
+ && !this.getType().equals(CommandType.AUTH);
if (!isCommandInternal()) {
this.authClient = new OnapAuthClient(
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 28b2f9bf..987c3f01 100644
--- a/framework/src/main/java/org/onap/cli/fw/OnapCommandRegistrar.java
+++ b/framework/src/main/java/org/onap/cli/fw/OnapCommandRegistrar.java
@@ -24,6 +24,7 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
+import org.onap.cli.fw.cmd.CommandType;
import org.onap.cli.fw.cmd.OnapHttpCommand;
import org.onap.cli.fw.conf.Constants;
import org.onap.cli.fw.conf.OnapCommandConfg;
diff --git a/framework/src/main/java/org/onap/cli/fw/OnapCommandSchema.java b/framework/src/main/java/org/onap/cli/fw/OnapCommandSchema.java
index 471ab057..2e3e0a5c 100644
--- a/framework/src/main/java/org/onap/cli/fw/OnapCommandSchema.java
+++ b/framework/src/main/java/org/onap/cli/fw/OnapCommandSchema.java
@@ -20,6 +20,8 @@ import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
+import org.onap.cli.fw.cmd.CommandType;
+
/**
* Provide command name and schema file location, which is placed in the main resources folder (in classpath). It is
* recommended to keep the name for schema, in the form of onap-[command-name]-schema.yaml, considered this format as
@@ -52,4 +54,11 @@ public @interface OnapCommandSchema {
* @return
*/
String schema() default "";
+
+ /**
+ * Command type
+ *
+ * @return
+ */
+ String type() default "cmd";
}
diff --git a/framework/src/main/java/org/onap/cli/fw/cmd/CommandType.java b/framework/src/main/java/org/onap/cli/fw/cmd/CommandType.java
new file mode 100644
index 00000000..633a8f35
--- /dev/null
+++ b/framework/src/main/java/org/onap/cli/fw/cmd/CommandType.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.cli.fw.cmd;
+
+import org.onap.cli.fw.error.OnapCommandInvalidCommandType;
+import org.onap.cli.fw.error.OnapCommandInvalidParameterType;
+
+/**
+ * Command type supported by Onap CLI.
+ *
+ */
+public enum CommandType {
+
+ AUTH,
+ CATALOG,
+ CMD;
+
+ /**
+ * Get parameter type.
+ *
+ * @param name
+ * type name
+ * @return type
+ * @throws OnapCommandInvalidParameterType
+ * exception
+ */
+ public static CommandType get(String name) throws OnapCommandInvalidCommandType {
+ if (AUTH.name().equalsIgnoreCase(name)) {
+ return AUTH;
+ } else if (CATALOG.name().equalsIgnoreCase(name)) {
+ return CATALOG;
+ } else if (CMD.name().equalsIgnoreCase(name)) {
+ return CMD;
+ } else {
+ throw new OnapCommandInvalidCommandType(name);
+ }
+ }
+}
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 7dfc0d46..9fccc668 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
@@ -82,6 +82,7 @@ public class Constants {
public static final String OPEN_CLI_SCHEMA_VERSION_VALUE = "1.0";
public static final String DESCRIPTION = "description";
+ 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";
diff --git a/framework/src/main/java/org/onap/cli/fw/error/OnapCommandInvalidCommandType.java b/framework/src/main/java/org/onap/cli/fw/error/OnapCommandInvalidCommandType.java
new file mode 100644
index 00000000..bdc2ef2b
--- /dev/null
+++ b/framework/src/main/java/org/onap/cli/fw/error/OnapCommandInvalidCommandType.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.cli.fw.error;
+
+/**
+ * Command type is invalid.
+ *
+ */
+public class OnapCommandInvalidCommandType extends OnapCommandException {
+
+ private static final long serialVersionUID = 2821256032317061067L;
+
+ public OnapCommandInvalidCommandType(String cmd) {
+ super("0x3003", "Command type " + cmd + " is invalid");
+
+ }
+
+}
diff --git a/framework/src/main/java/org/onap/cli/fw/utils/ExternalSchema.java b/framework/src/main/java/org/onap/cli/fw/utils/ExternalSchema.java
index 12f217ce..16675c26 100644
--- a/framework/src/main/java/org/onap/cli/fw/utils/ExternalSchema.java
+++ b/framework/src/main/java/org/onap/cli/fw/utils/ExternalSchema.java
@@ -16,6 +16,8 @@
package org.onap.cli.fw.utils;
+import org.onap.cli.fw.cmd.CommandType;
+
public class ExternalSchema {
private String schemaName;
@@ -23,6 +25,7 @@ public class ExternalSchema {
private String cmdName;
private String cmdVersion;
private String version;
+ private String type = CommandType.CMD.name();
private String http = "false";
public String getSchemaName() {
@@ -77,4 +80,14 @@ public class ExternalSchema {
return this.getHttp().equals("true");
}
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+
+
}
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 77d50171..f891fd09 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,6 +23,7 @@ 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.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;
@@ -108,6 +109,7 @@ 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;
import org.onap.cli.fw.cmd.OnapSwaggerCommand;
import org.onap.cli.fw.conf.Constants;
@@ -138,7 +140,6 @@ import org.onap.cli.fw.http.HttpResult;
import org.onap.cli.fw.input.OnapCommandParameter;
import org.onap.cli.fw.input.ParameterType;
import org.onap.cli.fw.input.cache.Param;
-import org.onap.cli.fw.log.OnapCommandLogger;
import org.onap.cli.fw.output.OnapCommandResult;
import org.onap.cli.fw.output.OnapCommandResultAttribute;
import org.onap.cli.fw.output.OnapCommandResultAttributeScope;
@@ -394,6 +395,14 @@ public class OnapCommandUtils {
}
break;
+
+ case COMMAND_TYPE:
+ Object type = values.get(key);
+ if (type != null) {
+ cmd.setType(CommandType.get(type.toString()));
+ }
+ break;
+
case SERVICE:
Map<String, String> serviceMap = (Map<String, String>) values.get(key);
@@ -1537,6 +1546,11 @@ public class OnapCommandUtils {
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());
+ }
+
if (resourceMap.get(Constants.HTTP) != null) {
schema.setHttp("true");
}
diff --git a/framework/src/main/resources/onap.properties b/framework/src/main/resources/onap.properties
index 19182ae3..786f2d29 100644
--- a/framework/src/main/resources/onap.properties
+++ b/framework/src/main/resources/onap.properties
@@ -29,7 +29,7 @@ cli.http.basic.common_headers.sdc.user-id.value=${onap-username}
#cli.service.auth=aaf
#schema validation
-cli.schema.top_level_params_list=open_cli_schema_version,name,version,description,service,parameters,results,http
+cli.schema.top_level_params_list=open_cli_schema_version,name,version,description,service,parameters,results,http,type
cli.schema.top_level_mandatory_list=open_cli_schema_version
cli.schema.service_params_list=name,version,auth,mode
diff --git a/framework/src/test/java/org/onap/cli/fw/error/OnapCommandErrorTest.java b/framework/src/test/java/org/onap/cli/fw/error/OnapCommandErrorTest.java
index cc12cfc0..f50fe567 100644
--- a/framework/src/test/java/org/onap/cli/fw/error/OnapCommandErrorTest.java
+++ b/framework/src/test/java/org/onap/cli/fw/error/OnapCommandErrorTest.java
@@ -303,4 +303,11 @@ public class OnapCommandErrorTest {
assertEquals("0xc001::Failed to load profile details, error", failed.getMessage());
}
+
+ @Test
+ public void onapCommandTypeInvalidTest() {
+ OnapCommandInvalidCommandType failed = new OnapCommandInvalidCommandType("test");
+
+ assertEquals("0x3003::Command type test is invalid", failed.getMessage());
+ }
}