Skip to content

Commit 6d23597

Browse files
committed
fix tests
1 parent 1bfd4a3 commit 6d23597

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

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

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public static DatabricksConfig resolve(DatabricksConfig cfg) throws DatabricksEx
4141
}
4242
}
4343

44-
static void loadFromEnvironmentVariables(DatabricksConfig cfg) throws IllegalAccessException {
44+
static void loadFromEnvironmentVariables(DatabricksConfig cfg) {
4545
if (cfg.getEnv() == null) {
4646
return;
4747
}
@@ -58,15 +58,16 @@ static void loadFromEnvironmentVariables(DatabricksConfig cfg) throws IllegalAcc
5858
}
5959
accessor.setValueOnConfig(cfg, env);
6060
}
61-
} catch (DatabricksException e) {
62-
String msg = String.format("%s auth: %s", cfg.getCredentialsProvider().authType(), e.getMessage());
61+
} catch (DatabricksException | IllegalAccessException e) {
62+
String msg =
63+
String.format("%s auth: %s", cfg.getCredentialsProvider().authType(), e.getMessage());
6364
throw new DatabricksException(msg, e);
6465
}
6566
}
6667

6768
static void loadFromConfig(DatabricksConfig cfg) throws IllegalAccessException {
6869
if (isNullOrEmpty(cfg.getProfile())
69-
&& (isAnyAuthConfigured(cfg)
70+
&& (isAnyAuthConfigured(cfg)
7071
|| !isNullOrEmpty(cfg.getHost())
7172
|| !isNullOrEmpty(cfg.getAzureWorkspaceResourceId()))) {
7273
return;
@@ -94,14 +95,13 @@ static void loadFromConfig(DatabricksConfig cfg) throws IllegalAccessException {
9495
if (!hasExplicitProfile) {
9596
profile = "DEFAULT";
9697
}
97-
9898
SubnodeConfiguration section = ini.getSection(profile);
99-
if (section == null && !hasExplicitProfile) {
99+
boolean sectionNotPresent = section == null || section.isEmpty();
100+
if (sectionNotPresent && !hasExplicitProfile) {
100101
LOG.info("{} has no {} profile configured", configFile, profile);
101102
return;
102103
}
103-
104-
if (section == null) {
104+
if (sectionNotPresent) {
105105
String msg = String.format("resolve: %s has no %s profile configured", configFile, profile);
106106
throw new DatabricksException(msg);
107107
}
@@ -166,18 +166,22 @@ static void validate(DatabricksConfig cfg) throws DatabricksException {
166166
}
167167
if (authSet.size() <= 1) return;
168168
String names = String.join(" and ", authSet);
169-
throw new DatabricksException(String.format("validate: more than one authorization method configured: %s", names));
169+
throw new DatabricksException(
170+
String.format("validate: more than one authorization method configured: %s", names));
170171
} catch (IllegalAccessException e) {
171172
throw new DatabricksException("Cannot create default config", e);
172173
}
173174
}
174175

175-
public static DatabricksException makeNicerError(String message, Exception e, DatabricksConfig cfg) {
176+
public static DatabricksException makeNicerError(
177+
String message, Exception e, DatabricksConfig cfg) {
176178
return makeNicerError(message, e, 200, cfg);
177179
}
178180

179-
public static DatabricksException makeNicerError(String message, Exception e, Integer statusCode, DatabricksConfig cfg) {
180-
boolean isHttpUnauthorizedOrForbidden = true; // TODO - pass status code with exception, default this to false
181+
public static DatabricksException makeNicerError(
182+
String message, Exception e, Integer statusCode, DatabricksConfig cfg) {
183+
boolean isHttpUnauthorizedOrForbidden =
184+
true; // TODO - pass status code with exception, default this to false
181185
if (statusCode == 401 || statusCode == 402) isHttpUnauthorizedOrForbidden = true;
182186
String debugString = "";
183187
if (cfg.getEnv() != null) {

0 commit comments

Comments
 (0)