Skip to content

Commit fc83237

Browse files
committed
refactored code
1 parent b6f1e48 commit fc83237

2 files changed

Lines changed: 22 additions & 10 deletions

File tree

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

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
* the IDTokenSource interface and provides a method for obtaining ID tokens specifically from Azure
1616
* DevOps Pipeline environment.
1717
*
18-
* <p>This implementation relies on the <a href="https://learn.microsoft.com/en-us/rest/api/azure/devops/distributedtask/oidctoken/create">Azure DevOps OIDC token API</a>.
18+
* <p>This implementation relies on the <a
19+
* href="https://learn.microsoft.com/en-us/rest/api/azure/devops/distributedtask/oidctoken/create">Azure
20+
* DevOps OIDC token API</a>.
1921
*/
2022
public class AzureDevOpsIDTokenSource implements IDTokenSource {
2123
/* Access token for authenticating with Azure DevOps API */
@@ -99,7 +101,9 @@ private String validateEnvironmentVariable(String varName) {
99101
varName));
100102
}
101103
throw new DatabricksException(
102-
String.format("Missing environment variable %s, likely not calling from Azure DevOps Pipeline", varName));
104+
String.format(
105+
"Missing environment variable %s, likely not calling from Azure DevOps Pipeline",
106+
varName));
103107
}
104108
return value;
105109
}
@@ -164,15 +168,9 @@ public IDToken getIDToken(String audience) {
164168
throw new DatabricksException("Azure DevOps OIDC token response missing 'oidcToken' field");
165169
}
166170

167-
try {
168-
String tokenValue = jsonResp.get("oidcToken").textValue();
169-
} catch (IllegalArgumentException e) {
170-
throw new DatabricksException(
171-
"Received invalid OIDC token from Azure DevOps: " + e.getMessage(), e);
172-
}
173-
171+
String tokenValue = jsonResp.get("oidcToken").textValue();
174172
if (Strings.isNullOrEmpty(tokenValue)) {
175-
throw new DatabricksException("Received empty OIDC token from Azure DevOps");
173+
throw new DatabricksException("Received empty OIDC token from Azure DevOps");
176174
}
177175
return new IDToken(tokenValue);
178176
}

databricks-sdk-java/src/test/java/com/databricks/sdk/core/oauth/AzureDevOpsIDTokenSourceTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,20 @@ private static Stream<Arguments> provideAllTestScenarios() throws IOException {
194194
createValidEnvironment(),
195195
null,
196196
null,
197+
DatabricksException.class),
198+
Arguments.of(
199+
"Non-string oidcToken field (number)",
200+
createHttpMock("{\"oidcToken\":123}", 200, null),
201+
createValidEnvironment(),
202+
null,
203+
null,
204+
DatabricksException.class),
205+
Arguments.of(
206+
"Non-string oidcToken field (object)",
207+
createHttpMock("{\"oidcToken\":{\"nested\":\"value\"}}", 200, null),
208+
createValidEnvironment(),
209+
null,
210+
null,
197211
DatabricksException.class));
198212
}
199213

0 commit comments

Comments
 (0)