- /**
- * Allows Directed Graphs the ability to interact with REST APIs.
- * @param parameters HashMap<String,String> of parameters passed by the DG to this function
- * <table border="1">
- * <thead><th>parameter</th><th>Mandatory/Optional</th><th>description</th><th>example values</th></thead>
- * <tbody>
- * <tr><td>templateFileName</td><td>Optional</td><td>full path to template file that can be used to build a request</td><td>/sdncopt/bvc/restapi/templates/vnf_service-configuration-operation_minimal.json</td></tr>
- * <tr><td>restapiUrl</td><td>Mandatory</td><td>url to send the request to</td><td>https://sdncodl:8543/restconf/operations/L3VNF-API:create-update-vnf-request</td></tr>
- * <tr><td>restapiUser</td><td>Optional</td><td>user name to use for http basic authentication</td><td>sdnc_ws</td></tr>
- * <tr><td>restapiPassword</td><td>Optional</td><td>unencrypted password to use for http basic authentication</td><td>plain_password</td></tr>
- * <tr><td>contentType</td><td>Optional</td><td>http content type to set in the http header</td><td>usually application/json or application/xml</td></tr>
- * <tr><td>format</td><td>Optional</td><td>should match request body format</td><td>json or xml</td></tr>
- * <tr><td>httpMethod</td><td>Optional</td><td>http method to use when sending the request</td><td>get post put delete patch</td></tr>
- * <tr><td>responsePrefix</td><td>Optional</td><td>location the response will be written to in context memory</td><td>tmp.restapi.result</td></tr>
- * <tr><td>listName[i]</td><td>Optional</td><td>Used for processing XML responses with repeating elements.</td>vpn-information.vrf-details<td></td></tr>
- * <tr><td>skipSending</td><td>Optional</td><td></td><td>true or false</td></tr>
- * <tr><td>convertResponse </td><td>Optional</td><td>whether the response should be converted</td><td>true or false</td></tr>
- * <tr><td>customHttpHeaders</td><td>Optional</td><td>a list additional http headers to be passed in, follow the format in the example</td><td>X-CSI-MessageId=messageId,headerFieldName=headerFieldValue</td></tr>
- * <tr><td>dumpHeaders</td><td>Optional</td><td>when true writes http header content to context memory</td><td>true or false</td></tr>
- * <tr><td>partner</td><td>Optional</td><td>needed for DME2 calls</td><td>dme2proxy</td></tr>
- * </tbody>
- * </table>
+ /**
+ * Validates the given URL in the parameters.
+ *
+ * @param restapiUrl rest api URL
+ * @throws SvcLogicException when URL validation fails
+ */
+ private static void validateUrl(String restapiUrl) throws SvcLogicException {
+ if (restapiUrl.contains(",")) {
+ String[] urls = restapiUrl.split(",");
+ for (String url : urls) {
+ validateUrl(url);
+ }
+ } else {
+ try {
+ URI.create(restapiUrl);
+ } catch (IllegalArgumentException e) {
+ throw new SvcLogicException("Invalid input of url " + e.getLocalizedMessage(), e);
+ }
+ }
+ }
+
+ /**
+ * Returns the list of list name.
+ *
+ * @param paramMap parameters map
+ * @return list of list name
+ */
+ private static Set<String> getListNameList(Map<String, String> paramMap) {
+ Set<String> ll = new HashSet<>();
+ for (Map.Entry<String, String> entry : paramMap.entrySet()) {
+ if (entry.getKey().startsWith("listName")) {
+ ll.add(entry.getValue());
+ }
+ }
+ return ll;
+ }
+
+ /**
+ * Parses the parameter string map of property, validates if required, assigns default value if
+ * present and returns the value.
+ *
+ * @param paramMap string param map
+ * @param name name of the property
+ * @param required if value required
+ * @param def default value
+ * @return value of the property
+ * @throws SvcLogicException if required parameter value is empty
+ */
+ public static String parseParam(Map<String, String> paramMap, String name, boolean required, String def)
+ throws SvcLogicException {
+ String s = paramMap.get(name);
+
+ if (s == null || s.trim().length() == 0) {
+ if (!required) {
+ return def;
+ }
+ throw new SvcLogicException("Parameter " + name + " is required in RestapiCallNode");
+ }
+
+ s = s.trim();
+ StringBuilder value = new StringBuilder();
+ int i = 0;
+ int i1 = s.indexOf('%');
+ while (i1 >= 0) {
+ int i2 = s.indexOf('%', i1 + 1);
+ if (i2 < 0) {
+ break;
+ }
+
+ String varName = s.substring(i1 + 1, i2);
+ String varValue = System.getenv(varName);
+ if (varValue == null) {
+ varValue = "%" + varName + "%";
+ }
+
+ value.append(s.substring(i, i1));
+ value.append(varValue);
+
+ i = i2 + 1;
+ i1 = s.indexOf('%', i);
+ }
+ value.append(s.substring(i));
+
+ log.info("Parameter {}: [{}]", name, maskPassword(name, value));
+
+ return value.toString();
+ }
+
+ private static Object maskPassword(String name, Object value) {
+ String[] pwdNames = {"pwd", "passwd", "password", "Pwd", "Passwd", "Password"};
+ for (String pwdName : pwdNames) {
+ if (name.contains(pwdName)) {
+ return "**********";
+ }
+ }
+ return value;
+ }
+
+ /**
+ * Allows Directed Graphs the ability to interact with REST APIs.
+ *
+ * @param paramMap HashMap<String,String> of parameters passed by the DG to this function
+ * <table border="1">
+ * <thead>
+ * <th>parameter</th>
+ * <th>Mandatory/Optional</th>
+ * <th>description</th>
+ * <th>example values</th></thead> <tbody>
+ * <tr>
+ * <td>templateFileName</td>
+ * <td>Optional</td>
+ * <td>full path to template file that can be used to build a request</td>
+ * <td>/sdncopt/bvc/restapi/templates/vnf_service-configuration-operation_minimal.json</td>
+ * </tr>
+ * <tr>
+ * <td>restapiUrl</td>
+ * <td>Mandatory</td>
+ * <td>url to send the request to</td>
+ * <td>https://sdncodl:8543/restconf/operations/L3VNF-API:create-update-vnf-request</td>
+ * </tr>
+ * <tr>
+ * <td>restapiUser</td>
+ * <td>Optional</td>
+ * <td>user name to use for http basic authentication</td>
+ * <td>sdnc_ws</td>
+ * </tr>
+ * <tr>
+ * <td>restapiPassword</td>
+ * <td>Optional</td>
+ * <td>unencrypted password to use for http basic authentication</td>
+ * <td>plain_password</td>
+ * </tr>
+ * <tr>
+ * <td>oAuthConsumerKey</td>
+ * <td>Optional</td>
+ * <td>Consumer key to use for http oAuth authentication</td>
+ * <td>plain_key</td>
+ * </tr>
+ * <tr>
+ * <td>oAuthConsumerSecret</td>
+ * <td>Optional</td>
+ * <td>Consumer secret to use for http oAuth authentication</td>
+ * <td>plain_secret</td>
+ * </tr>
+ * <tr>
+ * <td>oAuthSignatureMethod</td>
+ * <td>Optional</td>
+ * <td>Consumer method to use for http oAuth authentication</td>
+ * <td>method</td>
+ * </tr>
+ * <tr>
+ * <td>oAuthVersion</td>
+ * <td>Optional</td>
+ * <td>Version http oAuth authentication</td>
+ * <td>version</td>
+ * </tr>
+ * <tr>
+ * <td>contentType</td>
+ * <td>Optional</td>
+ * <td>http content type to set in the http header</td>
+ * <td>usually application/json or application/xml</td>
+ * </tr>
+ * <tr>
+ * <td>format</td>
+ * <td>Optional</td>
+ * <td>should match request body format</td>
+ * <td>json or xml</td>
+ * </tr>
+ * <tr>
+ * <td>httpMethod</td>
+ * <td>Optional</td>
+ * <td>http method to use when sending the request</td>
+ * <td>get post put delete patch</td>
+ * </tr>
+ * <tr>
+ * <td>responsePrefix</td>
+ * <td>Optional</td>
+ * <td>location the response will be written to in context memory</td>
+ * <td>tmp.restapi.result</td>
+ * </tr>
+ * <tr>
+ * <td>listName[i]</td>
+ * <td>Optional</td>
+ * <td>Used for processing XML responses with repeating
+ * elements.</td>vpn-information.vrf-details
+ * <td></td>
+ * </tr>
+ * <tr>
+ * <td>skipSending</td>
+ * <td>Optional</td>
+ * <td></td>
+ * <td>true or false</td>
+ * </tr>
+ * <tr>
+ * <td>convertResponse</td>
+ * <td>Optional</td>
+ * <td>whether the response should be converted</td>
+ * <td>true or false</td>
+ * </tr>
+ * <tr>
+ * <td>customHttpHeaders</td>
+ * <td>Optional</td>
+ * <td>a list additional http headers to be passed in, follow the format in the example</td>
+ * <td>X-CSI-MessageId=messageId,headerFieldName=headerFieldValue</td>
+ * </tr>
+ * <tr>
+ * <td>dumpHeaders</td>
+ * <td>Optional</td>
+ * <td>when true writes http header content to context memory</td>
+ * <td>true or false</td>
+ * </tr>
+ * <tr>
+ * <td>partner</td>
+ * <td>Optional</td>
+ * <td>used to retrieve username, password and url if partner store exists</td>
+ * <td>aaf</td>
+ * </tr>
+ * <tr>
+ * <td>returnRequestPayload</td>
+ * <td>Optional</td>
+ * <td>used to return payload built in the request</td>
+ * <td>true or false</td>
+ * </tr>
+ * </tbody>
+ * </table>