Skip to content

Commit

Permalink
SQL: Refactor Tableau connector to make use of the connection propert…
Browse files Browse the repository at this point in the history
…ies (#69169)

* Refactor to make use of the connection propreties

This refactors the way the connection URL is being built, to make use of
frameworks' ability to construct the URL based on a set of connection
propreties.
This also ensures that the URI attributes are properly escaped.

(cherry picked from commit 3c1e0a9)
  • Loading branch information
bpintea committed May 18, 2021
1 parent 34586d5 commit 77b8473
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,7 @@
} else{
urlBuilder += "http://";
}
urlBuilder += attr["server"] + ":" + attr["port"];
urlBuilder += attr["server"] + ":" + attr["port"] + "?";

var params = [];
params["user"] = attr["username"];
params["password"] = attr["password"];

var formattedParams = [];

for (var key in params) {
if (params[key]) {
var param = encodeURIComponent(params[key]);
formattedParams.push(connectionHelper.formatKeyValuePair(key, param));
}
}

if (formattedParams.length > 0) {
urlBuilder += "?" + formattedParams.join("&")
}

// logging visible in log.txt if -DLogLevel=Debug is added in Tableau command line
logging.log("ES JDBC URL before adding additional parameters: " + urlBuilder);

// TODO: wrap error-prone "free form"
var additionalConnectionParameters = attr[connectionHelper.attributeWarehouse];
if (additionalConnectionParameters != null && additionalConnectionParameters.trim().length > 0) {
urlBuilder += (formattedParams.length == 0) ? "?" : "&";
urlBuilder += additionalConnectionParameters;
}

logging.log("ES JDBC final URL: " + urlBuilder);
return [urlBuilder];
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
(function propertiesbuilder(attr) {
var props = {};

props["user"] = attr["username"];
props["password"] = attr["password"];

var extraProps = attr[connectionHelper.attributeWarehouse];
if (extraProps != null && extraProps.trim().length > 0) {
// allow `&` and white-space as attribue-value pair delimiters
var avps = extraProps.trim().split(/[\s&]/);
for (var i = 0; i < avps.length; i++) {
var tokens = avps[i].split("=");
if (tokens.length != 2 || tokens[0].length == 0 || tokens[1].length == 0) {
var errMessage = "Invalid additional settings property `" + avps[i] + "`: " +
"not conforming to the attribute=value format."
return connectionHelper.ThrowTableauException(errMessage);
} else {
props[tokens[0]] = tokens[1];
}
}
}

return props;
})
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,8 @@
</attribute-list>
</required-attributes>
</connection-normalizer>
<connection-properties>
<script file='connectionProperties.js'/>
</connection-properties>
</connection-resolver>
</tdr>

0 comments on commit 77b8473

Please sign in to comment.