Mentions légales du service
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
reference-repository
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
grid5000
reference-repository
Commits
314918c5
Commit
314918c5
authored
4 years ago
by
Baptiste Jonglez
Browse files
Options
Downloads
Patches
Plain Diff
[schema] Add validators for IPv4 and IPv6 networks
parent
3aadfcea
No related branches found
No related tags found
No related merge requests found
Pipeline
#220652
passed
4 years ago
Stage: validate
Stage: generate
Stage: deploy
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/refrepo/valid/input/lib/custom_validators.rb
+48
-0
48 additions, 0 deletions
lib/refrepo/valid/input/lib/custom_validators.rb
lib/refrepo/valid/input/schemas/schema-site.yaml
+6
-6
6 additions, 6 deletions
lib/refrepo/valid/input/schemas/schema-site.yaml
with
54 additions
and
6 deletions
lib/refrepo/valid/input/lib/custom_validators.rb
+
48
−
0
View file @
314918c5
...
...
@@ -43,6 +43,29 @@ class HashValidator::Validator::Ipv4AddressValidator < HashValidator::Validator:
end
end
class
HashValidator::Validator::Ipv4NetworkValidator
<
HashValidator
::
Validator
::
Base
def
initialize
super
(
'ipv4_network'
)
end
def
validate
(
key
,
values
,
_validations
,
errors
)
if
not
values
.
is_a?
(
String
)
errors
[
key
]
=
"IPv4 network should be a String"
elsif
not
values
.
include?
(
'/'
)
errors
[
key
]
=
"IPv4 network should contain a '/' character"
else
address
=
values
.
split
(
"/"
)[
0
]
prefix_length
=
Integer
(
values
.
split
(
"/"
)[
1
])
rescue
nil
if
(
not
prefix_length
.
is_a?
(
Integer
))
||
prefix_length
<
0
||
prefix_length
>
32
errors
[
key
]
=
"Invalid IPv4 prefix length for network
#{
values
}
"
elsif
not
address
=~
Resolv
::
IPv4
::
Regex
errors
[
key
]
=
"Invalid IPv4 network format
#{
values
}
"
end
end
end
end
class
HashValidator::Validator::Ipv6AddressValidator
<
HashValidator
::
Validator
::
Base
def
initialize
...
...
@@ -60,6 +83,31 @@ class HashValidator::Validator::Ipv6AddressValidator < HashValidator::Validator:
end
end
class
HashValidator::Validator::Ipv6NetworkValidator
<
HashValidator
::
Validator
::
Base
def
initialize
super
(
'ipv6_network'
)
end
def
validate
(
key
,
values
,
_validations
,
errors
)
if
not
values
.
is_a?
(
String
)
errors
[
key
]
=
"IPv6 network should be a String"
elsif
not
values
.
include?
(
'/'
)
errors
[
key
]
=
"IPv6 network should contain a '/' character"
else
address
=
values
.
split
(
"/"
)[
0
]
prefix_length
=
Integer
(
values
.
split
(
"/"
)[
1
])
rescue
nil
if
(
not
prefix_length
.
is_a?
(
Integer
))
||
prefix_length
<
0
||
prefix_length
>
128
errors
[
key
]
=
"Invalid IPv6 prefix length for network
#{
values
}
"
elsif
not
address
=~
Resolv
::
IPv6
::
Regex
errors
[
key
]
=
"Invalid IPv6 network format
#{
values
}
"
end
end
end
end
HashValidator
.
append_validator
(
HashValidator
::
Validator
::
LinecardPortValidator
.
new
)
HashValidator
.
append_validator
(
HashValidator
::
Validator
::
Ipv4AddressValidator
.
new
)
HashValidator
.
append_validator
(
HashValidator
::
Validator
::
Ipv4NetworkValidator
.
new
)
HashValidator
.
append_validator
(
HashValidator
::
Validator
::
Ipv6AddressValidator
.
new
)
HashValidator
.
append_validator
(
HashValidator
::
Validator
::
Ipv6NetworkValidator
.
new
)
This diff is collapsed.
Click to expand it.
lib/refrepo/valid/input/schemas/schema-site.yaml
+
6
−
6
View file @
314918c5
...
...
@@ -49,7 +49,7 @@ sys_admin_contact: email
security_contact
:
email
user_support_contact
:
email
compilation_server
:
boolean
virt_ip_range
:
string
virt_ip_range
:
ipv4_network
production
:
boolean
laptops
:
<optional_hash>
:
...
...
@@ -61,15 +61,15 @@ laptops:
ip
:
ipv4_address
mac
:
optional_string
g5ksubnet
:
network
:
string
network
:
ipv4_network
gateway
:
ipv4_address
kavlans
:
<multi>
:
network
:
string
network
:
ipv4_network
gateway
:
ipv4_address
network_ipv6
:
string
network_ipv6
:
ipv6_network
gateway_ipv6
:
optional_ipv6_address
kavlan_ip_range
:
string
kavlan_ip_range
:
ipv4_network
kavlan_topo
:
optional_string
kavlan_nef
:
optional_integer
pdus
:
...
...
@@ -101,6 +101,6 @@ pdus:
renater_ip
:
ipv4_address
frontend_ip
:
ipv4_address
ipv6
:
prefix
:
string
prefix
:
ipv6_network
site_global_kavlan
:
integer
site_index
:
integer
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment