Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
GÉANT Service Orchestrator
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
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
GÉANT Orchestration and Automation Team
GAP
GÉANT Service Orchestrator
Commits
73d83091
Commit
73d83091
authored
3 months ago
by
Karel van Klink
Committed by
Mohammad Torkashvand
3 months ago
Browse files
Options
Downloads
Patches
Plain Diff
Update typing of ga and gs id validation method
parent
7fdced2d
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!324
Feature/manage sid and gids
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
gso/utils/types/geant_ids.py
+10
-10
10 additions, 10 deletions
gso/utils/types/geant_ids.py
with
10 additions
and
10 deletions
gso/utils/types/geant_ids.py
+
10
−
10
View file @
73d83091
"""
Type definitions for the GA and GS IDs.
"""
from
functools
import
partial
from
typing
import
Annotated
from
typing
import
Annotated
,
Literal
from
pydantic
import
AfterValidator
from
gso.services.subscriptions
import
is_resource_type_value_unique
def
validate_id
(
value
:
str
,
prefix
:
str
,
field_name
:
str
)
->
str
:
def
validate_id
(
value
:
str
,
prefix
:
Literal
[
"
GA
"
,
"
GS
"
]
,
field_name
:
str
)
->
str
:
"""
Validate that the ID is unique, has the correct prefix, and is within valid constraints.
Args:
value
(str)
: The ID value to validate.
prefix
(str)
: The required prefix for the ID
(e.g.,
"
GA-
"
or
"
GS-
"
)
.
field_name
(str)
: The database field name to check for uniqueness
(e.g.,
"
ga_id
"
or
"
gs_id
"
)
.
value: The ID value to validate.
prefix: The required prefix for the ID.
field_name: The database field name to check for uniqueness.
Raises:
ValueError: If the ID is not valid.
...
...
@@ -29,21 +29,21 @@ def validate_id(value: str, prefix: str, field_name: str) -> str:
raise
ValueError
(
err
)
try
:
numeric_part
=
int
(
value
[
len
(
prefix
)
:
])
numeric_part
=
int
(
value
.
split
(
"
-
"
)[
-
1
])
except
ValueError
:
err
=
f
"
{
field_name
}
must have a numeric part after the prefix
'
{
prefix
}
'
.
"
raise
ValueError
(
err
)
from
ValueError
if
min_range
<=
numeric_part
<=
max_range
:
err
=
f
"
{
field_name
}
must not have a numeric part between 50000 and 99999
.
"
err
=
f
"
{
field_name
}
must not have a numeric part between 50000 and 99999
, received
{
numeric_part
}
"
raise
ValueError
(
err
)
if
not
is_resource_type_value_unique
(
field_name
,
value
):
err
=
f
"
{
field_name
}
must be unique.
"
err
=
f
"
{
field_name
}
must be unique
,
{
value
}
is already in use
.
"
raise
ValueError
(
err
)
return
value
IMPORTED_GA_ID
=
Annotated
[
str
,
AfterValidator
(
partial
(
validate_id
,
prefix
=
"
GA
-
"
,
field_name
=
"
ga_id
"
))]
IMPORTED_GS_ID
=
Annotated
[
str
,
AfterValidator
(
partial
(
validate_id
,
prefix
=
"
GS
-
"
,
field_name
=
"
gs_id
"
))]
IMPORTED_GA_ID
=
Annotated
[
str
,
AfterValidator
(
partial
(
validate_id
,
prefix
=
"
GA
"
,
field_name
=
"
ga_id
"
))]
IMPORTED_GS_ID
=
Annotated
[
str
,
AfterValidator
(
partial
(
validate_id
,
prefix
=
"
GS
"
,
field_name
=
"
gs_id
"
))]
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