Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature:added permission configuration support for nacos 1.2 #2367

Merged
merged 16 commits into from Mar 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion bom/pom.xml
Expand Up @@ -86,7 +86,7 @@
<redis-clients.version>2.9.0</redis-clients.version>
<eureka-clients.version>1.9.5</eureka-clients.version>
<consul-clients.version>1.4.2</consul-clients.version>
<nacos-client.version>1.0.0</nacos-client.version>
<nacos-client.version>1.2.0</nacos-client.version>
<etcd-client-v3.version>0.3.0</etcd-client-v3.version>
<testcontainers.version>1.11.2</testcontainers.version>
<guava.version>27.0.1-jre</guava.version>
Expand Down
Expand Up @@ -26,6 +26,7 @@
import com.alibaba.nacos.api.exception.NacosException;

import io.seata.common.exception.NotSupportYetException;
import io.seata.common.util.StringUtils;
import io.seata.config.AbstractConfiguration;
import io.seata.config.Configuration;
import io.seata.config.ConfigurationChangeEvent;
Expand All @@ -50,6 +51,8 @@ public class NacosConfiguration extends AbstractConfiguration {
private static final String CONFIG_TYPE = "nacos";
private static final String DEFAULT_NAMESPACE = "";
private static final String PRO_NAMESPACE_KEY = "namespace";
private static final String USER_NAME = "username";
private static final String PASSWORD = "password";
private static final Configuration FILE_CONFIG = ConfigurationFactory.CURRENT_FILE_INSTANCE;
private static volatile ConfigService configService;
private static final int MAP_INITIAL_CAPACITY = 8;
Expand Down Expand Up @@ -191,6 +194,16 @@ private static Properties getConfigProperties() {
}
properties.setProperty(PRO_NAMESPACE_KEY, namespace);
}
String userName = StringUtils.isNotBlank(System.getProperty(USER_NAME)) ? System.getProperty(USER_NAME)
: FILE_CONFIG.getConfig(getNacosUserName());
if (StringUtils.isNotBlank(userName)) {
String password = StringUtils.isNotBlank(System.getProperty(PASSWORD)) ? System.getProperty(PASSWORD)
: FILE_CONFIG.getConfig(getNacosPassword());
if (StringUtils.isNotBlank(password)) {
properties.setProperty(USER_NAME, userName);
properties.setProperty(PASSWORD, password);
}
}
return properties;
}

Expand All @@ -206,6 +219,16 @@ private static String getNacosGroupKey() {
return String.join(ConfigurationKeys.FILE_CONFIG_SPLIT_CHAR, ConfigurationKeys.FILE_ROOT_CONFIG, CONFIG_TYPE, GROUP_KEY);
}

private static String getNacosUserName() {
return String.join(ConfigurationKeys.FILE_CONFIG_SPLIT_CHAR, ConfigurationKeys.FILE_ROOT_CONFIG, CONFIG_TYPE,
USER_NAME);
}

private static String getNacosPassword() {
return String.join(ConfigurationKeys.FILE_CONFIG_SPLIT_CHAR, ConfigurationKeys.FILE_ROOT_CONFIG, CONFIG_TYPE,
PASSWORD);
}

private static String getNacosGroup() {
return FILE_CONFIG.getConfig(getNacosGroupKey(), DEFAULT_GROUP);
}
Expand Down
Expand Up @@ -30,6 +30,7 @@
import com.alibaba.nacos.api.naming.pojo.Instance;
import com.alibaba.nacos.client.naming.utils.CollectionUtils;

import io.seata.common.util.StringUtils;
import io.seata.config.Configuration;
import io.seata.config.ConfigurationFactory;
import io.seata.config.ConfigurationKeys;
Expand All @@ -47,6 +48,8 @@ public class NacosRegistryServiceImpl implements RegistryService<EventListener>
private static final String PRO_NAMESPACE_KEY = "namespace";
private static final String REGISTRY_TYPE = "nacos";
private static final String REGISTRY_CLUSTER = "cluster";
private static final String USER_NAME = "username";
private static final String PASSWORD = "password";
private static final Configuration FILE_CONFIG = ConfigurationFactory.CURRENT_FILE_INSTANCE;
private static volatile NamingService naming;
private static final ConcurrentMap<String, List<EventListener>> LISTENER_SERVICE_MAP = new ConcurrentHashMap<>();
Expand Down Expand Up @@ -192,6 +195,16 @@ private static Properties getNamingProperties() {
}
properties.setProperty(PRO_NAMESPACE_KEY, namespace);
}
String userName = StringUtils.isNotBlank(System.getProperty(USER_NAME)) ? System.getProperty(USER_NAME)
: FILE_CONFIG.getConfig(getNacosUserName());
if (StringUtils.isNotBlank(userName)) {
String password = StringUtils.isNotBlank(System.getProperty(PASSWORD)) ? System.getProperty(PASSWORD)
: FILE_CONFIG.getConfig(getNacosPassword());
if (StringUtils.isNotBlank(password)) {
properties.setProperty(USER_NAME, userName);
properties.setProperty(PASSWORD, password);
}
}
return properties;
}

