Skip to content

Commit 23369fa

Browse files
committed
Fix vulnerabilities
1 parent f04f6cb commit 23369fa

File tree

2 files changed

+22
-21
lines changed

2 files changed

+22
-21
lines changed

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

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
package com.databricks.sdk.core;
22

33
import com.databricks.sdk.core.utils.Environment;
4-
import java.io.File;
54
import java.io.FileNotFoundException;
5+
import java.io.FileReader;
66
import java.io.IOException;
77
import java.lang.reflect.Field;
88
import java.net.MalformedURLException;
99
import java.net.URL;
1010
import java.nio.file.Paths;
1111
import java.util.*;
12-
import org.ini4j.Ini;
13-
import org.ini4j.Profile;
12+
import org.apache.commons.configuration2.INIConfiguration;
13+
import org.apache.commons.configuration2.SubnodeConfiguration;
14+
import org.apache.commons.configuration2.ex.ConfigurationException;
1415
import org.slf4j.Logger;
1516
import org.slf4j.LoggerFactory;
1617

@@ -59,14 +60,14 @@ static void loadFromEnvironmentVariables(DatabricksConfig cfg) throws IllegalAcc
5960
}
6061
} catch (DatabricksException e) {
6162
String msg =
62-
String.format("%s auth: %s", cfg.getCredentialsProvider().authType(), e.getMessage());
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;
@@ -86,15 +87,15 @@ static void loadFromConfig(DatabricksConfig cfg) throws IllegalAccessException {
8687
configFile = configFile.replaceFirst("^~", userHome);
8788
}
8889

89-
Ini ini = parseDatabricksCfg(configFile, isDefaultConfig);
90+
INIConfiguration ini = parseDatabricksCfg(configFile, isDefaultConfig);
9091
if (ini == null) return;
9192
String profile = cfg.getProfile();
9293
boolean hasExplicitProfile = !isNullOrEmpty(profile);
9394
if (!hasExplicitProfile) {
9495
profile = "DEFAULT";
9596
}
9697

97-
Profile.Section section = ini.get(profile);
98+
SubnodeConfiguration section = ini.getSection(profile);
9899
if (section == null && !hasExplicitProfile) {
99100
LOG.info("{} has no {} profile configured", configFile, profile);
100101
return;
@@ -106,26 +107,26 @@ static void loadFromConfig(DatabricksConfig cfg) throws IllegalAccessException {
106107
}
107108

108109
for (ConfigAttributeAccessor accessor : accessors) {
109-
String value = section.get(accessor.getName());
110+
String value = section.getString(accessor.getName());
110111
if (!isNullOrEmpty(accessor.getValueFromConfig(cfg))) {
111112
continue;
112113
}
113114
accessor.setValueOnConfig(cfg, value);
114115
}
115116
}
116117

117-
private static Ini parseDatabricksCfg(String configFile, boolean isDefaultConfig) {
118-
Ini ini = new Ini();
119-
try {
120-
ini.load(new File(configFile));
118+
private static INIConfiguration parseDatabricksCfg(String configFile, boolean isDefaultConfig) {
119+
INIConfiguration iniConfig = new INIConfiguration();
120+
try (FileReader reader = new FileReader(configFile)) {
121+
iniConfig.read(reader);
121122
} catch (FileNotFoundException e) {
122123
if (isDefaultConfig) {
123124
return null;
124125
}
125-
} catch (IOException e) {
126+
} catch (IOException | ConfigurationException e) {
126127
throw new DatabricksException("Cannot load " + configFile, e);
127128
}
128-
return ini;
129+
return iniConfig;
129130
}
130131

131132
public static void fixHostIfNeeded(DatabricksConfig cfg) {
@@ -166,21 +167,21 @@ static void validate(DatabricksConfig cfg) throws DatabricksException {
166167
if (authSet.size() <= 1) return;
167168
String names = String.join(" and ", authSet);
168169
throw new DatabricksException(
169-
String.format("validate: more than one authorization method configured: %s", names));
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

175176
public static DatabricksException makeNicerError(
176-
String message, Exception e, DatabricksConfig cfg) {
177+
String message, Exception e, DatabricksConfig cfg) {
177178
return makeNicerError(message, e, 200, cfg);
178179
}
179180

180181
public static DatabricksException makeNicerError(
181-
String message, Exception e, Integer statusCode, DatabricksConfig cfg) {
182+
String message, Exception e, Integer statusCode, DatabricksConfig cfg) {
182183
boolean isHttpUnauthorizedOrForbidden =
183-
true; // TODO - pass status code with exception, default this to false
184+
true; // TODO - pass status code with exception, default this to false
184185
if (statusCode == 401 || statusCode == 402) isHttpUnauthorizedOrForbidden = true;
185186
String debugString = "";
186187
if (cfg.getEnv() != null) {
@@ -264,4 +265,4 @@ public static boolean isAnyAuthConfigured(DatabricksConfig cfg) throws IllegalAc
264265
}
265266
return false;
266267
}
267-
}
268+
}

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
44
<modelVersion>4.0.0</modelVersion>
55
<groupId>com.databricks</groupId>
66
<artifactId>databricks-sdk-parent</artifactId>
@@ -291,4 +291,4 @@
291291
</build>
292292
</profile>
293293
</profiles>
294-
</project>
294+
</project>

0 commit comments

Comments
 (0)