Skip to content

Commit 77b8473

Browse files
committed
SQL: Refactor Tableau connector to make use of the connection properties (#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)
1 parent 34586d5 commit 77b8473

File tree

3 files changed

+28
-29
lines changed

3 files changed

+28
-29
lines changed

x-pack/plugin/sql/connectors/tableau/connector/connectionBuilder.js

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,35 +6,7 @@
66
} else{
77
urlBuilder += "http://";
88
}
9-
urlBuilder += attr["server"] + ":" + attr["port"];
9+
urlBuilder += attr["server"] + ":" + attr["port"] + "?";
1010

11-
var params = [];
12-
params["user"] = attr["username"];
13-
params["password"] = attr["password"];
14-
15-
var formattedParams = [];
16-
17-
for (var key in params) {
18-
if (params[key]) {
19-
var param = encodeURIComponent(params[key]);
20-
formattedParams.push(connectionHelper.formatKeyValuePair(key, param));
21-
}
22-
}
23-
24-
if (formattedParams.length > 0) {
25-
urlBuilder += "?" + formattedParams.join("&")
26-
}
27-
28-
// logging visible in log.txt if -DLogLevel=Debug is added in Tableau command line
29-
logging.log("ES JDBC URL before adding additional parameters: " + urlBuilder);
30-
31-
// TODO: wrap error-prone "free form"
32-
var additionalConnectionParameters = attr[connectionHelper.attributeWarehouse];
33-
if (additionalConnectionParameters != null && additionalConnectionParameters.trim().length > 0) {
34-
urlBuilder += (formattedParams.length == 0) ? "?" : "&";
35-
urlBuilder += additionalConnectionParameters;
36-
}
37-
38-
logging.log("ES JDBC final URL: " + urlBuilder);
3911
return [urlBuilder];
4012
})
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
(function propertiesbuilder(attr) {
2+
var props = {};
3+
4+
props["user"] = attr["username"];
5+
props["password"] = attr["password"];
6+
7+
var extraProps = attr[connectionHelper.attributeWarehouse];
8+
if (extraProps != null && extraProps.trim().length > 0) {
9+
// allow `&` and white-space as attribue-value pair delimiters
10+
var avps = extraProps.trim().split(/[\s&]/);
11+
for (var i = 0; i < avps.length; i++) {
12+
var tokens = avps[i].split("=");
13+
if (tokens.length != 2 || tokens[0].length == 0 || tokens[1].length == 0) {
14+
var errMessage = "Invalid additional settings property `" + avps[i] + "`: " +
15+
"not conforming to the attribute=value format."
16+
return connectionHelper.ThrowTableauException(errMessage);
17+
} else {
18+
props[tokens[0]] = tokens[1];
19+
}
20+
}
21+
}
22+
23+
return props;
24+
})

x-pack/plugin/sql/connectors/tableau/connector/connectionResolver.tdr

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,8 @@
1717
</attribute-list>
1818
</required-attributes>
1919
</connection-normalizer>
20+
<connection-properties>
21+
<script file='connectionProperties.js'/>
22+
</connection-properties>
2023
</connection-resolver>
2124
</tdr>

0 commit comments

Comments
 (0)