Expand All @@ -214,4 +227,14 @@ private static String getNacosNameSpaceFileKey() {
private static String getNacosClusterFileKey() {
return String.join(ConfigurationKeys.FILE_CONFIG_SPLIT_CHAR, ConfigurationKeys.FILE_ROOT_REGISTRY, REGISTRY_TYPE, REGISTRY_CLUSTER);
}

private static String getNacosUserName() {
return String.join(ConfigurationKeys.FILE_CONFIG_SPLIT_CHAR, ConfigurationKeys.FILE_ROOT_CONFIG, REGISTRY_TYPE,
USER_NAME);
}

private static String getNacosPassword() {
return String.join(ConfigurationKeys.FILE_CONFIG_SPLIT_CHAR, ConfigurationKeys.FILE_ROOT_CONFIG, REGISTRY_TYPE,
PASSWORD);
}
}
4 changes: 4 additions & 0 deletions script/client/conf/registry.conf
Expand Up @@ -5,6 +5,8 @@ registry {
nacos {
serverAddr = "localhost"
namespace = ""
username = ""
password = ""
}
eureka {
serviceUrl = "http://localhost:8761/eureka"
Expand Down Expand Up @@ -49,6 +51,8 @@ config {
serverAddr = "localhost"
namespace = ""
group = "SEATA_GROUP"
username = ""
password = ""
}
consul {
serverAddr = "127.0.0.1:8500"
Expand Down
4 changes: 4 additions & 0 deletions script/client/spring/application.properties
Expand Up @@ -66,6 +66,8 @@ seata.config.etcd3.server-addr=http://localhost:2379
seata.config.nacos.namespace=
seata.config.nacos.serverAddr=localhost
seata.config.nacos.group=SEATA_GROUP
seata.config.nacos.username=
seata.config.nacos.password=

seata.config.zk.server-addr=127.0.0.1:2181
seata.config.zk.session-timeout=6000
Expand All @@ -84,6 +86,8 @@ seata.registry.eureka.service-url=http://localhost:8761/eureka

seata.registry.nacos.server-addr=localhost
seata.registry.nacos.namespace=
seata.registry.nacos.username=
seata.registry.nacos.password=

seata.registry.redis.server-addr=localhost:6379
seata.registry.redis.db=0
Expand Down
4 changes: 4 additions & 0 deletions script/client/spring/application.yml
Expand Up @@ -63,6 +63,8 @@ seata:
namespace:
serverAddr: localhost
group: SEATA_GROUP
userName: ""
password: ""
zk:
server-addr: 127.0.0.1:2181
session-timeout: 6000
Expand All @@ -81,6 +83,8 @@ seata:
nacos:
server-addr: localhost
namespace:
userName: ""
password: ""
redis:
server-addr: localhost:6379
db: 0
Expand Down
Expand Up @@ -29,6 +29,8 @@ public class ConfigNacosProperties {
private String serverAddr = "localhost";
private String namespace = "";
private String group = "SEATA_GROUP";
private String username = "";
private String password = "";

public String getServerAddr() {
return serverAddr;
Expand Down Expand Up @@ -56,4 +58,22 @@ public ConfigNacosProperties setGroup(String group) {
this.group = group;
return this;
}

public String getUsername() {
return username;
}

public ConfigNacosProperties setUsername(String username) {
this.username = username;
return this;
}

public String getPassword() {
return password;
}

public ConfigNacosProperties setPassword(String password) {
this.password = password;
return this;
}
}
Expand Up @@ -29,6 +29,8 @@ public class RegistryNacosProperties {
private String serverAddr = "localhost";
private String namespace = "";
private String cluster = "default";
private String username = "";
private String password = "";

public String getServerAddr() {
return serverAddr;
Expand Down Expand Up @@ -56,4 +58,21 @@ public RegistryNacosProperties setCluster(String cluster) {
this.cluster = cluster;
return this;
}
public String getUsername() {
return username;
}

public RegistryNacosProperties setUsername(String username) {
this.username = username;
return this;
}

public String getPassword() {
return password;
}

public RegistryNacosProperties setPassword(String password) {
this.password = password;
return this;
}
}
4 changes: 4 additions & 0 deletions server/src/main/resources/registry.conf
Expand Up @@ -6,6 +6,8 @@ registry {
serverAddr = "localhost"
namespace = ""
cluster = "default"
username = ""
password = ""
}
eureka {
serviceUrl = "http://localhost:8761/eureka"
Expand Down Expand Up @@ -54,6 +56,8 @@ config {
serverAddr = "localhost"
namespace = ""
group = "SEATA_GROUP"
username = ""
password = ""
}
consul {
serverAddr = "127.0.0.1:8500"
Expand Down