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

[type:fix] Fix the nacos data sync model missing the contextPath configuration (#5721) #5722

Merged
merged 11 commits into from
Oct 31, 2024
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ public ConfigService nacosConfigService(final NacosProperties nacosProp) throws
if (StringUtils.isNotBlank(nacosProp.getPassword())) {
properties.put(PropertyKeyConst.PASSWORD, nacosProp.getPassword());
}
if (StringUtils.isNotBlank(nacosProp.getContextPath())) {
properties.put(PropertyKeyConst.CONTEXT_PATH, nacosProp.getContextPath());
}
}
return NacosFactory.createConfigService(properties);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public class NacosProperties {

private String password;

private String contextPath;

private NacosACMProperties acm;

/**
Expand Down Expand Up @@ -107,6 +109,24 @@ public void setPassword(final String password) {
this.password = password;
}

/**
* Gets the value of contextPath.
*
* @return the value of contextPath
*/
public String getContextPath() {
return contextPath;
}

/**
* Sets the contextPath.
*
* @param contextPath contextPath
*/
public void setContextPath(final String contextPath) {
this.contextPath = contextPath;
}

/**
* Gets the value of acm.
*
Expand Down
1 change: 1 addition & 0 deletions shenyu-admin/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ shenyu:
# namespace: 1c10d748-af86-43b9-8265-75f487d20c6c
# username:
# password:
# context-path: nacos
# acm:
# enabled: false
# endpoint: acm.aliyun.com
Expand Down
1 change: 1 addition & 0 deletions shenyu-bootstrap/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ shenyu:
# namespace: 1c10d748-af86-43b9-8265-75f487d20c6c
# username:
# password:
# context-path: nacos
# acm:
# enabled: false
# endpoint: acm.aliyun.com
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ public ConfigService nacosConfigService(final NacosConfig nacosConfig) throws Ex
if (nacosConfig.getPassword() != null) {
properties.put(PropertyKeyConst.PASSWORD, nacosConfig.getPassword());
}
if (StringUtils.isNotBlank(nacosConfig.getContextPath())) {
properties.put(PropertyKeyConst.CONTEXT_PATH, nacosConfig.getContextPath());
}
}
return NacosFactory.createConfigService(properties);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public class NacosConfig {

private String password;

private String contextPath;

private NacosACMConfig acm;

/**
Expand Down Expand Up @@ -103,6 +105,24 @@ public void setPassword(final String password) {
this.password = password;
}

/**
* Gets the value of contextPath.
*
* @return the value of contextPath
*/
public String getContextPath() {
return contextPath;
}

/**
* Sets the contextPath.
*
* @param contextPath contextPath
*/
public void setContextPath(final String contextPath) {
this.contextPath = contextPath;
}

/**
* get acm.
*
Expand Down Expand Up @@ -134,12 +154,13 @@ public boolean equals(final Object o) {
&& Objects.equals(namespace, that.namespace)
&& Objects.equals(username, that.username)
&& Objects.equals(password, that.password)
&& Objects.equals(contextPath, that.contextPath)
&& Objects.equals(acm, that.acm);
}

@Override
public int hashCode() {
return Objects.hash(url, namespace, username, password, acm);
return Objects.hash(url, namespace, username, password, contextPath, acm);
}

@Override
Expand All @@ -157,6 +178,9 @@ public String toString() {
+ ", password='"
+ password
+ '\''
+ ", contextPath='"
+ contextPath
+ '\''
+ ", acm="
+ acm
+ '}';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public final class NacosConfigTest {

private static final String USERNAME = "username";

private static final String CONTEXT_PATH = "nacos";

private static final NacosACMConfig ACM = new NacosACMConfig();

private NacosConfig nacosConfig;
Expand All @@ -51,12 +53,14 @@ public void setUp() {
nacosConfig.setNamespace(NAMESPACE);
nacosConfig.setPassword(PASSWORD);
nacosConfig.setUsername(USERNAME);
nacosConfig.setContextPath(CONTEXT_PATH);
nacosConfig.setAcm(ACM);
that = new NacosConfig();
that.setUrl(URL);
that.setNamespace(NAMESPACE);
that.setPassword(PASSWORD);
that.setUsername(USERNAME);
that.setContextPath(CONTEXT_PATH);
that.setAcm(ACM);
}

Expand All @@ -66,6 +70,7 @@ public void testGetterSetter() {
assertEquals(NAMESPACE, nacosConfig.getNamespace());
assertEquals(PASSWORD, nacosConfig.getPassword());
assertEquals(USERNAME, nacosConfig.getUsername());
assertEquals(CONTEXT_PATH, nacosConfig.getContextPath());
assertEquals(ACM, nacosConfig.getAcm());
}

Expand All @@ -80,7 +85,7 @@ public void testEquals() {
@Test
public void testHashCode() {
assertEquals(Objects.hash(nacosConfig.getUrl(), nacosConfig.getNamespace(),
nacosConfig.getUsername(), nacosConfig.getPassword(), nacosConfig.getAcm()),
nacosConfig.getUsername(), nacosConfig.getPassword(), nacosConfig.getContextPath(), nacosConfig.getAcm()),
nacosConfig.hashCode());
}
}
Loading