private boolean isSecured = false;
public void setValues(List<String> values) {
- this.values = values;
+ this.values = (values == null) ? new ArrayList<>() : values;
}
public String getName() {
continue;
}
+ //First check if there is an specific plugin exist, otherwise check for profile plugin
if (plugins.containsKey(schema.getSchemaName())) {
this.register(schema.getCmdName(), schema.getProduct(), plugins.get(schema.getSchemaName()));
} else if (plugins.containsKey(schema.getSchemaProfile())) {
}
public static void copyParamsFrom(OnapCommand from, OnapCommand to) throws OnapCommandInvalidParameterValue {
- OnapCommandUtils.copyParamsFrom(from, to, new HashMap<String, String>());
+ copyParamsFrom(from, to, new HashMap<String, String>());
}
/**
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);
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);
}
/**
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();
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;
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
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());
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";
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;
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;
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;