This is an automated email from the ASF dual-hosted git repository.

liuhongyu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shenyu.git


The following commit(s) were added to refs/heads/master by this push:
     new 268149226e [type:refactor] Optimize code for 
shenyu-spring-boot-starter (#5873)
268149226e is described below

commit 268149226e49813fc0c354b5829adc5c2541c3ab
Author: po-168 <[email protected]>
AuthorDate: Tue Feb 11 18:27:39 2025 +0800

    [type:refactor] Optimize code for shenyu-spring-boot-starter (#5873)
    
    Co-authored-by: aias00 <[email protected]>
---
 .../common/config/ShenyuClientCommonBeanConfiguration.java   |  2 +-
 .../starter/netty/ShenyuNettyWebServerConfiguration.java     |  6 ++++--
 .../starter/k8s/IngressControllerConfiguration.java          | 12 ++++++++----
 3 files changed, 13 insertions(+), 7 deletions(-)

diff --git 
a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-client/shenyu-spring-boot-starter-client-common/src/main/java/org/apache/shenyu/springboot/starter/client/common/config/ShenyuClientCommonBeanConfiguration.java
 
b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-client/shenyu-spring-boot-starter-client-common/src/main/java/org/apache/shenyu/springboot/starter/client/common/config/ShenyuClientCommonBeanConfiguration.java
index b16a9b8e96..948d75af5f 100644
--- 
a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-client/shenyu-spring-boot-starter-client-common/src/main/java/org/apache/shenyu/springboot/starter/client/common/config/ShenyuClientCommonBeanConfiguration.java
+++ 
b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-client/shenyu-spring-boot-starter-client-common/src/main/java/org/apache/shenyu/springboot/starter/client/common/config/ShenyuClientCommonBeanConfiguration.java
@@ -73,7 +73,7 @@ public class ShenyuClientCommonBeanConfiguration {
      * @return the shenyu discovery config
      */
     @Bean
-    @ConditionalOnProperty(prefix = "shenyu.discovery", name = "enable", 
matchIfMissing = false, havingValue = "true")
+    @ConditionalOnProperty(prefix = "shenyu.discovery", name = "enable", 
havingValue = "true")
     @ConfigurationProperties(prefix = "shenyu.discovery")
     public ShenyuDiscoveryConfig shenyuDiscoveryConfig() {
         return new ShenyuDiscoveryConfig();
diff --git 
a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-gateway/src/main/java/org/apache/shenyu/springboot/starter/netty/ShenyuNettyWebServerConfiguration.java
 
b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-gateway/src/main/java/org/apache/shenyu/springboot/starter/netty/ShenyuNettyWebServerConfiguration.java
index 09b88531a1..775ddb40c1 100644
--- 
a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-gateway/src/main/java/org/apache/shenyu/springboot/starter/netty/ShenyuNettyWebServerConfiguration.java
+++ 
b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-gateway/src/main/java/org/apache/shenyu/springboot/starter/netty/ShenyuNettyWebServerConfiguration.java
@@ -19,6 +19,7 @@ package org.apache.shenyu.springboot.starter.netty;
 
 import io.netty.channel.ChannelOption;
 import io.netty.channel.WriteBufferWaterMark;
+import org.apache.commons.collections4.CollectionUtils;
 import org.apache.shenyu.common.config.NettyHttpProperties;
 import org.apache.shenyu.common.exception.ShenyuException;
 import org.apache.shenyu.common.config.ssl.ShenyuSniAsyncMapping;
@@ -99,12 +100,13 @@ public class ShenyuNettyWebServerConfiguration {
                     throw new ShenyuException("Can not find 
shenyuSniAsyncMapping bean");
                 }
                 if ("manual".equals(sniProperties.getMod())) {
-                    if (Objects.isNull(sniProperties.getCertificates()) || 
sniProperties.getCertificates().isEmpty()) {
+                    List<SslCrtAndKeyFile> sslCrtAndKeyFiles = 
sniProperties.getCertificates();
+                    if (CollectionUtils.isEmpty(sslCrtAndKeyFiles)) {
                         throw new ShenyuException("At least one certificate is 
required");
                     }
 
                     // Use the first certificate as the default certificate 
(this default certificate will not actually be used)
-                    List<SslCrtAndKeyFile> certificates = 
sniProperties.getCertificates();
+                    List<SslCrtAndKeyFile> certificates = sslCrtAndKeyFiles;
                     for (SslCrtAndKeyFile certificate : certificates) {
                         try {
                             
shenyuSniAsyncMapping.addSslCertificate(certificate);
diff --git 
a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-k8s/src/main/java/org/apache/shenyu/springboot/starter/k8s/IngressControllerConfiguration.java
 
b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-k8s/src/main/java/org/apache/shenyu/springboot/starter/k8s/IngressControllerConfiguration.java
index d745b89f4d..0a6ad99abd 100644
--- 
a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-k8s/src/main/java/org/apache/shenyu/springboot/starter/k8s/IngressControllerConfiguration.java
+++ 
b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-k8s/src/main/java/org/apache/shenyu/springboot/starter/k8s/IngressControllerConfiguration.java
@@ -35,6 +35,7 @@ import io.kubernetes.client.openapi.models.V1SecretList;
 import io.kubernetes.client.openapi.models.V1Service;
 import io.kubernetes.client.openapi.models.V1ServiceList;
 import io.kubernetes.client.util.generic.GenericKubernetesApi;
+import org.apache.commons.collections4.MapUtils;
 import org.apache.shenyu.common.config.NettyHttpProperties;
 import org.apache.shenyu.common.config.ssl.ShenyuSniAsyncMapping;
 import org.apache.shenyu.common.exception.ShenyuException;
@@ -55,6 +56,8 @@ import reactor.netty.tcp.TcpSslContextSpec;
 import java.io.ByteArrayInputStream;
 import java.io.InputStream;
 import java.time.Duration;
+
+import java.util.Map;
 import java.util.Objects;
 import java.util.Optional;
 import java.util.concurrent.Executors;
@@ -97,7 +100,6 @@ public class IngressControllerConfiguration {
                                 .build());
         // TODO support config in application.yaml
         builder.withWorkerCount(2);
-//        builder.withReadyFunc(ingressReconciler::informerReady);
         return 
builder.withReconciler(ingressReconciler).withName("ingressController").build();
     }
 
@@ -260,9 +262,11 @@ public class IngressControllerConfiguration {
             String defaultNamespace = 
Optional.ofNullable(sniProperties.getDefaultK8sSecretNamespace()).orElse("default");
             CoreV1Api coreV1Api = new CoreV1Api(apiClient);
             V1Secret secret = coreV1Api.readNamespacedSecret(defaultName, 
defaultNamespace, "true");
-            if (Objects.nonNull(secret.getData())) {
-                InputStream crtStream = new 
ByteArrayInputStream(secret.getData().get("tls.crt"));
-                InputStream keyStream = new 
ByteArrayInputStream(secret.getData().get("tls.key"));
+
+            Map<String, byte[]> secretData = secret.getData();
+            if (MapUtils.isEmpty(secretData)) {
+                InputStream crtStream = new 
ByteArrayInputStream(secretData.get("tls.crt"));
+                InputStream keyStream = new 
ByteArrayInputStream(secretData.get("tls.key"));
                 return TcpSslContextSpec.forServer(crtStream, keyStream);
             } else {
                 throw new ShenyuException(String.format("Can not read cert and 
key from default secret %s/%s", defaultNamespace, defaultName));

Reply via email to