Skip to content

Commit

Permalink
fix: set nacos group and namespace for serverConnectorConfig metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
wenxuan70 committed Oct 27, 2023
1 parent 96ca33d commit c2973a8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ public class NacosConfigModifier implements PolarisConfigModifier {
* nacos contextPath.
*/
public static final String CONTEXT_PATH = "contextPath";
/**
* nacos namespace.
*/
public static final String NAMESPACE = "namespace";
/**
* nacos group.
*/
public static final String GROUP = "group";
private static final Logger LOGGER = LoggerFactory.getLogger(NacosConfigModifier.class);
private static final String ID = "nacos";
private final NacosContextProperties nacosContextProperties;
Expand Down Expand Up @@ -114,6 +122,14 @@ public void modify(ConfigurationImpl configuration) {
metadata.put(CONTEXT_PATH, nacosContextProperties.getContextPath());
}

if (StringUtils.isNotBlank(nacosContextProperties.getNamespace())) {
metadata.put(NAMESPACE, nacosContextProperties.getNamespace());
}

if (StringUtils.isNotBlank(nacosContextProperties.getGroup())) {
metadata.put(GROUP, nacosContextProperties.getGroup());
}

configuration.getGlobal().getServerConnectors().add(serverConnectorConfig);
DiscoveryConfigImpl discoveryConfig = new DiscoveryConfigImpl();
discoveryConfig.setServerConnectorId(ID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ public void testModify() {
assertThat(metadata.get(NacosConfigModifier.USERNAME)).isEqualTo(nacosContextProperties.getUsername());
assertThat(metadata.get(NacosConfigModifier.PASSWORD)).isEqualTo(nacosContextProperties.getPassword());
assertThat(metadata.get(NacosConfigModifier.CONTEXT_PATH)).isEqualTo(nacosContextProperties.getContextPath());
assertThat(metadata.get(NacosConfigModifier.NAMESPACE)).isEqualTo(nacosContextProperties.getNamespace());
assertThat(metadata.get(NacosConfigModifier.GROUP)).isEqualTo(nacosContextProperties.getGroup());
}

@SpringBootApplication
Expand Down

0 comments on commit c2973a8

Please sign in to comment.