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;
protected boolean isInitialzied = false;
+ protected CommandType type = CommandType.CMD;
+
public String getSchemaVersion() {
return Constants.OPEN_CLI_SCHEMA_VERSION_VALUE;
}
this.cmdSchemaName = schemaName;
}
+ public CommandType getType() {
+ return this.type;
+ }
+
+ public void setType(CommandType type) {
+ this.type = type;
+ }
+
/**
* Initialize this command from command schema.
*
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(
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;
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
* @return
*/
String schema() default "";
+
+ /**
+ * Command type
+ *
+ * @return
+ */
+ String type() default "cmd";
}
--- /dev/null
+/*
+ * 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);
+ }
+ }
+}
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";
--- /dev/null
+/*
+ * 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");
+
+ }
+
+}
package org.onap.cli.fw.utils;
+import org.onap.cli.fw.cmd.CommandType;
+
public class ExternalSchema {
private String schemaName;
private String cmdName;
private String cmdVersion;
private String version;
+ private String type = CommandType.CMD.name();
private String http = "false";
public String getSchemaName() {
return this.getHttp().equals("true");
}
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+
+
}
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;
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;
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;
}
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);
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");
}
#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
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());
+ }
}