From 182a6fd8d1b9458cbc85ed17c2ad29b4762c037c Mon Sep 17 00:00:00 2001 From: Ryan Eberhard Date: Tue, 28 Feb 2023 09:24:09 -0500 Subject: [PATCH] Compensating changes for SnakeYAML 2.0 --- pom.xml | 2 +- .../src/main/java/io/kubernetes/client/util/FilePersister.java | 3 ++- util/src/main/java/io/kubernetes/client/util/KubeConfig.java | 3 ++- util/src/main/java/io/kubernetes/client/util/Yaml.java | 1 + .../io/kubernetes/client/util/generic/dynamic/Dynamics.java | 3 ++- 5 files changed, 8 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index f8d112b863..2d428d3b2b 100644 --- a/pom.xml +++ b/pom.xml @@ -43,8 +43,8 @@ UTF-8 1.3.2 - 1.33 2.0.5 + 2.0 2.9.3 3.21.10 4.13 diff --git a/util/src/main/java/io/kubernetes/client/util/FilePersister.java b/util/src/main/java/io/kubernetes/client/util/FilePersister.java index f4c800268d..4a7a2fa29d 100644 --- a/util/src/main/java/io/kubernetes/client/util/FilePersister.java +++ b/util/src/main/java/io/kubernetes/client/util/FilePersister.java @@ -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; @@ -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(); } diff --git a/util/src/main/java/io/kubernetes/client/util/KubeConfig.java b/util/src/main/java/io/kubernetes/client/util/KubeConfig.java index b5aa94240a..20bfd452a4 100644 --- a/util/src/main/java/io/kubernetes/client/util/KubeConfig.java +++ b/util/src/main/java/io/kubernetes/client/util/KubeConfig.java @@ -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; @@ -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 configMap = (Map) config; diff --git a/util/src/main/java/io/kubernetes/client/util/Yaml.java b/util/src/main/java/io/kubernetes/client/util/Yaml.java index f7f702a55f..d27abfb7cf 100644 --- a/util/src/main/java/io/kubernetes/client/util/Yaml.java +++ b/util/src/main/java/io/kubernetes/client/util/Yaml.java @@ -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()); diff --git a/util/src/main/java/io/kubernetes/client/util/generic/dynamic/Dynamics.java b/util/src/main/java/io/kubernetes/client/util/generic/dynamic/Dynamics.java index f93e05b34f..88b20494e2 100644 --- a/util/src/main/java/io/kubernetes/client/util/generic/dynamic/Dynamics.java +++ b/util/src/main/java/io/kubernetes/client/util/generic/dynamic/Dynamics.java @@ -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);