Skip to content

Commit 9f9f7a1

Browse files
committed
code formatting
Signed-off-by: Sreekanth Vadigi <[email protected]>
1 parent cf281fd commit 9f9f7a1

File tree

5 files changed

+32
-25
lines changed

5 files changed

+32
-25
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import org.apache.http.HttpMessage;
1919

2020
public class DatabricksConfig {
21-
2221
private CredentialsProvider credentialsProvider = new DefaultCredentialsProvider();
2322

2423
@ConfigAttribute(env = "DATABRICKS_HOST")

databricks-sdk-java/src/main/java/com/databricks/sdk/core/oauth/AzureServicePrincipalCredentialsProvider.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,17 @@ public OAuthHeaderFactory configure(DatabricksConfig config) {
2626
|| config.getAzureClientSecret() == null) {
2727
return null;
2828
}
29-
30-
this.tenantId = config.getAzureTenantId() != null ? config.getAzureTenantId() : AzureUtils.inferTenantId(config);
29+
30+
this.tenantId =
31+
config.getAzureTenantId() != null
32+
? config.getAzureTenantId()
33+
: AzureUtils.inferTenantId(config);
3134
if (this.tenantId == null) {
3235
return null;
3336
}
34-
35-
AzureUtils.ensureHostPresent(
36-
config, mapper, this::tokenSourceFor);
37-
37+
38+
AzureUtils.ensureHostPresent(config, mapper, this::tokenSourceFor);
39+
3840
CachedTokenSource inner = tokenSourceFor(config, config.getEffectiveAzureLoginAppId());
3941
CachedTokenSource cloud =
4042
tokenSourceFor(config, config.getAzureEnvironment().getServiceManagementEndpoint());

databricks-sdk-java/src/main/java/com/databricks/sdk/core/utils/AzureUtils.java

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -106,20 +106,20 @@ public static Optional<String> getAzureWorkspaceResourceId(Workspace workspace)
106106

107107
/**
108108
* Infers the Azure tenant ID from the Databricks workspace login page.
109-
*
109+
*
110110
* @param config The DatabricksConfig instance
111111
* @return the discovered tenant ID, or null if discovery fails
112112
*/
113113
public static String inferTenantId(DatabricksConfig config) {
114114
if (config.getAzureTenantId() != null) {
115115
return config.getAzureTenantId();
116116
}
117-
117+
118118
if (!config.isAzure() || config.getHost() == null) {
119119
logger.warn("Cannot infer tenant ID: workspace is not Azure or host is missing");
120120
return null;
121121
}
122-
122+
123123
String loginUrl = config.getHost() + AZURE_AUTH_ENDPOINT;
124124

125125
try {
@@ -128,52 +128,59 @@ public static String inferTenantId(DatabricksConfig config) {
128128
logger.warn("Failed to get redirect location from Azure auth endpoint: {}", loginUrl);
129129
return null;
130130
}
131-
131+
132132
String extractedTenantId = extractTenantIdFromUrl(redirectLocation);
133133
if (extractedTenantId == null) {
134134
logger.warn("Failed to extract tenant ID from redirect URL: {}", redirectLocation);
135135
return null;
136136
}
137-
137+
138138
logger.info("Successfully discovered Azure tenant ID: {}", extractedTenantId);
139139
return extractedTenantId;
140-
140+
141141
} catch (Exception e) {
142-
logger.warn("Exception occurred while inferring Azure tenant ID from {}: {}", loginUrl, e.getMessage());
142+
logger.warn(
143+
"Exception occurred while inferring Azure tenant ID from {}: {}",
144+
loginUrl,
145+
e.getMessage());
143146
return null;
144147
}
145148
}
146-
147-
private static String getRedirectLocation(DatabricksConfig config, String loginUrl) throws IOException {
149+
150+
private static String getRedirectLocation(DatabricksConfig config, String loginUrl)
151+
throws IOException {
148152
Request request = new Request("GET", loginUrl);
149153
request.setRedirectionBehavior(false);
150154
Response response = config.getHttpClient().execute(request);
151-
155+
152156
if (response.getStatusCode() != 302) {
153-
logger.warn("Expected redirect (302) from {}, got status code: {}", loginUrl, response.getStatusCode());
157+
logger.warn(
158+
"Expected redirect (302) from {}, got status code: {}",
159+
loginUrl,
160+
response.getStatusCode());
154161
return null;
155162
}
156-
163+
157164
String location = response.getFirstHeader("Location");
158165
if (location == null) {
159166
logger.warn("No Location header in redirect response from {}", loginUrl);
160167
}
161-
168+
162169
return location;
163170
}
164-
171+
165172
private static String extractTenantIdFromUrl(String redirectUrl) {
166173
try {
167174
// Parse: https://login.microsoftonline.com/<tenant-id>/oauth2/authorize?...
168175
URL entraIdUrl = new URL(redirectUrl);
169176
String[] pathSegments = entraIdUrl.getPath().split("/");
170-
177+
171178
if (pathSegments.length < 2) {
172179
logger.warn("Invalid path in Location header: {}", entraIdUrl.getPath());
173180
return null;
174181
}
175182

176-
return pathSegments[1];
183+
return pathSegments[1];
177184
} catch (Exception e) {
178185
logger.warn("Failed to parse tenant ID from URL {}: {}", redirectUrl, e.getMessage());
179186
return null;

databricks-sdk-java/src/test/java/com/databricks/sdk/core/DatabricksConfigTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,5 +250,4 @@ public void testGetTokenSourceWithOAuth() {
250250
assertFalse(tokenSource instanceof ErrorTokenSource);
251251
assertEquals(tokenSource.getToken().getAccessToken(), "test-token");
252252
}
253-
254253
}

databricks-sdk-java/src/test/java/com/databricks/sdk/core/utils/AzureUtilsTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
import static org.junit.jupiter.api.Assertions.*;
44

55
import com.databricks.sdk.core.DatabricksConfig;
6-
import com.databricks.sdk.core.commons.CommonsHttpClient;
76
import com.databricks.sdk.core.FixtureServer;
7+
import com.databricks.sdk.core.commons.CommonsHttpClient;
88
import java.io.IOException;
99
import org.junit.jupiter.api.Test;
1010

0 commit comments

Comments
 (0)