use of org.apache.shenyu.admin.config.properties.NacosProperties in project incubator-shenyu by apache.
the class NacosPropertiesTest method testNacosPropertiesDefault.
@Test
public void testNacosPropertiesDefault() {
load(NacosPropertiesTest.NacosPropertiesConfiguration.class);
NacosProperties nacosProperties = getContext().getBean(NacosProperties.class);
assertNull(nacosProperties.getUrl());
assertNull(nacosProperties.getNamespace());
assertNull(nacosProperties.getAcm());
}
use of org.apache.shenyu.admin.config.properties.NacosProperties in project incubator-shenyu by apache.
the class NacosPropertiesTest method testNacosPropertiesSpecified.
@Test
public void testNacosPropertiesSpecified() {
final String url = "localhost:8848";
final String namespace = "1c10d748-af86-43b9-8265-75f487d20c6c";
NacosProperties.NacosACMProperties acm = new NacosProperties.NacosACMProperties();
acm.setEnabled(false);
acm.setEndpoint("acm.aliyun.com");
load(NacosPropertiesTest.NacosPropertiesConfiguration.class, "shenyu.sync.nacos.url=localhost:8848", "shenyu.sync.nacos.namespace=1c10d748-af86-43b9-8265-75f487d20c6c", "shenyu.sync.nacos.acm.enabled=false", "shenyu.sync.nacos.acm.endpoint=acm.aliyun.com");
NacosProperties nacosProperties = getContext().getBean(NacosProperties.class);
assertEquals(nacosProperties.getUrl(), url);
assertEquals(nacosProperties.getNamespace(), namespace);
assertEquals(nacosProperties.getAcm().isEnabled(), acm.isEnabled());
assertEquals(nacosProperties.getAcm().getEndpoint(), acm.getEndpoint());
}
use of org.apache.shenyu.admin.config.properties.NacosProperties in project incubator-shenyu by apache.
the class NacosConfiguration method nacosConfigService.
/**
* register configService in spring ioc.
*
* @param nacosProp the nacos configuration
* @return ConfigService {@linkplain ConfigService}
* @throws Exception the exception
*/
@Bean
@ConditionalOnMissingBean(ConfigService.class)
public ConfigService nacosConfigService(final NacosProperties nacosProp) throws Exception {
Properties properties = new Properties();
if (nacosProp.getAcm() != null && nacosProp.getAcm().isEnabled()) {
// Use aliyun ACM service
properties.put(PropertyKeyConst.ENDPOINT, nacosProp.getAcm().getEndpoint());
properties.put(PropertyKeyConst.NAMESPACE, nacosProp.getAcm().getNamespace());
// Use subaccount ACM administrative authority
properties.put(PropertyKeyConst.ACCESS_KEY, nacosProp.getAcm().getAccessKey());
properties.put(PropertyKeyConst.SECRET_KEY, nacosProp.getAcm().getSecretKey());
} else {
properties.put(PropertyKeyConst.SERVER_ADDR, nacosProp.getUrl());
if (StringUtils.isNotBlank(nacosProp.getNamespace())) {
properties.put(PropertyKeyConst.NAMESPACE, nacosProp.getNamespace());
}
if (StringUtils.isNotBlank(nacosProp.getUsername())) {
properties.put(PropertyKeyConst.USERNAME, nacosProp.getUsername());
}
if (StringUtils.isNotBlank(nacosProp.getPassword())) {
properties.put(PropertyKeyConst.PASSWORD, nacosProp.getPassword());
}
}
return NacosFactory.createConfigService(properties);
}
Aggregations