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

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


The following commit(s) were added to refs/heads/master by this push:
     new e26409de3dd Support Nacos authentication (#27328)
e26409de3dd is described below

commit e26409de3dd917d078530539c121119ea7e0fd39
Author: niu niu <[email protected]>
AuthorDate: Mon Jul 24 17:47:51 2023 +0800

    Support Nacos authentication (#27328)
    
    * Support Nacos authentication
    
    * Add nacos properties test
---
 .../mode/repository/cluster/nacos/NacosRepository.java       |  2 ++
 .../repository/cluster/nacos/props/NacosPropertyKey.java     | 12 +++++++++++-
 .../repository/cluster/nacos/props/NacosPropertiesTest.java  |  8 +++++++-
 3 files changed, 20 insertions(+), 2 deletions(-)

diff --git 
a/mode/type/cluster/repository/provider/nacos/src/main/java/org/apache/shardingsphere/mode/repository/cluster/nacos/NacosRepository.java
 
b/mode/type/cluster/repository/provider/nacos/src/main/java/org/apache/shardingsphere/mode/repository/cluster/nacos/NacosRepository.java
index 7011fc71052..0426110681b 100644
--- 
a/mode/type/cluster/repository/provider/nacos/src/main/java/org/apache/shardingsphere/mode/repository/cluster/nacos/NacosRepository.java
+++ 
b/mode/type/cluster/repository/provider/nacos/src/main/java/org/apache/shardingsphere/mode/repository/cluster/nacos/NacosRepository.java
@@ -81,6 +81,8 @@ public final class NacosRepository implements 
ClusterPersistRepository {
         Properties props = new Properties();
         props.setProperty("serverAddr", config.getServerLists());
         props.setProperty("namespace", config.getNamespace());
+        props.setProperty("username", 
nacosProps.getValue(NacosPropertyKey.USERNAME));
+        props.setProperty("password", 
nacosProps.getValue(NacosPropertyKey.PASSWORD));
         try {
             return NamingFactory.createNamingService(props);
         } catch (final NacosException ex) {
diff --git 
a/mode/type/cluster/repository/provider/nacos/src/main/java/org/apache/shardingsphere/mode/repository/cluster/nacos/props/NacosPropertyKey.java
 
b/mode/type/cluster/repository/provider/nacos/src/main/java/org/apache/shardingsphere/mode/repository/cluster/nacos/props/NacosPropertyKey.java
index f0e310c9ab5..6d9e1f24c6b 100644
--- 
a/mode/type/cluster/repository/provider/nacos/src/main/java/org/apache/shardingsphere/mode/repository/cluster/nacos/props/NacosPropertyKey.java
+++ 
b/mode/type/cluster/repository/provider/nacos/src/main/java/org/apache/shardingsphere/mode/repository/cluster/nacos/props/NacosPropertyKey.java
@@ -46,7 +46,17 @@ public enum NacosPropertyKey implements TypedPropertyKey {
     /**
      * Time to live seconds.
      */
-    TIME_TO_LIVE_SECONDS("timeToLiveSeconds", String.valueOf(30), int.class);
+    TIME_TO_LIVE_SECONDS("timeToLiveSeconds", String.valueOf(30), int.class),
+    
+    /**
+     * Username.
+     */
+    USERNAME("username", "", String.class),
+    
+    /**
+     * Password.
+     */
+    PASSWORD("password", "", String.class);
     
     private final String key;
     
diff --git 
a/mode/type/cluster/repository/provider/nacos/src/test/java/org/apache/shardingsphere/mode/repository/cluster/nacos/props/NacosPropertiesTest.java
 
b/mode/type/cluster/repository/provider/nacos/src/test/java/org/apache/shardingsphere/mode/repository/cluster/nacos/props/NacosPropertiesTest.java
index 17cad973a9d..7e04a0810d3 100644
--- 
a/mode/type/cluster/repository/provider/nacos/src/test/java/org/apache/shardingsphere/mode/repository/cluster/nacos/props/NacosPropertiesTest.java
+++ 
b/mode/type/cluster/repository/provider/nacos/src/test/java/org/apache/shardingsphere/mode/repository/cluster/nacos/props/NacosPropertiesTest.java
@@ -35,6 +35,8 @@ class NacosPropertiesTest {
         
assertThat(actual.getValue(NacosPropertyKey.RETRY_INTERVAL_MILLISECONDS), 
is(1000L));
         assertThat(actual.getValue(NacosPropertyKey.MAX_RETRIES), is(5));
         assertThat(actual.getValue(NacosPropertyKey.TIME_TO_LIVE_SECONDS), 
is(60));
+        assertThat(actual.getValue(NacosPropertyKey.USERNAME), is("nacos"));
+        assertThat(actual.getValue(NacosPropertyKey.PASSWORD), is("nacos"));
     }
     
     private Properties createProperties() {
@@ -42,7 +44,9 @@ class NacosPropertiesTest {
                 new Property(NacosPropertyKey.CLUSTER_IP.getKey(), 
"127.0.0.1"),
                 new 
Property(NacosPropertyKey.RETRY_INTERVAL_MILLISECONDS.getKey(), "1000"),
                 new Property(NacosPropertyKey.MAX_RETRIES.getKey(), "5"),
-                new Property(NacosPropertyKey.TIME_TO_LIVE_SECONDS.getKey(), 
"60"));
+                new Property(NacosPropertyKey.TIME_TO_LIVE_SECONDS.getKey(), 
"60"),
+                new Property(NacosPropertyKey.USERNAME.getKey(), "nacos"),
+                new Property(NacosPropertyKey.PASSWORD.getKey(), "nacos"));
     }
     
     @Test
@@ -52,5 +56,7 @@ class NacosPropertiesTest {
         
assertThat(actual.getValue(NacosPropertyKey.RETRY_INTERVAL_MILLISECONDS), 
is(500L));
         assertThat(actual.getValue(NacosPropertyKey.MAX_RETRIES), is(3));
         assertThat(actual.getValue(NacosPropertyKey.TIME_TO_LIVE_SECONDS), 
is(30));
+        assertThat(actual.getValue(NacosPropertyKey.USERNAME), is(""));
+        assertThat(actual.getValue(NacosPropertyKey.PASSWORD), is(""));
     }
 }

Reply via email to