Skip to content

Commit 8dc3985

Browse files
Anthrinothomasbanghart
authored andcommitted
Assign User Agent and x-looker-appid headers in Looker JDBC Driver
Fixes: b/343254086
1 parent 4ffa373 commit 8dc3985

2 files changed

Lines changed: 13 additions & 5 deletions

File tree

core/src/main/java/org/apache/calcite/avatica/remote/looker/LookerSdkFactory.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import com.looker.rtl.Transport;
2525
import com.looker.rtl.TransportKt;
2626
import com.looker.sdk.ApiSettings;
27+
import com.looker.sdk.Constants;
2728
import com.looker.sdk.LookerSDK;
2829

2930
import java.sql.SQLException;
@@ -48,6 +49,8 @@ private LookerSdkFactory() {
4849

4950
private static final String RESULT_FORMAT = "json_bi";
5051
private static final String QUERY_ENDPOINT = "/api/4.0/sql_interface_queries/%s/run/%s";
52+
private static final String DRIVER_USER_AGENT = "looker-jdbc-driver-1.24.1";
53+
private static final String USER_AGENT_STRING = "User-Agent";
5154

5255
/**
5356
* 1 hour in seconds. This is not configurable.
@@ -125,12 +128,15 @@ private static AuthSession createAuthSession(String url, Map<String, String> pro
125128

126129
ConfigurationProvider finalizedConfig = ApiSettings.fromMap(apiConfig);
127130

131+
// assign values for user agent and x-looker-appid headers and add to session
128132
String userAgent = props.get("userAgent");
129-
if (userAgent != null) {
130-
Map<String, String> headers = finalizedConfig.getHeaders();
131-
headers.put("User-Agent", props.get("userAgent"));
132-
finalizedConfig.setHeaders(headers);
133+
if (userAgent == null) {
134+
userAgent = DRIVER_USER_AGENT;
133135
}
136+
Map<String, String> headers = finalizedConfig.getHeaders();
137+
headers.put(USER_AGENT_STRING, userAgent);
138+
headers.put(Constants.LOOKER_APPID, userAgent);
139+
finalizedConfig.setHeaders(headers);
134140

135141
AuthSession session = new AuthSession(finalizedConfig, new Transport(finalizedConfig));
136142

looker.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ You should make it from a branch that differs from Avatica's
6464

6565
In Avatica's `gradle.properties`, update the value of
6666
`calcite.avatica.version` to the release name (something like
67-
`1.22.1-looker`) and commit.
67+
`1.22.1-looker`). Additionally, update the `DRIVER_USER_AGENT` property string
68+
in [LookerSdkFactory](core/src/main/java/org/apache/calcite/avatica/remote/looker/LookerSdkFactory.java)
69+
to point to the same build version and commit.
6870

6971
Define Looker's Nexus repository in your `~/.gradle/init.gradle.kts`
7072
file:

0 commit comments

Comments
 (0)