mirror of
https://github.com/Telecominfraproject/ols-ucentral-schema.git
synced 2025-10-30 01:32:26 +00:00
generate-reader, generate-example: introduce new uc-portrange format
The `uc-portrange` string format will match single ports and ranges in `minport-maxport` notation. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
This commit is contained in:
committed by
John Crispin
parent
af9e861ec1
commit
b5531dd0a0
@@ -211,6 +211,14 @@ function random_value(kind, minLength, maxLength) {
|
|||||||
case 'uc-base64':
|
case 'uc-base64':
|
||||||
return b64enc(random_phrase(50, 100));
|
return b64enc(random_phrase(50, 100));
|
||||||
|
|
||||||
|
case 'uc-portrange':
|
||||||
|
switch (math.rand() % 2) {
|
||||||
|
case 0: return sprintf('%d', math.rand() % 65536);
|
||||||
|
case 1: return join('-', sort([ math.rand() % 65536, math.rand() % 65536 ]));
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if (minLength <= 15 && maxLength >= 20)
|
if (minLength <= 15 && maxLength >= 20)
|
||||||
return random_phrase(minLength, maxLength);
|
return random_phrase(minLength, maxLength);
|
||||||
|
|||||||
@@ -95,6 +95,15 @@ let GeneratorProto = {
|
|||||||
'return b64dec(value) != null;'
|
'return b64dec(value) != null;'
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
"uc-portrange": {
|
||||||
|
desc: 'network port range',
|
||||||
|
code: [
|
||||||
|
'let ports = match(value, /^([0-9]|[1-9][0-9]*)(-([0-9]|[1-9][0-9]*))?$/);',
|
||||||
|
'if (!ports) return false;',
|
||||||
|
'let min = +ports[1], max = ports[2] ? +ports[3] : min;',
|
||||||
|
'return (min <= 65535 && max <= 65535 && max >= min);'
|
||||||
|
]
|
||||||
|
},
|
||||||
"hostname": {
|
"hostname": {
|
||||||
desc: 'hostname',
|
desc: 'hostname',
|
||||||
code: [
|
code: [
|
||||||
|
|||||||
Reference in New Issue
Block a user