Skip to content

Commit f3156e2

Browse files
Make GCP SA token refresh non-blocking with warning on failure (#718)
## 🥞 Stacked PR Use this [link](https://github.com/databricks/databricks-sdk-java/pull/718/files) to review incremental changes. - [**hectorcast-db/stack/port-6-gcp-sa-nonblocking**](#718) [[Files changed](https://github.com/databricks/databricks-sdk-java/pull/718/files)] - [hectorcast-db/stack/port-7-integration-test-metadata](#719) [[Files changed](https://github.com/databricks/databricks-sdk-java/pull/719/files/098605a019d01e262cd9d81d0315be4b77a0fd55..69946cd4740e3226676dd7ff2dce4f0ecbaede68)] - [hectorcast-db/stack/port-8-remove-unified-flag](#720) [[Files changed](https://github.com/databricks/databricks-sdk-java/pull/720/files/69946cd4740e3226676dd7ff2dce4f0ecbaede68..af8d93a4758d730905a9d95833f05911c68e8b5c)] --------- ## Summary Port of Go SDK [#1544](databricks/databricks-sdk-go#1544). Makes the GCP SA access token (`X-Databricks-GCP-SA-Access-Token`) refresh non-blocking in both `GoogleIdCredentialsProvider` and `GoogleCredentialsCredentialsProvider`. On failure, a warning is logged and the header is skipped instead of throwing an exception. The token is now always attempted regardless of client type (previously only for ACCOUNT clients). **Why:** On unified hosts, the config type may not perfectly distinguish account vs workspace operations. Making the SA token optional ensures GCP auth doesn't fail when the SA token isn't needed. **Changes:** - `GoogleIdCredentialsProvider`: removed `ClientType.ACCOUNT` guard, catch `IOException` and log warning - `GoogleCredentialsCredentialsProvider`: same pattern `NO_CHANGELOG=true` ## Test plan - [ ] Verify GCP auth works for account and workspace clients - [ ] Verify warning is logged when SA token refresh fails
1 parent cc5965f commit f3156e2

File tree

2 files changed

+10
-19
lines changed

2 files changed

+10
-19
lines changed

databricks-sdk-java/src/main/java/com/databricks/sdk/core/GoogleCredentialsCredentialsProvider.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,12 @@ public HeaderFactory configure(DatabricksConfig config) {
6666
Map<String, String> headers = new HashMap<>();
6767
headers.put("Authorization", String.format("Bearer %s", idToken.getTokenValue()));
6868

69-
if (config.getClientType() == ClientType.ACCOUNT) {
70-
AccessToken token;
71-
try {
72-
token = finalServiceAccountCredentials.createScoped(GCP_SCOPES).refreshAccessToken();
73-
} catch (IOException e) {
74-
String message =
75-
"Failed to refresh access token from Google service account credentials.";
76-
LOG.error(message + e);
77-
throw new DatabricksException(message, e);
78-
}
69+
try {
70+
AccessToken token =
71+
finalServiceAccountCredentials.createScoped(GCP_SCOPES).refreshAccessToken();
7972
headers.put(SA_ACCESS_TOKEN_HEADER, token.getTokenValue());
73+
} catch (IOException e) {
74+
LOG.warn("Failed to refresh GCP SA access token, skipping header: {}", e.getMessage());
8075
}
8176

8277
return headers;

databricks-sdk-java/src/main/java/com/databricks/sdk/core/GoogleIdCredentialsProvider.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,11 @@ public HeaderFactory configure(DatabricksConfig config) {
6969
throw new DatabricksException(message, e);
7070
}
7171

72-
if (config.getClientType() == ClientType.ACCOUNT) {
73-
try {
74-
headers.put(
75-
SA_ACCESS_TOKEN_HEADER, gcpScopedCredentials.refreshAccessToken().getTokenValue());
76-
} catch (IOException e) {
77-
String message = "Failed to refresh access token from scoped id token credentials.";
78-
LOG.error(message + e);
79-
throw new DatabricksException(message, e);
80-
}
72+
try {
73+
headers.put(
74+
SA_ACCESS_TOKEN_HEADER, gcpScopedCredentials.refreshAccessToken().getTokenValue());
75+
} catch (IOException e) {
76+
LOG.warn("Failed to refresh GCP SA access token, skipping header: {}", e.getMessage());
8177
}
8278

8379
return headers;

0 commit comments

Comments
 (0)