Fix: make kubernetes token string optional for ApiConfig
Change-Id: I679944fb5df3ed71a8af7c12a92aec3c4e36bee6
diff --git a/apps/k8s-node/api/src/main/java/org/onosproject/k8snode/api/DefaultK8sApiConfig.java b/apps/k8s-node/api/src/main/java/org/onosproject/k8snode/api/DefaultK8sApiConfig.java
index 48f6b13..dc8d030 100644
--- a/apps/k8s-node/api/src/main/java/org/onosproject/k8snode/api/DefaultK8sApiConfig.java
+++ b/apps/k8s-node/api/src/main/java/org/onosproject/k8snode/api/DefaultK8sApiConfig.java
@@ -172,7 +172,6 @@
checkArgument(state != null, NOT_NULL_MSG, "state");
if (scheme == HTTPS) {
- checkArgument(token != null, NOT_NULL_MSG, "token");
checkArgument(caCertData != null, NOT_NULL_MSG, "caCertData");
checkArgument(clientCertData != null, NOT_NULL_MSG, "clientCertData");
checkArgument(clientKeyData != null, NOT_NULL_MSG, "clientKeyData");
diff --git a/apps/k8s-node/app/src/main/java/org/onosproject/k8snode/codec/K8sApiConfigCodec.java b/apps/k8s-node/app/src/main/java/org/onosproject/k8snode/codec/K8sApiConfigCodec.java
index a65f47d..b7da2a0 100644
--- a/apps/k8s-node/app/src/main/java/org/onosproject/k8snode/codec/K8sApiConfigCodec.java
+++ b/apps/k8s-node/app/src/main/java/org/onosproject/k8snode/codec/K8sApiConfigCodec.java
@@ -17,6 +17,7 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
+import org.apache.commons.lang.StringUtils;
import org.onlab.packet.IpAddress;
import org.onosproject.codec.CodecContext;
import org.onosproject.codec.JsonCodec;
@@ -53,10 +54,14 @@
.put(STATE, entity.state().name());
if (entity.scheme() == HTTPS) {
- node.put(TOKEN, entity.token())
- .put(CA_CERT_DATA, entity.caCertData())
+ node.put(CA_CERT_DATA, entity.caCertData())
.put(CLIENT_CERT_DATA, entity.clientCertData())
.put(CLIENT_KEY_DATA, entity.clientKeyData());
+
+ if (entity.token() != null) {
+ node.put(TOKEN, entity.token());
+ }
+
} else {
if (entity.token() != null) {
node.put(TOKEN, entity.token());
@@ -107,8 +112,6 @@
String clientKeyData = "";
if (scheme == HTTPS) {
- token = nullIsIllegal(tokenJson.asText(),
- TOKEN + MISSING_MESSAGE);
caCertData = nullIsIllegal(caCertDataJson.asText(),
CA_CERT_DATA + MISSING_MESSAGE);
clientCertData = nullIsIllegal(clientCertDataJson.asText(),
@@ -116,6 +119,10 @@
clientKeyData = nullIsIllegal(clientKeyDataJson.asText(),
CLIENT_KEY_DATA + MISSING_MESSAGE);
+ if (tokenJson != null) {
+ token = tokenJson.asText();
+ }
+
} else {
if (tokenJson != null) {
token = tokenJson.asText();
@@ -134,10 +141,22 @@
}
}
- return builder.token(token)
- .caCertData(caCertData)
- .clientCertData(clientCertData)
- .clientKeyData(clientKeyData)
- .build();
+ if (StringUtils.isNotEmpty(token)) {
+ builder.token(token);
+ }
+
+ if (StringUtils.isNotEmpty(caCertData)) {
+ builder.caCertData(caCertData);
+ }
+
+ if (StringUtils.isNotEmpty(clientCertData)) {
+ builder.clientCertData(clientCertData);
+ }
+
+ if (StringUtils.isNotEmpty(clientKeyData)) {
+ builder.clientKeyData(clientKeyData);
+ }
+
+ return builder.build();
}
}
diff --git a/apps/k8s-node/app/src/main/java/org/onosproject/k8snode/util/K8sNodeUtil.java b/apps/k8s-node/app/src/main/java/org/onosproject/k8snode/util/K8sNodeUtil.java
index 023cec9..bf76feb 100644
--- a/apps/k8s-node/app/src/main/java/org/onosproject/k8snode/util/K8sNodeUtil.java
+++ b/apps/k8s-node/app/src/main/java/org/onosproject/k8snode/util/K8sNodeUtil.java
@@ -248,10 +248,13 @@
if (config.scheme() == K8sApiConfig.Scheme.HTTPS) {
configBuilder.withTrustCerts(true)
- .withOauthToken(config.token())
.withCaCertData(config.caCertData())
.withClientCertData(config.clientCertData())
.withClientKeyData(config.clientKeyData());
+
+ if (StringUtils.isNotEmpty(config.token())) {
+ configBuilder.withOauthToken(config.token());
+ }
}
return new DefaultKubernetesClient(configBuilder.build());