diff options
Diffstat (limited to 'framework/src/main/java')
5 files changed, 77 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); } } } |