return this.get(cmdName, this.getEnabledProductVersion());
}
- private OnapCommand get(String cmdName, String version) throws OnapCommandException {
+ /**
+ * Get the OnapCommand, which CLI main would use to find the command based on the command name.
+ *
+ * @param cmdName
+ * Name of command
+ * @param version
+ * product version
+ * @return OnapCommand
+ * @throws OnapCommandException
+ * Exception
+ */
+ public OnapCommand get(String cmdName, String version) throws OnapCommandException {
Class<? extends OnapCommand> cls = registry.get(cmdName + ":" + version);
//mrkanag: Restrict auth/catalog type commands only available during devMode. in production
//don't expose the auth type and catalog type commands
if (ano.schema() != null && !ano.schema().isEmpty()) {
map.put(ano.schema(), cmd);
} else if (ano.type() != null && !ano.type().isEmpty()) {
- this.registerProfilePlugin(ano.type(), cmd);
+ this.registerProfilePlugin(ano.type(), cmd);
map.put(ano.type(), cmd);
} else {
throw new OnapUnsupportedSchemaProfile(ano.schema());
import org.onap.cli.fw.http.HttpResult;
import org.onap.cli.fw.http.OnapHttpConnection;
import org.onap.cli.fw.output.OnapCommandResultAttribute;
+import org.onap.cli.fw.utils.OnapCommandDiscoveryUtils;
import org.onap.cli.fw.utils.OnapCommandUtils;
/**
return;
}
- OnapCommand login = this.findAuthCommand("login");
+ OnapCommand login = OnapCommandDiscoveryUtils.findAuthCommand(this.cmd, "login");
OnapCommandUtils.copyParamsFrom(this.cmd, login);
login.execute();
return;
}
- OnapCommand logout = this.findAuthCommand("logout");
+ OnapCommand logout = OnapCommandDiscoveryUtils.findAuthCommand(this.cmd, "logout");
OnapCommandUtils.copyParamsFrom(this.cmd, logout);
} else { //Catalog mode
OnapCommand catalog = OnapCommandRegistrar.getRegistrar().get("catalog");
- OnapCommandUtils.copyParamsFrom(cmd, catalog);
+ Map<String, String> paramsOverrides = new HashMap<>();
+ paramsOverrides.put(Constants.CATALOG_SERVICE_NAME, cmd.getService().getName());
+ paramsOverrides.put(Constants.CATALOG_SERVICE_VERSION, cmd.getService().getVersion());
+
+ OnapCommandUtils.copyParamsFrom(cmd, catalog, paramsOverrides);
catalog.execute();
public HttpResult run(HttpInput input) throws OnapCommandHttpFailure {
return this.http.request(input);
}
-
- /**
- *
- * @param authAction login/logout
- * @return
- * @throws OnapCommandException
- */
- private OnapCommand findAuthCommand(String authAction) throws OnapCommandException {
- OnapCommand auth = null;
- try {
- //Find the auth command for the given service and version under current enabled product
- auth = OnapCommandRegistrar.getRegistrar().get(
- this.cmd.getInfo().getService() + "-" +
- this.cmd.getService().getAuthType() + "-" + authAction);
- } catch (OnapCommandNotFound e) {
- //Find the auth command for current enabled product
- auth = OnapCommandRegistrar.getRegistrar().get(
- this.cmd.getService().getAuthType() + "-" + authAction);
- }
-
- return auth;
- }
}
import java.util.ServiceLoader;
import org.onap.cli.fw.OnapCommand;
+import org.onap.cli.fw.OnapCommandRegistrar;
+import org.onap.cli.fw.cmd.OnapHttpCommand;
import org.onap.cli.fw.conf.Constants;
import org.onap.cli.fw.conf.OnapCommandConfg;
import org.onap.cli.fw.error.OnapCommandDiscoveryFailed;
import org.onap.cli.fw.error.OnapCommandException;
import org.onap.cli.fw.error.OnapCommandInstantiationFailed;
import org.onap.cli.fw.error.OnapCommandInvalidSchema;
+import org.onap.cli.fw.error.OnapCommandNotFound;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternResolver;
}
}
+
+ /**
+ *
+ * @param authAction login/logout
+ * @return
+ * @throws OnapCommandException
+ */
+ public static OnapCommand findAuthCommand(OnapHttpCommand forCmd, String authAction) throws OnapCommandException {
+ OnapCommand auth = null;
+ try {
+ //mrkanag: fix this to discover the auth command by matching info->product & service
+ auth = OnapCommandRegistrar.getRegistrar().get(
+ forCmd.getInfo().getService() + "-" +
+ forCmd.getService().getAuthType() + "-" + authAction,
+ forCmd.getInfo().getProduct());
+ } catch (OnapCommandNotFound e) {
+ auth = OnapCommandRegistrar.getRegistrar().get(
+ forCmd.getService().getAuthType() + "-" + authAction,
+ forCmd.getInfo().getProduct());
+ }
+
+ return auth;
+ }
}
}catch (OnapCommandException e) {
OnapCommandUtils.throwOrCollect(e, errorList, validate);
}
+
+ //Handle the parameters for auth
+ if (!cmd.getService().isNoAuth()) {
+ OnapCommand login = OnapCommandDiscoveryUtils.findAuthCommand(cmd, "login");
+ OnapCommandUtils.copyParamSchemasFrom(login, cmd);
+ }
+
return errorList;
}
*
* @throws OnapCommandInvalidParameterValue
*/
- public static void copyParamsFrom(OnapHttpCommand from, OnapCommand to) throws OnapCommandInvalidParameterValue {
+ public static void copyParamsFrom(OnapCommand from, OnapCommand to, Map<String, String> paramOverride) throws OnapCommandInvalidParameterValue {
for (OnapCommandParameter param: to.getParameters()) {
OnapCommandParameter fromParam = from.getParametersMap().get(param.getName());
if (fromParam != null) {
param.setValue(fromParam.getValue());
param.setDefaultValue(fromParam.getDefaultValue());
- } else if (param.getName().equalsIgnoreCase(Constants.CATALOG_SERVICE_NAME)) { // for catalog cmd
- param.setValue(from.getService().getName());
- } else if (param.getName().equalsIgnoreCase(Constants.CATALOG_SERVICE_VERSION)) { // for catalog cmd
- param.setValue(from.getService().getVersion());
+ }
+
+ if (paramOverride.containsKey(param.getName())) {
+ param.setValue(paramOverride.get(param.getName()));
+ }
+ }
+ }
+
+ public static void copyParamsFrom(OnapCommand from, OnapCommand to) throws OnapCommandInvalidParameterValue {
+ OnapCommandUtils.copyParamsFrom(from, to, new HashMap<String, String>());
+ }
+
+ /**
+ * Copy param schema from source command to destination command, useful in adding login command params into command
+ * @param from
+ * @param to
+ * @throws OnapCommandException
+ */
+ public static void copyParamSchemasFrom(OnapCommand from, OnapCommand to) throws OnapCommandException {
+ for (OnapCommandParameter param: from.getParameters()) {
+ if (!to.getParametersMap().containsKey(param.getName())) {
+ to.getParameters().add(param);
}
}
}
package org.onap.cli.fw.ad;
+import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import org.junit.Before;
}
}
+ @Test
+ public void noCatalogYesAuthWithAdditionalParamsTest() throws OnapCommandException {
+ try {
+ OnapHttpCommand cmd = getCommand("sample-test-schema-yes-auth-with-additional-params-no-catalog.yaml");
+ assertTrue(cmd.getParametersMap().containsKey("string-param"));
+ } catch (OnapCommandException e) {
+ fail("External command Yes Auth No Catalog failed to run");
+ e.printStackTrace(System.out);
+ }
+ }
+
@Test
public void noCatalogNoAuthTest() throws OnapCommandException {
try {
--- /dev/null
+open_cli_schema_version: 1.0
+
+name: testauth-login
+
+description: basic login auth command
+
+info:
+ product: open-cli
+ service: test
+ type: auth
+ author: Kanagaraj Manickam mkr1481@gmail.com
+
+parameters:
+ - name: string-param
+ type: string
+ description: Oclip string param
+ long_option: string-param
+ short_option: c
+ is_optional: false
+ default_Value: test
+
+# followings are dummy simulator for http command
+http:
+ request:
+ uri: /
+ method: GET
+ success_codes:
+ - 200
--- /dev/null
+open_cli_schema_version: 1.0
+
+name: testauth-logout
+
+description: basic logout auth command
+
+info:
+ product: open-cli
+ service: test
+ type: auth
+ author: Kanagaraj Manickam mkr1481@gmail.com
+
+# followings are dummy simulator for http command
+http:
+ request:
+ uri: /
+ method: GET
+ success_codes:
+ - 200
\ No newline at end of file
--- /dev/null
+open_cli_schema_version: 1.0
+
+name: sample-cmd-yes-auth-no-catalog-extra-params
+
+description: sample
+
+
+info:
+ product: open-cli
+ service: test
+ type: cmd
+ author: Kanagaraj Manickam mkr1481@gmail.com
+
+http:
+
+ service:
+ name: sample
+ version: v1
+ auth: testauth
+ mode: catalog
+
+ request:
+ uri: /test
+ method: GET
+ success_codes:
+ - 200
+ result_map:
+ name: ${name}