Skip to content

Commit

Permalink
feat: enforce docker image to belong to either deephdc or `ai4oshub…
Browse files Browse the repository at this point in the history
…` DockerHub orgs (or our Harbor)
  • Loading branch information
IgnacioHeredia committed Sep 9, 2024
1 parent 5b4c67f commit 78fe123
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 14 deletions.
3 changes: 3 additions & 0 deletions ai4papi/routers/v1/deployments/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@ def create_deployment(
reference=user_conf,
)

# Utils validate conf
user_conf = utils.validate_conf(user_conf)

# Check if the provided configuration is within the job quotas
quotas.check_jobwise(
conf=user_conf,
Expand Down
41 changes: 27 additions & 14 deletions ai4papi/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,24 +150,37 @@ def validate_conf(conf):
"""
Validate user configuration
"""
# Check datasets_info list
for d in conf['storage']['datasets']:

# Validate DOI
# ref: https://stackoverflow.com/a/48524047/18471590
pattern = r"^10.\d{4,9}/[-._;()/:A-Z0-9]+$"
if not re.match(pattern, d['doi'], re.IGNORECASE):
# Check that the Dockerhub image belongs either to "deephdc" or "ai4oshub"
# or that it points to our Harbor instance (eg. CVAT)
image = conf.get('general', {}).get('docker_image')
if image:
if image.split('/')[0] not in ["deephdc", "ai4oshub", "registry.services.ai4os.eu"]:
raise HTTPException(
status_code=400,
detail="Invalid DOI."
detail="The docker image should belong to either 'deephdc' or 'ai4oshub' \
DockerHub organizations or be hosted in the project's Harbor."
)

# Check force pull parameter
if not isinstance(d['force_pull'], bool):
raise HTTPException(
status_code=400,
detail="Force pull should be bool."
)
# Check datasets_info list
datasets = conf.get('storage', {}).get('datasets')
if datasets:
for d in datasets:

# Validate DOI
# ref: https://stackoverflow.com/a/48524047/18471590
pattern = r"^10.\d{4,9}/[-._;()/:A-Z0-9]+$"
if not re.match(pattern, d['doi'], re.IGNORECASE):
raise HTTPException(
status_code=400,
detail="Invalid DOI."
)

# Check force pull parameter
if not isinstance(d['force_pull'], bool):
raise HTTPException(
status_code=400,
detail="Force pull should be bool."
)

return conf

Expand Down

0 comments on commit 78fe123

Please sign in to comment.