Search in sources :

Example 1 with NacosProperties

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());
}
Also used : NacosProperties(org.apache.shenyu.admin.config.properties.NacosProperties) Test(org.junit.jupiter.api.Test) AbstractConfigurationTest(org.apache.shenyu.admin.AbstractConfigurationTest)

Example 2 with NacosProperties

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());
}
Also used : NacosProperties(org.apache.shenyu.admin.config.properties.NacosProperties) Test(org.junit.jupiter.api.Test) AbstractConfigurationTest(org.apache.shenyu.admin.AbstractConfigurationTest)

Example 3 with NacosProperties

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);
}
Also used : NacosProperties(org.apache.shenyu.admin.config.properties.NacosProperties) Properties(java.util.Properties) EnableConfigurationProperties(org.springframework.boot.context.properties.EnableConfigurationProperties) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Aggregations

NacosProperties (org.apache.shenyu.admin.config.properties.NacosProperties)3 AbstractConfigurationTest (org.apache.shenyu.admin.AbstractConfigurationTest)2 Test (org.junit.jupiter.api.Test)2 Properties (java.util.Properties)1 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)1 EnableConfigurationProperties (org.springframework.boot.context.properties.EnableConfigurationProperties)1 Bean (org.springframework.context.annotation.Bean)1