001/**
002 * Copyright (c) 2015-2022, Michael Yang 杨福海 (fuhai999@gmail.com).
003 * <p>
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 * <p>
008 * http://www.apache.org/licenses/LICENSE-2.0
009 * <p>
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package io.jboot.app.config.support.nacos;
017
018
019import io.jboot.app.config.JbootConfigKit;
020import io.jboot.app.config.annotation.ConfigModel;
021
022import java.util.Properties;
023
024/**
025 * @see com.alibaba.nacos.api.PropertyKeyConst
026 */
027@ConfigModel(prefix = "jboot.config.nacos")
028public class NacosServerConfig {
029
030    private boolean enable = false;
031
032    private String isUseCloudNamespaceParsing;
033    private String isUseEndpointParsingRule;
034    private String endpoint;
035    private String endpointPort;
036    private String namespace;
037    private String username;
038    private String password;
039    private String accessKey;
040    private String secretKey;
041    private String ramRoleName;
042    private String serverAddr;
043    private String contextPath;
044    private String clusterName;
045    private String encode;
046    private String configLongPollTimeout;
047    private String configRetryTime;
048    private String maxRetry;
049    private String enableRemoteSyncConfig;
050
051    private String dataId;
052    private String group;
053
054    public boolean isEnable() {
055        return enable;
056    }
057
058    public void setEnable(boolean enable) {
059        this.enable = enable;
060    }
061
062    public String getIsUseCloudNamespaceParsing() {
063        return isUseCloudNamespaceParsing;
064    }
065
066    public void setIsUseCloudNamespaceParsing(String isUseCloudNamespaceParsing) {
067        this.isUseCloudNamespaceParsing = isUseCloudNamespaceParsing;
068    }
069
070    public String getIsUseEndpointParsingRule() {
071        return isUseEndpointParsingRule;
072    }
073
074    public void setIsUseEndpointParsingRule(String isUseEndpointParsingRule) {
075        this.isUseEndpointParsingRule = isUseEndpointParsingRule;
076    }
077
078    public String getEndpoint() {
079        return endpoint;
080    }
081
082    public void setEndpoint(String endpoint) {
083        this.endpoint = endpoint;
084    }
085
086    public String getEndpointPort() {
087        return endpointPort;
088    }
089
090    public void setEndpointPort(String endpointPort) {
091        this.endpointPort = endpointPort;
092    }
093
094    public String getNamespace() {
095        return namespace;
096    }
097
098    public void setNamespace(String namespace) {
099        this.namespace = namespace;
100    }
101
102    public String getUsername() {
103        return username;
104    }
105
106    public void setUsername(String username) {
107        this.username = username;
108    }
109
110    public String getPassword() {
111        return password;
112    }
113
114    public void setPassword(String password) {
115        this.password = password;
116    }
117
118    public String getAccessKey() {
119        return accessKey;
120    }
121
122    public void setAccessKey(String accessKey) {
123        this.accessKey = accessKey;
124    }
125
126    public String getSecretKey() {
127        return secretKey;
128    }
129
130    public void setSecretKey(String secretKey) {
131        this.secretKey = secretKey;
132    }
133
134    public String getRamRoleName() {
135        return ramRoleName;
136    }
137
138    public void setRamRoleName(String ramRoleName) {
139        this.ramRoleName = ramRoleName;
140    }
141
142    public String getServerAddr() {
143        return serverAddr;
144    }
145
146    public void setServerAddr(String serverAddr) {
147        this.serverAddr = serverAddr;
148    }
149
150    public String getContextPath() {
151        return contextPath;
152    }
153
154    public void setContextPath(String contextPath) {
155        this.contextPath = contextPath;
156    }
157
158    public String getClusterName() {
159        return clusterName;
160    }
161
162    public void setClusterName(String clusterName) {
163        this.clusterName = clusterName;
164    }
165
166    public String getEncode() {
167        return encode;
168    }
169
170    public void setEncode(String encode) {
171        this.encode = encode;
172    }
173
174    public String getConfigLongPollTimeout() {
175        return configLongPollTimeout;
176    }
177
178    public void setConfigLongPollTimeout(String configLongPollTimeout) {
179        this.configLongPollTimeout = configLongPollTimeout;
180    }
181
182    public String getConfigRetryTime() {
183        return configRetryTime;
184    }
185
186    public void setConfigRetryTime(String configRetryTime) {
187        this.configRetryTime = configRetryTime;
188    }
189
190    public String getMaxRetry() {
191        return maxRetry;
192    }
193
194    public void setMaxRetry(String maxRetry) {
195        this.maxRetry = maxRetry;
196    }
197
198    public String getEnableRemoteSyncConfig() {
199        return enableRemoteSyncConfig;
200    }
201
202    public void setEnableRemoteSyncConfig(String enableRemoteSyncConfig) {
203        this.enableRemoteSyncConfig = enableRemoteSyncConfig;
204    }
205
206    public String getDataId() {
207        return dataId;
208    }
209
210    public void setDataId(String dataId) {
211        this.dataId = dataId;
212    }
213
214    public String getGroup() {
215        return group;
216    }
217
218    public void setGroup(String group) {
219        this.group = group;
220    }
221
222    public Properties toProperties() {
223        Properties properties = new Properties();
224        putProperties(properties, "isUseCloudNamespaceParsing", isUseCloudNamespaceParsing);
225        putProperties(properties, "isUseEndpointParsingRule", isUseEndpointParsingRule);
226        putProperties(properties, "endpoint", endpoint);
227        putProperties(properties, "endpointPort", endpointPort);
228        putProperties(properties, "namespace", namespace);
229        putProperties(properties, "username", username);
230        putProperties(properties, "password", password);
231        putProperties(properties, "accessKey", accessKey);
232        putProperties(properties, "secretKey", secretKey);
233        putProperties(properties, "ramRoleName", ramRoleName);
234        putProperties(properties, "serverAddr", serverAddr);
235        putProperties(properties, "contextPath", contextPath);
236        putProperties(properties, "clusterName", clusterName);
237        putProperties(properties, "encode", encode);
238        putProperties(properties, "configLongPollTimeout", configLongPollTimeout);
239        putProperties(properties, "configRetryTime", configRetryTime);
240        putProperties(properties, "maxRetry", maxRetry);
241        putProperties(properties, "enableRemoteSyncConfig", enableRemoteSyncConfig);
242        return properties;
243    }
244
245    private void putProperties(Properties p, String key, String value) {
246        if (value != null && value.trim().length() > 0) {
247            p.put(key, value);
248        }
249    }
250
251
252    public boolean isConfigOk() {
253        return JbootConfigKit.areNotBlank(serverAddr, dataId, group);
254    }
255}