Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/github_actions/actions/labeler-5
Browse files Browse the repository at this point in the history
  • Loading branch information
pmendelski authored Apr 10, 2024
2 parents 157635f + 8bfa27a commit ddc18e3
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 18 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
A configuration library,
similar to the one created in [Spring Boot](https://docs.spring.io/spring-boot/docs/current/reference/html/spring-boot-features.html#boot-features-external-config)
of [typesafe](https://github.com/lightbend/config), that is:
- lightweight, without a burden of a framework (has exactly two dependencies gson and yamlsnake)
- lightweight, without a burden of a framework (has exactly two dependencies gson and snakeyaml)
- loads configuration from multiple sources: arguments, classpath, file system
- supports multiple formats YAML, JSON, properties
- provides a collection of parsers for values such as `java.util.Duration`
Expand Down
1 change: 0 additions & 1 deletion build-logic/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
rootProject.name = "build-logic"

dependencyResolutionManagement {
@Suppress("UnstableApiUsage")
versionCatalogs {
create("libs") {
from(files("../gradle/libs.versions.toml"))
Expand Down
6 changes: 3 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
[versions]
# build tools
java = "17"
java = "21"
jacoco = "0.8.11"

[libraries]
# build tools
gradle-nexus-publish = { module = "io.github.gradle-nexus:publish-plugin", version = "1.1.0" }
# dependencies
jetbrains-annotations = { module = "org.jetbrains:annotations", version = "24.1.0" }
snakeyaml = { module = "org.yaml:snakeyaml", version = "2.2" }
snakeyaml = { module = "org.snakeyaml:snakeyaml-engine", version = "2.7" }
gson = { module = "com.google.code.gson:gson", version = "2.10.1" }
# test dependencies
spock-core = { module = "org.spockframework:spock-core", version = "2.4-M1-groovy-4.0" }
spock-core = { module = "org.spockframework:spock-core", version = "2.4-M4-groovy-4.0" }
jsonassert = { module = "org.skyscreamer:jsonassert", version = "1.5.1" }
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-all.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
27 changes: 17 additions & 10 deletions src/main/java/com/coditory/quark/config/ConfigFormat.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import org.yaml.snakeyaml.DumperOptions;
import org.yaml.snakeyaml.Yaml;
import org.snakeyaml.engine.v2.api.DumpSettings;
import org.snakeyaml.engine.v2.api.Load;
import org.snakeyaml.engine.v2.api.LoadSettings;
import org.snakeyaml.engine.v2.api.Dump;
import org.snakeyaml.engine.v2.common.FlowStyle;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
Expand Down Expand Up @@ -84,26 +87,30 @@ private interface ConfigFormatParser {
}

private static class YamlConfigParser implements ConfigFormatParser {
@SuppressWarnings("unchecked")
@Override
public Config parse(String config) {
Yaml yaml = new Yaml();
Map<String, Object> map = yaml.load(config);
LoadSettings settings = LoadSettings.builder().build();
Load yaml = new Load(settings);
Map<String, Object> map = (Map<String, Object>) yaml.loadFromString(config);
return Config.of(map);
}

@SuppressWarnings("unchecked")
@Override
public Config parse(InputStream config) {
Yaml yaml = new Yaml();
Map<String, Object> map = yaml.load(config);
LoadSettings settings = LoadSettings.builder().build();
Load yaml = new Load(settings);
Map<String, Object> map = (Map<String, Object>) yaml.loadFromInputStream(config);
return Config.of(map);
}

@Override
public String stringify(Config config) {
DumperOptions options = new DumperOptions();
options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
Yaml yaml = new Yaml(options);
return yaml.dump(config.toMap());
DumpSettings settings = DumpSettings.builder().setDefaultFlowStyle(FlowStyle.BLOCK).build();
Dump dump = new Dump(settings);
dump.dumpToString(config.toMap());
return dump.dumpToString(config.toMap());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ public class SecretHidingValueMapper implements ConfigEntryMapper {
private static final Set<String> DEFAULT_SECRET_NAMES = Set.of(
"password", "passwords",
"secret", "secrets",
"token", "tokens"
"token", "tokens",
"key", "keys",
"apiKey", "apiKeys"
);

private static final SecretHidingValueMapper DEFAULT_SECRET_HIDING_VALUE_MAPPER =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class HideSecretValuesSpec extends Specification {
]
where:
field << [
"secret", "secrets", "password", "passwords", "token", "tokens"
"secret", "secrets", "password", "passwords", "token", "tokens", "key", "keys", "apiKey", "apiKeys"
]
}

Expand Down

0 comments on commit ddc18e3

Please sign in to comment.