Skip to content

Commit c22ac6c

Browse files
committed
Added path checks to the schema validations
1 parent 9443c6e commit c22ac6c

File tree

28 files changed

+57
-40
lines changed

28 files changed

+57
-40
lines changed

core/data/impl/nodeimpl.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,8 @@ def read_locals(self) -> dict:
205205
try:
206206
schema_files = ['schemas/nodes_schema.yaml']
207207
schema_files.extend([str(x) for x in Path('./extensions').rglob('*_schema.yaml')])
208-
c = Core(source_file=config_file, schema_files=schema_files, file_encoding='utf-8')
208+
c = Core(source_file=config_file, schema_files=schema_files, file_encoding='utf-8',
209+
extensions=['core/utils/validators.py'])
209210
try:
210211
c.validate(raise_exception=True)
211212
except SchemaError as ex:

core/data/node.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ def extensions(self) -> dict:
8888

8989
def read_config(self, file: str) -> dict:
9090
try:
91-
c = Core(source_file=file, schema_files=['schemas/main_schema.yaml'], file_encoding='utf-8')
91+
c = Core(source_file=file, schema_files=['schemas/main_schema.yaml'], file_encoding='utf-8',
92+
extensions=['core/utils/validators.py'])
9293
try:
9394
c.validate(raise_exception=True)
9495
except SchemaError as ex:

core/data/server.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ def read_locals(self) -> dict:
7474
config_file = os.path.join(self.node.config_dir, 'servers.yaml')
7575
if os.path.exists(config_file):
7676
try:
77-
c = Core(source_file=config_file, schema_files=['schemas/servers_schema.yaml'], file_encoding='utf-8')
77+
c = Core(source_file=config_file, schema_files=['schemas/servers_schema.yaml'], file_encoding='utf-8',
78+
extensions=['core/utils/validators.py'])
7879
try:
7980
c.validate(raise_exception=True)
8081
except SchemaError as ex:

core/plugin.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,8 @@ def read_locals(self) -> dict:
429429
if os.path.exists(path):
430430
schema_files = [str(x) for x in Path(path).glob('*.yaml')]
431431
schema_files.append('schemas/commands_schema.yaml')
432-
c = Core(source_file=filename, schema_files=schema_files, file_encoding='utf-8')
432+
c = Core(source_file=filename, schema_files=schema_files, file_encoding='utf-8',
433+
extensions=['core/utils/validators.py'])
433434
try:
434435
c.validate(raise_exception=True)
435436
except SchemaError as ex:

core/services/base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ def read_locals(self) -> dict:
118118
path = os.path.join('services', self.name.lower(), 'schemas')
119119
if os.path.exists(path):
120120
schema_files = [str(x) for x in Path(path).glob('*.yaml')]
121-
c = Core(source_file=filename, schema_files=schema_files, file_encoding='utf-8')
121+
c = Core(source_file=filename, schema_files=schema_files, file_encoding='utf-8',
122+
extensions=['core/utils/validators.py'])
122123
try:
123124
c.validate(raise_exception=True)
124125
except SchemaError as ex:

core/utils/validators.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import os
2+
3+
from pykwalify.errors import SchemaError
4+
5+
from core import DEFAULT_TAG, COMMAND_LINE_ARGS
6+
7+
def file_exists(value, rule_obj, path):
8+
if path and path.split("/")[1] in [DEFAULT_TAG, COMMAND_LINE_ARGS.node]:
9+
if not os.path.exists(os.path.expandvars(value)):
10+
raise SchemaError(msg=f'File "{value}" does not exist', path=path)
11+
return True

extensions/github/schemas/github_schema.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ schema;github_schema:
33
nullable: false
44
mapping:
55
enabled: {type: bool, nullable: false}
6-
repo: {type: str, required: true, nullable: false, range: {min: 1}}
7-
target: {type: str, required: true, nullable: false, range: {min: 1}}
6+
repo: {type: url, required: true, nullable: false}
7+
target: {type: str, required: true, nullable: false, range: {min: 1}, func: file_exists}
88
filter: {type: str, nullable: false, range: {min: 1}}

extensions/lardoon/schemas/lardoon_schema.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ schema;node_lardoon_schema:
55
cmd: {type: str, pattern: '.+\.exe$', required: true, nullable: false, range: {min: 1}}
66
minutes: {type: int, nullable: false}
77
bind: {type: str, pattern: '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}:\d{1,5}', required: true, nullable: false}
8-
url: {type: str, pattern: 'http(s)?://[a-zA-Z0-9\-.]+(:[0-9]+)?(/.*)?', nullable: false}
8+
url: {type: url, nullable: false}
99
schema;instance_lardoon_schema:
1010
type: map
1111
nullable: false
1212
mapping:
1313
enabled: {type: bool, nullable: false}
1414
debug: {type: bool, nullable: false}
15-
tacviewExportPath: {type: str, nullable: false, range: {min: 1}}
15+
tacviewExportPath: {type: str, nullable: false, range: {min: 1}, func: file_exists}

extensions/lotatc/schemas/lotatc_schema.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ schema;node_lotatc_schema:
33
nullable: false
44
allowempty: true # we might want to specify additional lotatc parameters, which are then not validated
55
mapping:
6-
installation: {type: str, nullable: false, range: {min: 1}}
6+
installation: {type: str, nullable: false, range: {min: 1}, func: file_exists}
77
autoupdate: {type: any, nullable: false}
88
schema;instance_lotatc_schema:
99
type: map

extensions/olympus/schemas/olympus_schema.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ schema;node_olympus_schema:
22
type: map
33
nullable: false
44
mapping:
5-
nodejs: {type: str, nullable: false, range: {min: 1}}
5+
nodejs: {type: str, nullable: false, range: {min: 1}, func: file_exists}
66
debug: {type: bool, nullable: false}
77
show_passwords: {type: bool, nullable: false}
88
authentication:
@@ -21,7 +21,7 @@ schema;instance_olympus_schema:
2121
enabled: {type: bool, nullable: false}
2222
debug: {type: bool, nullable: false}
2323
show_passwords: {type: bool, nullable: false}
24-
url: {type: str, pattern: 'http(s)?://[a-zA-Z0-9\-.]+(:[0-9]+)?(/.*)?', nullable: false}
24+
url: {type: url, nullable: false}
2525
regex;(backend|server):
2626
type: map
2727
nullable: false
@@ -44,5 +44,5 @@ schema;instance_olympus_schema:
4444
required: true
4545
allowempty: true
4646
mapping:
47-
path: {type: str, nullable: false, range: {min: 1}}
47+
path: {type: str, nullable: false, range: {min: 1}, func: file_exists}
4848
port: {type: int, required: true, range: {min: 80, max: 65535}, nullable: false}

0 commit comments

Comments
 (0)