Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
AKPlanning
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
Felix Blanke
AKPlanning
Commits
033388c6
Commit
033388c6
authored
2 months ago
by
Felix Blanke
Browse files
Options
Downloads
Patches
Plain Diff
Address linter remarks
parent
6f43998c
Branches
Branches containing commit
No related tags found
1 merge request
!25
Feature: Use JSON schema
Pipeline
#275694
passed
2 months ago
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
AKModel/utils.py
+9
-5
9 additions, 5 deletions
AKModel/utils.py
with
9 additions
and
5 deletions
AKModel/utils.py
+
9
−
5
View file @
033388c6
import
json
from
pathlib
import
Path
from
pathlib
import
Path
import
referencing.retrieval
import
referencing.retrieval
from
jsonschema
import
Draft202012Validator
from
jsonschema
import
Draft202012Validator
from
jsonschema.protocols
import
Validator
from
jsonschema.protocols
import
Validator
from
referencing
import
Registry
,
Resource
from
referencing
import
Registry
from
AKPlanning
import
settings
from
AKPlanning
import
settings
def
_construct_schema_path
(
uri
:
str
|
Path
)
->
Path
:
def
_construct_schema_path
(
uri
:
str
|
Path
)
->
Path
:
"""
Construct a schema URI.
This function also checks for unallowed directory traversals
out of the
'
schema
'
subfolder.
"""
schema_base_path
=
Path
(
settings
.
BASE_DIR
).
resolve
()
schema_base_path
=
Path
(
settings
.
BASE_DIR
).
resolve
()
uri_path
=
(
schema_base_path
/
uri
).
resolve
()
uri_path
=
(
schema_base_path
/
uri
).
resolve
()
if
not
uri_path
.
is_relative_to
(
schema_base_path
/
"
schemas
"
):
if
not
uri_path
.
is_relative_to
(
schema_base_path
/
"
schemas
"
):
...
@@ -18,8 +22,8 @@ def _construct_schema_path(uri: str | Path) -> Path:
...
@@ -18,8 +22,8 @@ def _construct_schema_path(uri: str | Path) -> Path:
@referencing.retrieval.to_cached_resource
()
@referencing.retrieval.to_cached_resource
()
def
retrieve_schema
(
uri
:
str
)
->
str
:
def
retrieve_schema
_from_disk
(
uri
:
str
)
->
str
:
# avoid dictionary traversals
"""
Retrieve schemas from disk by URI.
"""
uri_path
=
_construct_schema_path
(
uri
)
uri_path
=
_construct_schema_path
(
uri
)
with
uri_path
.
open
(
"
r
"
)
as
ff
:
with
uri_path
.
open
(
"
r
"
)
as
ff
:
return
ff
.
read
()
return
ff
.
read
()
...
@@ -31,7 +35,7 @@ def construct_schema_validator(schema: str | dict) -> Validator:
...
@@ -31,7 +35,7 @@ def construct_schema_validator(schema: str | dict) -> Validator:
In particular, all schemas from the
'
schemas
'
directory
In particular, all schemas from the
'
schemas
'
directory
are loaded into the registry.
are loaded into the registry.
"""
"""
registry
=
Registry
(
retrieve
=
retrieve_schema
)
registry
=
Registry
(
retrieve
=
retrieve_schema
_from_disk
)
if
isinstance
(
schema
,
str
):
if
isinstance
(
schema
,
str
):
schema_uri
=
str
(
Path
(
"
schemas
"
)
/
schema
)
schema_uri
=
str
(
Path
(
"
schemas
"
)
/
schema
)
...
...
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