Skip to content

Commit

Permalink
Compensating changes for SnakeYAML 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
rjeberhard authored and ryanjbaxter committed Mar 30, 2023
1 parent eac8035 commit 182a6fd
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<javax.annotation.version>1.3.2</javax.annotation.version>
<snakeyaml.version>1.33</snakeyaml.version>
<slf4j.version>2.0.5</slf4j.version>
<snakeyaml.version>2.0</snakeyaml.version>
<caffeine.version>2.9.3</caffeine.version>
<protobuf.version>3.21.10</protobuf.version>
<junit.version>4.13</junit.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import org.yaml.snakeyaml.LoaderOptions;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.constructor.SafeConstructor;

Expand Down Expand Up @@ -51,7 +52,7 @@ public void save(
// Note this is imperfect, should protect against other processes writing this file too...
synchronized (configFile) {
try (FileWriter fw = new FileWriter(configFile)) {
Yaml yaml = new Yaml(new SafeConstructor());
Yaml yaml = new Yaml(new SafeConstructor(new LoaderOptions()));
yaml.dump(config, fw);
fw.flush();
}
Expand Down
3 changes: 2 additions & 1 deletion util/src/main/java/io/kubernetes/client/util/KubeConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.apache.commons.codec.binary.Base64;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.yaml.snakeyaml.LoaderOptions;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.constructor.SafeConstructor;

Expand Down Expand Up @@ -83,7 +84,7 @@ public static void registerAuthenticator(Authenticator auth) {

/** Load a Kubernetes config from a Reader */
public static KubeConfig loadKubeConfig(Reader input) {
Yaml yaml = new Yaml(new SafeConstructor());
Yaml yaml = new Yaml(new SafeConstructor(new LoaderOptions()));
Object config = yaml.load(input);
Map<String, Object> configMap = (Map<String, Object>) config;

Expand Down
1 change: 1 addition & 0 deletions util/src/main/java/io/kubernetes/client/util/Yaml.java
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ private Object constructDateTime(ScalarNode node) {

public static class CustomRepresenter extends Representer {
public CustomRepresenter() {
super(new DumperOptions());
this.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
this.representers.put(IntOrString.class, new RepresentIntOrString());
this.representers.put(byte[].class, new RepresentByteArray());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@
import com.google.gson.JsonElement;
import io.kubernetes.client.openapi.JSON;
import java.util.Map;
import org.yaml.snakeyaml.LoaderOptions;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.constructor.SafeConstructor;

public class Dynamics {

static final JSON internalJSONCodec = new JSON();
static final Yaml internalYamlCodec = new Yaml(new SafeConstructor());
static final Yaml internalYamlCodec = new Yaml(new SafeConstructor(new LoaderOptions()));

public static DynamicKubernetesObject newFromJson(String jsonContent) {
return newFromJson(internalJSONCodec.getGson(), jsonContent);
Expand Down

0 comments on commit 182a6fd

Please sign in to comment.