Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
samikshya-db committed Nov 7, 2024
1 parent 1bfd4a3 commit 6d23597
Showing 1 changed file with 16 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static DatabricksConfig resolve(DatabricksConfig cfg) throws DatabricksEx
}
}

static void loadFromEnvironmentVariables(DatabricksConfig cfg) throws IllegalAccessException {
static void loadFromEnvironmentVariables(DatabricksConfig cfg) {
if (cfg.getEnv() == null) {
return;
}
Expand All @@ -58,15 +58,16 @@ static void loadFromEnvironmentVariables(DatabricksConfig cfg) throws IllegalAcc
}
accessor.setValueOnConfig(cfg, env);
}
} catch (DatabricksException e) {
String msg = String.format("%s auth: %s", cfg.getCredentialsProvider().authType(), e.getMessage());
} catch (DatabricksException | IllegalAccessException e) {
String msg =
String.format("%s auth: %s", cfg.getCredentialsProvider().authType(), e.getMessage());
throw new DatabricksException(msg, e);
}
}

static void loadFromConfig(DatabricksConfig cfg) throws IllegalAccessException {
if (isNullOrEmpty(cfg.getProfile())
&& (isAnyAuthConfigured(cfg)
&& (isAnyAuthConfigured(cfg)
|| !isNullOrEmpty(cfg.getHost())
|| !isNullOrEmpty(cfg.getAzureWorkspaceResourceId()))) {
return;
Expand Down Expand Up @@ -94,14 +95,13 @@ static void loadFromConfig(DatabricksConfig cfg) throws IllegalAccessException {
if (!hasExplicitProfile) {
profile = "DEFAULT";
}

SubnodeConfiguration section = ini.getSection(profile);
if (section == null && !hasExplicitProfile) {
boolean sectionNotPresent = section == null || section.isEmpty();
if (sectionNotPresent && !hasExplicitProfile) {
LOG.info("{} has no {} profile configured", configFile, profile);
return;
}

if (section == null) {
if (sectionNotPresent) {
String msg = String.format("resolve: %s has no %s profile configured", configFile, profile);
throw new DatabricksException(msg);
}
Expand Down Expand Up @@ -166,18 +166,22 @@ static void validate(DatabricksConfig cfg) throws DatabricksException {
}
if (authSet.size() <= 1) return;
String names = String.join(" and ", authSet);
throw new DatabricksException(String.format("validate: more than one authorization method configured: %s", names));
throw new DatabricksException(
String.format("validate: more than one authorization method configured: %s", names));
} catch (IllegalAccessException e) {
throw new DatabricksException("Cannot create default config", e);
}
}

public static DatabricksException makeNicerError(String message, Exception e, DatabricksConfig cfg) {
public static DatabricksException makeNicerError(
String message, Exception e, DatabricksConfig cfg) {
return makeNicerError(message, e, 200, cfg);
}

public static DatabricksException makeNicerError(String message, Exception e, Integer statusCode, DatabricksConfig cfg) {
boolean isHttpUnauthorizedOrForbidden = true; // TODO - pass status code with exception, default this to false
public static DatabricksException makeNicerError(
String message, Exception e, Integer statusCode, DatabricksConfig cfg) {
boolean isHttpUnauthorizedOrForbidden =
true; // TODO - pass status code with exception, default this to false
if (statusCode == 401 || statusCode == 402) isHttpUnauthorizedOrForbidden = true;
String debugString = "";
if (cfg.getEnv() != null) {
Expand Down

0 comments on commit 6d23597

Please sign in to comment.