Skip to content

Commit

Permalink
Refactor ArgsUtils.getConfigurationSubject() (#30114)
Browse files Browse the repository at this point in the history
* Refactor ShowEncryptRuleExecutor

* Refactor ArgsUtils
  • Loading branch information
terrymanu authored Feb 13, 2024
1 parent 7b3a525 commit 78c05da
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import java.util.LinkedList;
import java.util.Map;
import java.util.Optional;
import java.util.Properties;
import java.util.stream.Collectors;

/**
Expand Down Expand Up @@ -67,14 +66,14 @@ private Collection<LocalDataQueryResultRow> buildColumnData(final EncryptTableRu
tableRuleConfig.getName(),
each.getName(),
each.getCipher().getName(),
each.getAssistedQuery().map(EncryptColumnItemRuleConfiguration::getName).orElse(""),
each.getLikeQuery().map(EncryptColumnItemRuleConfiguration::getName).orElse(""),
each.getAssistedQuery().map(EncryptColumnItemRuleConfiguration::getName),
each.getLikeQuery().map(EncryptColumnItemRuleConfiguration::getName),
encryptorAlgorithmConfig.getType(),
encryptorAlgorithmConfig.getProps(),
assistedQueryEncryptorAlgorithmConfig.map(AlgorithmConfiguration::getType).orElse(""),
assistedQueryEncryptorAlgorithmConfig.map(AlgorithmConfiguration::getProps).orElse(new Properties()),
likeQueryEncryptorAlgorithmConfig.map(AlgorithmConfiguration::getType).orElse(""),
likeQueryEncryptorAlgorithmConfig.map(AlgorithmConfiguration::getProps).orElse(new Properties())));
assistedQueryEncryptorAlgorithmConfig.map(AlgorithmConfiguration::getType),
assistedQueryEncryptorAlgorithmConfig.map(AlgorithmConfiguration::getProps),
likeQueryEncryptorAlgorithmConfig.map(AlgorithmConfiguration::getType),
likeQueryEncryptorAlgorithmConfig.map(AlgorithmConfiguration::getProps)));
}
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,17 @@ public static String replaceArg(final String targetValue, final String defaultVa
}

/**
* Get configuration file.
* Get configuration subject.
*
* @param url URL
* @param urlPrefix URL prefix
* @param pathType path type
* @return configuration file
* @param configurationType configuration type
* @return configuration subject
*/
public static String getConfigurationFile(final String url, final String urlPrefix, final String pathType) {
public static String getConfigurationSubject(final String url, final String urlPrefix, final String configurationType) {
String configuredFile = url.substring(urlPrefix.length(), url.contains("?") ? url.indexOf('?') : url.length());
String result = configuredFile.substring(pathType.length());
Preconditions.checkArgument(!result.isEmpty(), "Configuration file is required in ShardingSphere URL.");
String result = configuredFile.substring(configurationType.length());
Preconditions.checkArgument(!result.isEmpty(), "Configuration subject is required in driver URL.");
return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public String getPathType() {
@Override
@SneakyThrows(IOException.class)
public byte[] getContent(final String url, final String urlPrefix) {
String file = ArgsUtils.getConfigurationFile(url, urlPrefix, getPathType());
String file = ArgsUtils.getConfigurationSubject(url, urlPrefix, getPathType());
try (
InputStream stream = Files.newInputStream(new File(file).toPath());
BufferedReader reader = new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public String getPathType() {
@Override
@SneakyThrows(IOException.class)
public byte[] getContent(final String url, final String urlPrefix) {
String file = ArgsUtils.getConfigurationFile(url, urlPrefix, getPathType());
String file = ArgsUtils.getConfigurationSubject(url, urlPrefix, getPathType());
try (
InputStream stream = Files.newInputStream(new File(file).toPath());
BufferedReader reader = new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public String getPathType() {
@Override
@SneakyThrows(IOException.class)
public byte[] getContent(final String url, final String urlPrefix) {
String file = ArgsUtils.getConfigurationFile(url, urlPrefix, getPathType());
String file = ArgsUtils.getConfigurationSubject(url, urlPrefix, getPathType());
try (
InputStream stream = ArgsUtils.getResourceAsStreamFromClasspath(file);
BufferedReader reader = new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public String getPathType() {
@Override
@SneakyThrows(IOException.class)
public byte[] getContent(final String url, final String urlPrefix) {
String file = ArgsUtils.getConfigurationFile(url, urlPrefix, getPathType());
String file = ArgsUtils.getConfigurationSubject(url, urlPrefix, getPathType());
try (
InputStream stream = ArgsUtils.getResourceAsStreamFromClasspath(file);
BufferedReader reader = new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public String getPathType() {
@Override
@SneakyThrows(IOException.class)
public byte[] getContent(final String url, final String urlPrefix) {
String file = ArgsUtils.getConfigurationFile(url, urlPrefix, getPathType());
String file = ArgsUtils.getConfigurationSubject(url, urlPrefix, getPathType());
try (
InputStream stream = ArgsUtils.getResourceAsStreamFromClasspath(file);
BufferedReader reader = new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8))) {
Expand Down

0 comments on commit 78c05da

Please sign in to comment.