30
30
* @author zhuoguang
31
31
*/
32
32
public class DefaultParamChecker extends AbstractParamChecker {
33
-
33
+
34
34
private Pattern namespaceShowNamePattern ;
35
-
35
+
36
36
private Pattern namespaceIdPattern ;
37
-
37
+
38
38
private Pattern dataIdPattern ;
39
-
39
+
40
40
private Pattern serviceNamePattern ;
41
-
41
+
42
42
private Pattern groupPattern ;
43
-
43
+
44
44
private Pattern clusterPattern ;
45
-
45
+
46
46
private Pattern ipPattern ;
47
-
47
+
48
48
private static final String CHECKER_TYPE = "default" ;
49
-
49
+
50
50
private static final String MAX_METADATA_LENGTH_PROP_NAME = "nacos.naming.service.metadata.length" ;
51
-
51
+
52
52
private static final String MAX_METADATA_LENGTH_ENV_NAME = "NACOS_NAMING_SERVICE_METADATA_LENGTH" ;
53
-
53
+
54
54
@ Override
55
55
public String getCheckerType () {
56
56
return CHECKER_TYPE ;
57
57
}
58
-
58
+
59
59
@ Override
60
60
public ParamCheckResponse checkParamInfoList (List <ParamInfo > paramInfos ) {
61
61
ParamCheckResponse paramCheckResponse = new ParamCheckResponse ();
@@ -72,14 +72,14 @@ public ParamCheckResponse checkParamInfoList(List<ParamInfo> paramInfos) {
72
72
paramCheckResponse .setSuccess (true );
73
73
return paramCheckResponse ;
74
74
}
75
-
75
+
76
76
@ Override
77
77
public void initParamCheckRule () {
78
78
this .paramCheckRule = new ParamCheckRule ();
79
79
initFormatPattern ();
80
80
replaceParamCheckRuleByEnv ();
81
81
}
82
-
82
+
83
83
private void initFormatPattern () {
84
84
this .namespaceShowNamePattern = Pattern .compile (this .paramCheckRule .namespaceShowNamePatternString );
85
85
this .namespaceIdPattern = Pattern .compile (this .paramCheckRule .namespaceIdPatternString );
@@ -89,7 +89,7 @@ private void initFormatPattern() {
89
89
this .clusterPattern = Pattern .compile (this .paramCheckRule .clusterPatternString );
90
90
this .ipPattern = Pattern .compile (this .paramCheckRule .ipPatternString );
91
91
}
92
-
92
+
93
93
/**
94
94
* if environment variables exists, it will be replaced.
95
95
*/
@@ -99,7 +99,7 @@ private void replaceParamCheckRuleByEnv() {
99
99
this .paramCheckRule .maxMetadataLength = NumberUtils .toInt (maxMetadataLength );
100
100
}
101
101
}
102
-
102
+
103
103
/**
104
104
* Check param info format.
105
105
*
@@ -155,7 +155,7 @@ public ParamCheckResponse checkParamInfoFormat(ParamInfo paramInfo) {
155
155
paramCheckResponse .setSuccess (true );
156
156
return paramCheckResponse ;
157
157
}
158
-
158
+
159
159
/**
160
160
* Check namespace show name format.
161
161
*
@@ -182,7 +182,7 @@ public ParamCheckResponse checkNamespaceShowNameFormat(String namespaceShowName)
182
182
paramCheckResponse .setSuccess (true );
183
183
return paramCheckResponse ;
184
184
}
185
-
185
+
186
186
/**
187
187
* Check namespace id format.
188
188
*
@@ -209,7 +209,7 @@ public ParamCheckResponse checkNamespaceIdFormat(String namespaceId) {
209
209
paramCheckResponse .setSuccess (true );
210
210
return paramCheckResponse ;
211
211
}
212
-
212
+
213
213
/**
214
214
* Check data id format.
215
215
*
@@ -224,8 +224,8 @@ public ParamCheckResponse checkDataIdFormat(String dataId) {
224
224
}
225
225
if (dataId .length () > paramCheckRule .maxDataIdLength ) {
226
226
paramCheckResponse .setSuccess (false );
227
- paramCheckResponse .setMessage (String . format ( "Param 'dataId' is illegal, the param length should not exceed %d." ,
228
- paramCheckRule .maxDataIdLength ));
227
+ paramCheckResponse .setMessage (
228
+ String . format ( "Param 'dataId' is illegal, the param length should not exceed %d." , paramCheckRule .maxDataIdLength ));
229
229
return paramCheckResponse ;
230
230
}
231
231
if (!dataIdPattern .matcher (dataId ).matches ()) {
@@ -236,7 +236,7 @@ public ParamCheckResponse checkDataIdFormat(String dataId) {
236
236
paramCheckResponse .setSuccess (true );
237
237
return paramCheckResponse ;
238
238
}
239
-
239
+
240
240
/**
241
241
* Check service name format.
242
242
*
@@ -251,8 +251,8 @@ public ParamCheckResponse checkServiceNameFormat(String serviceName) {
251
251
}
252
252
if (serviceName .length () > paramCheckRule .maxServiceNameLength ) {
253
253
paramCheckResponse .setSuccess (false );
254
- paramCheckResponse .setMessage (String . format ( "Param 'serviceName' is illegal, the param length should not exceed %d." ,
255
- paramCheckRule .maxServiceNameLength ));
254
+ paramCheckResponse .setMessage (
255
+ String . format ( "Param 'serviceName' is illegal, the param length should not exceed %d." , paramCheckRule .maxServiceNameLength ));
256
256
return paramCheckResponse ;
257
257
}
258
258
if (!serviceNamePattern .matcher (serviceName ).matches ()) {
@@ -263,7 +263,7 @@ public ParamCheckResponse checkServiceNameFormat(String serviceName) {
263
263
paramCheckResponse .setSuccess (true );
264
264
return paramCheckResponse ;
265
265
}
266
-
266
+
267
267
/**
268
268
* Check group format.
269
269
*
@@ -278,8 +278,8 @@ public ParamCheckResponse checkGroupFormat(String group) {
278
278
}
279
279
if (group .length () > paramCheckRule .maxGroupLength ) {
280
280
paramCheckResponse .setSuccess (false );
281
- paramCheckResponse .setMessage (String . format ( "Param 'group' is illegal, the param length should not exceed %d." ,
282
- paramCheckRule .maxGroupLength ));
281
+ paramCheckResponse .setMessage (
282
+ String . format ( "Param 'group' is illegal, the param length should not exceed %d." , paramCheckRule .maxGroupLength ));
283
283
return paramCheckResponse ;
284
284
}
285
285
if (!groupPattern .matcher (group ).matches ()) {
@@ -290,7 +290,7 @@ public ParamCheckResponse checkGroupFormat(String group) {
290
290
paramCheckResponse .setSuccess (true );
291
291
return paramCheckResponse ;
292
292
}
293
-
293
+
294
294
/**
295
295
* Check cluster format.
296
296
*
@@ -313,7 +313,7 @@ public ParamCheckResponse checkClusterFormat(String clusterString) {
313
313
paramCheckResponse .setSuccess (true );
314
314
return paramCheckResponse ;
315
315
}
316
-
316
+
317
317
/**
318
318
* Check single cluster format.
319
319
*
@@ -326,11 +326,11 @@ public ParamCheckResponse checkSingleClusterFormat(String cluster) {
326
326
paramCheckResponse .setSuccess (true );
327
327
return paramCheckResponse ;
328
328
}
329
-
329
+
330
330
if (cluster .length () > paramCheckRule .maxClusterLength ) {
331
331
paramCheckResponse .setSuccess (false );
332
- paramCheckResponse .setMessage (String . format ( "Param 'cluster' is illegal, the param length should not exceed %d." ,
333
- paramCheckRule .maxClusterLength ));
332
+ paramCheckResponse .setMessage (
333
+ String . format ( "Param 'cluster' is illegal, the param length should not exceed %d." , paramCheckRule .maxClusterLength ));
334
334
return paramCheckResponse ;
335
335
}
336
336
if (!clusterPattern .matcher (cluster ).matches ()) {
@@ -341,7 +341,7 @@ public ParamCheckResponse checkSingleClusterFormat(String cluster) {
341
341
paramCheckResponse .setSuccess (true );
342
342
return paramCheckResponse ;
343
343
}
344
-
344
+
345
345
/**
346
346
* Check ip format.
347
347
*
@@ -356,8 +356,7 @@ public ParamCheckResponse checkIpFormat(String ip) {
356
356
}
357
357
if (ip .length () > paramCheckRule .maxIpLength ) {
358
358
paramCheckResponse .setSuccess (false );
359
- paramCheckResponse .setMessage (String .format ("Param 'ip' is illegal, the param length should not exceed %d." ,
360
- paramCheckRule .maxIpLength ));
359
+ paramCheckResponse .setMessage (String .format ("Param 'ip' is illegal, the param length should not exceed %d." , paramCheckRule .maxIpLength ));
361
360
return paramCheckResponse ;
362
361
}
363
362
if (!ipPattern .matcher (ip ).matches ()) {
@@ -368,7 +367,7 @@ public ParamCheckResponse checkIpFormat(String ip) {
368
367
paramCheckResponse .setSuccess (true );
369
368
return paramCheckResponse ;
370
369
}
371
-
370
+
372
371
/**
373
372
* Check port format.
374
373
*
@@ -386,20 +385,20 @@ public ParamCheckResponse checkPortFormat(String port) {
386
385
portInt = Integer .parseInt (port );
387
386
} catch (Exception e ) {
388
387
paramCheckResponse .setSuccess (false );
389
- paramCheckResponse .setMessage (String . format ( "Param 'port' is illegal, the value should be between %d and %d." ,
390
- paramCheckRule .minPort , paramCheckRule .maxPort ));
388
+ paramCheckResponse .setMessage (
389
+ String . format ( "Param 'port' is illegal, the value should be between %d and %d." , paramCheckRule .minPort , paramCheckRule .maxPort ));
391
390
return paramCheckResponse ;
392
391
}
393
392
if (portInt > paramCheckRule .maxPort || portInt < paramCheckRule .minPort ) {
394
393
paramCheckResponse .setSuccess (false );
395
- paramCheckResponse .setMessage (String . format ( "Param 'port' is illegal, the value should be between %d and %d." ,
396
- paramCheckRule .minPort , paramCheckRule .maxPort ));
394
+ paramCheckResponse .setMessage (
395
+ String . format ( "Param 'port' is illegal, the value should be between %d and %d." , paramCheckRule .minPort , paramCheckRule .maxPort ));
397
396
return paramCheckResponse ;
398
397
}
399
398
paramCheckResponse .setSuccess (true );
400
399
return paramCheckResponse ;
401
400
}
402
-
401
+
403
402
/**
404
403
* Check metadata format.
405
404
*
@@ -423,8 +422,8 @@ public ParamCheckResponse checkMetadataFormat(Map<String, String> metadata) {
423
422
}
424
423
if (totalLength > paramCheckRule .maxMetadataLength ) {
425
424
paramCheckResponse .setSuccess (false );
426
- paramCheckResponse .setMessage (String . format ( "Param 'Metadata' is illegal, the param length should not exceed %d." ,
427
- paramCheckRule .maxMetadataLength ));
425
+ paramCheckResponse .setMessage (
426
+ String . format ( "Param 'Metadata' is illegal, the param length should not exceed %d." , paramCheckRule .maxMetadataLength ));
428
427
return paramCheckResponse ;
429
428
}
430
429
paramCheckResponse .setSuccess (true );
0 commit comments