aboutsummaryrefslogtreecommitdiffstats
path: root/profiles
diff options
context:
space:
mode:
Diffstat (limited to 'profiles')
-rw-r--r--profiles/http/src/main/java/org/onap/cli/fw/http/auth/OnapCommandHttpAuthClient.java10
-rw-r--r--profiles/http/src/main/java/org/onap/cli/fw/http/cmd/OnapHttpCommand.java11
-rw-r--r--profiles/http/src/main/java/org/onap/cli/fw/http/conf/OnapCommandHttpConstants.java2
-rw-r--r--profiles/http/src/main/java/org/onap/cli/fw/http/schema/OnapCommandSchemaHttpLoader.java41
4 files changed, 47 insertions, 17 deletions
diff --git a/profiles/http/src/main/java/org/onap/cli/fw/http/auth/OnapCommandHttpAuthClient.java b/profiles/http/src/main/java/org/onap/cli/fw/http/auth/OnapCommandHttpAuthClient.java
index af02afdd..4b1752af 100644
--- a/profiles/http/src/main/java/org/onap/cli/fw/http/auth/OnapCommandHttpAuthClient.java
+++ b/profiles/http/src/main/java/org/onap/cli/fw/http/auth/OnapCommandHttpAuthClient.java
@@ -44,6 +44,8 @@ public class OnapCommandHttpAuthClient {
private OnapHttpConnection http = null;
+ private Map<String, String> loginCache = new HashMap<>();
+
public OnapCommandHttpAuthClient(OnapHttpCommand cmd, boolean debug) throws OnapCommandHttpFailure, OnapCommandInvalidParameterValue {
this.cmd = cmd;
this.http = new OnapHttpConnection(debug);
@@ -68,15 +70,14 @@ public class OnapCommandHttpAuthClient {
login.execute();
//It is safely assumed that all outputs are considered as common http headers.
- Map<String, String> headers = new HashMap<>();
for (OnapCommandResultAttribute attr: login.getResult().getRecords()) {
String headerValue = attr.getValues().get(0);
if (headerValue != null && !headerValue.isEmpty()) {
- headers.put(attr.getName(), attr.getValues().get(0));
+ this.loginCache.put(attr.getName(), attr.getValues().get(0));
}
}
- this.http.setCommonHeaders(headers);
+ this.http.setCommonHeaders(this.loginCache);
}
/**
@@ -93,7 +94,8 @@ public class OnapCommandHttpAuthClient {
OnapCommand logout = OnapCommandSchemaHttpLoader.findAuthCommand(this.cmd, "logout");
- OnapCommandUtils.copyParamsFrom(this.cmd, logout);
+ //for logout, share the login cache, which would be used for logout such a token
+ OnapCommandUtils.copyParamsFrom(this.cmd, logout, this.loginCache);
logout.execute();
diff --git a/profiles/http/src/main/java/org/onap/cli/fw/http/cmd/OnapHttpCommand.java b/profiles/http/src/main/java/org/onap/cli/fw/http/cmd/OnapHttpCommand.java
index 09ba7449..7178be81 100644
--- a/profiles/http/src/main/java/org/onap/cli/fw/http/cmd/OnapHttpCommand.java
+++ b/profiles/http/src/main/java/org/onap/cli/fw/http/cmd/OnapHttpCommand.java
@@ -21,6 +21,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
import org.onap.cli.fw.cmd.OnapCommand;
import org.onap.cli.fw.cmd.OnapCommandType;
@@ -122,7 +123,8 @@ public class OnapHttpCommand extends OnapCommand {
private boolean isAuthRequired() {
return !this.getService().isNoAuth()
&& "false".equals(this.getParametersMap().get(OnapCommandHttpConstants.DEFAULT_PARAMETER_NO_AUTH).getValue())
- && this.getInfo().getCommandType().equals(OnapCommandType.CMD);
+ && (this.getInfo().getCommandType().equals(OnapCommandType.CMD) ||
+ this.getInfo().getCommandType().equals(OnapCommandType.CATALOG));
}
@Override
@@ -168,6 +170,13 @@ public class OnapHttpCommand extends OnapCommand {
throw new OnapCommandExecutionFailed(this.getName(), output.getBody(), output.getStatus());
}
+ //pre-process result map for spl entries and input parameters
+ for (Entry<String, String> resultMap : this.getResultMap().entrySet()) {
+ String value = OnapCommandUtils.replaceLineForSpecialValues(resultMap.getValue());
+ value = OnapCommandUtils.replaceLineFromInputParameters(value, this.getParametersMap());
+ this.resultMap.put(resultMap.getKey(), value);
+ }
+
Map<String, ArrayList<String>> results = OnapCommandHttpUtils.populateOutputs(this.getResultMap(), output);
results = OnapCommandUtils.populateOutputsFromInputParameters(results, this.getParametersMap());
diff --git a/profiles/http/src/main/java/org/onap/cli/fw/http/conf/OnapCommandHttpConstants.java b/profiles/http/src/main/java/org/onap/cli/fw/http/conf/OnapCommandHttpConstants.java
index c33d2f27..7b421523 100644
--- a/profiles/http/src/main/java/org/onap/cli/fw/http/conf/OnapCommandHttpConstants.java
+++ b/profiles/http/src/main/java/org/onap/cli/fw/http/conf/OnapCommandHttpConstants.java
@@ -75,6 +75,8 @@ public class OnapCommandHttpConstants {
public static final String HTTP_SAMPLE_RESPONSE_FAILED_PARSING = "The http Sample response json is failed to parse.";
//auth plugin
public static final String AUTH_SERVICE_AUTHORIZATION = "Authorization";
+ public static final String AUTH_SERVICE_LOGIN = "login";
+
//catalog plugin
public static final String CATALOG_SERVICE_NAME = "catalog-service-name";
public static final String CATALOG_SERVICE_VERSION = "catalog-service-version";
diff --git a/profiles/http/src/main/java/org/onap/cli/fw/http/schema/OnapCommandSchemaHttpLoader.java b/profiles/http/src/main/java/org/onap/cli/fw/http/schema/OnapCommandSchemaHttpLoader.java
index a7424732..04d1c10a 100644
--- a/profiles/http/src/main/java/org/onap/cli/fw/http/schema/OnapCommandSchemaHttpLoader.java
+++ b/profiles/http/src/main/java/org/onap/cli/fw/http/schema/OnapCommandSchemaHttpLoader.java
@@ -27,6 +27,7 @@ import java.util.Set;
import java.util.stream.Collectors;
import org.onap.cli.fw.cmd.OnapCommand;
+import org.onap.cli.fw.cmd.OnapCommandType;
import org.onap.cli.fw.conf.OnapCommandConfig;
import org.onap.cli.fw.conf.OnapCommandConstants;
import org.onap.cli.fw.error.OnapCommandException;
@@ -189,23 +190,15 @@ public class OnapCommandSchemaHttpLoader {
case OnapCommandHttpConstants.AUTH:
Object obj = serviceMap.get(key);
srv.setAuthType(obj.toString());
-
- //On None type, username, password and no_auth are invalid
- if (srv.isNoAuth()) {
- cmd.getParametersMap().get(OnapCommandHttpConstants.DEAFULT_PARAMETER_USERNAME).setInclude(false);
- cmd.getParametersMap().get(OnapCommandHttpConstants.DEAFULT_PARAMETER_PASSWORD).setInclude(false);
- cmd.getParametersMap().get(OnapCommandHttpConstants.DEFAULT_PARAMETER_NO_AUTH).setInclude(false);
- }
break;
- //mrkanag: from auth command, add the parameters to the command's parameters list
-
case OnapCommandHttpConstants.MODE:
Object mode = serviceMap.get(key);
srv.setMode(mode.toString());
break;
}
}
+
cmd.setService(srv);
}
break;
@@ -234,10 +227,34 @@ public class OnapCommandSchemaHttpLoader {
OnapCommandUtils.throwOrCollect(e, errorList, validate);
}
- //Handle the parameters for auth
+ //Handle the parameters for auth:
+ // for commands, copy params from login command to this command
if (!cmd.getService().isNoAuth()) {
- OnapCommand login = OnapCommandSchemaHttpLoader.findAuthCommand(cmd, "login");
- OnapCommandUtils.copyParamSchemasFrom(login, cmd);
+ if (cmd.getInfo().getCommandType().equals(OnapCommandType.AUTH)) {
+ OnapCommandUtils.throwOrCollect(new OnapCommandInvalidSchema(
+ cmd.getSchemaName(), "For auth type commands, http->service->auth should be none"),
+ errorList,
+ validate);
+ } else {
+ OnapCommand login = OnapCommandSchemaHttpLoader.findAuthCommand(cmd, "login");
+ OnapCommandUtils.copyParamSchemasFrom(login, cmd);
+ }
+ } else {
+ //with service->auth: none,
+ //normal cmd: ignore all auth parms
+ if (!cmd.getInfo().getCommandType().equals(OnapCommandType.AUTH)) {
+ cmd.getParametersMap().get(OnapCommandHttpConstants.DEAFULT_PARAMETER_USERNAME).setInclude(false);
+ cmd.getParametersMap().get(OnapCommandHttpConstants.DEAFULT_PARAMETER_PASSWORD).setInclude(false);
+ cmd.getParametersMap().get(OnapCommandHttpConstants.DEFAULT_PARAMETER_NO_AUTH).setInclude(false);
+ } else {
+ //auth: login and logout commands, ignore no-auth
+ cmd.getParametersMap().get(OnapCommandHttpConstants.DEFAULT_PARAMETER_NO_AUTH).setInclude(false);
+ //auth: only for logout commands, ignore username and password too
+ if (!cmd.getName().endsWith(OnapCommandHttpConstants.AUTH_SERVICE_LOGIN)) {
+ cmd.getParametersMap().get(OnapCommandHttpConstants.DEAFULT_PARAMETER_USERNAME).setInclude(false);
+ cmd.getParametersMap().get(OnapCommandHttpConstants.DEAFULT_PARAMETER_PASSWORD).setInclude(false);
+ }
+ }
}
return errorList;