summaryrefslogtreecommitdiffstats
path: root/framework
diff options
context:
space:
mode:
Diffstat (limited to 'framework')
-rw-r--r--framework/src/main/java/org/onap/cli/fw/OnapCommandRegistrar.java15
-rw-r--r--framework/src/main/java/org/onap/cli/fw/ad/OnapAuthClient.java33
-rw-r--r--framework/src/main/java/org/onap/cli/fw/utils/OnapCommandDiscoveryUtils.java26
-rw-r--r--framework/src/main/java/org/onap/cli/fw/utils/OnapCommandSchemaLoaderUtils.java7
-rw-r--r--framework/src/main/java/org/onap/cli/fw/utils/OnapCommandUtils.java28
-rw-r--r--framework/src/test/java/org/onap/cli/fw/ad/OnapAuthClientCommandBasedTest.java12
-rw-r--r--framework/src/test/resources/open-cli-schema/testauth-login.yaml28
-rw-r--r--framework/src/test/resources/open-cli-schema/testauth-logout.yaml19
-rw-r--r--framework/src/test/resources/sample-test-schema-yes-auth-with-additional-params-no-catalog.yaml28
9 files changed, 164 insertions, 32 deletions
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 9d1d9d07..d50ff464 100644
--- a/framework/src/main/java/org/onap/cli/fw/OnapCommandRegistrar.java
+++ b/framework/src/main/java/org/onap/cli/fw/OnapCommandRegistrar.java
@@ -207,7 +207,18 @@ public class OnapCommandRegistrar {
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
@@ -233,7 +244,7 @@ public class OnapCommandRegistrar {
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());
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 471b7eaf..6a324808 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
@@ -32,6 +32,7 @@ import org.onap.cli.fw.http.HttpInput;
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;
/**
@@ -62,7 +63,7 @@ public class OnapAuthClient {
return;
}
- OnapCommand login = this.findAuthCommand("login");
+ OnapCommand login = OnapCommandDiscoveryUtils.findAuthCommand(this.cmd, "login");
OnapCommandUtils.copyParamsFrom(this.cmd, login);
login.execute();
@@ -91,7 +92,7 @@ public class OnapAuthClient {
return;
}
- OnapCommand logout = this.findAuthCommand("logout");
+ OnapCommand logout = OnapCommandDiscoveryUtils.findAuthCommand(this.cmd, "logout");
OnapCommandUtils.copyParamsFrom(this.cmd, logout);
@@ -116,7 +117,11 @@ public class OnapAuthClient {
} 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();
@@ -153,26 +158,4 @@ public class OnapAuthClient {
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;
- }
}
diff --git a/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandDiscoveryUtils.java b/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandDiscoveryUtils.java
index 37220434..e1b3ea2b 100644
--- a/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandDiscoveryUtils.java
+++ b/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandDiscoveryUtils.java
@@ -35,12 +35,15 @@ import java.util.Map;
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;
@@ -319,4 +322,27 @@ public class OnapCommandDiscoveryUtils {
}
}
+
+ /**
+ *
+ * @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;
+ }
}
diff --git a/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandSchemaLoaderUtils.java b/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandSchemaLoaderUtils.java
index ba72abd5..04bfd23c 100644
--- a/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandSchemaLoaderUtils.java
+++ b/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandSchemaLoaderUtils.java
@@ -705,6 +705,13 @@ public class OnapCommandSchemaLoaderUtils {
}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;
}
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 0c5a75fb..57a2e303 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
@@ -705,7 +705,7 @@ public class OnapCommandUtils {
*
* @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());
@@ -713,10 +713,28 @@ public class OnapCommandUtils {
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);
}
}
}
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 9c733c94..58b44f4a 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
@@ -16,6 +16,7 @@
package org.onap.cli.fw.ad;
+import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import org.junit.Before;
@@ -92,6 +93,17 @@ public class OnapAuthClientCommandBasedTest {
}
@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 {
OnapHttpCommand cmd = getCommand("sample-test-schema-no-auth-no-catalog.yaml");
diff --git a/framework/src/test/resources/open-cli-schema/testauth-login.yaml b/framework/src/test/resources/open-cli-schema/testauth-login.yaml
new file mode 100644
index 00000000..8f3a8339
--- /dev/null
+++ b/framework/src/test/resources/open-cli-schema/testauth-login.yaml
@@ -0,0 +1,28 @@
+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
diff --git a/framework/src/test/resources/open-cli-schema/testauth-logout.yaml b/framework/src/test/resources/open-cli-schema/testauth-logout.yaml
new file mode 100644
index 00000000..d8de7c6f
--- /dev/null
+++ b/framework/src/test/resources/open-cli-schema/testauth-logout.yaml
@@ -0,0 +1,19 @@
+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
diff --git a/framework/src/test/resources/sample-test-schema-yes-auth-with-additional-params-no-catalog.yaml b/framework/src/test/resources/sample-test-schema-yes-auth-with-additional-params-no-catalog.yaml
new file mode 100644
index 00000000..4470e634
--- /dev/null
+++ b/framework/src/test/resources/sample-test-schema-yes-auth-with-additional-params-no-catalog.yaml
@@ -0,0 +1,28 @@
+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}