Skip to content

Commit

Permalink
Improve registry validation (#1429)
Browse files Browse the repository at this point in the history
* Allow that a provider can upload its function without a registry

* Simplified mock setting
  • Loading branch information
Tansito authored Aug 1, 2024
1 parent 0a0b645 commit 65cda73
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 7 deletions.
1 change: 0 additions & 1 deletion docker-compose-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ services:
- [email protected]
- SITE_HOST=http://gateway:8000
- SETTINGS_AUTH_MECHANISM=mock_token
- SETTINGS_AUTH_MOCKPROVIDER_REGISTRY=test
- DATABASE_HOST=postgres
- DATABASE_PORT=5432
- DATABASE_NAME=serverlessdb
Expand Down
1 change: 0 additions & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ services:
- [email protected]
- SITE_HOST=http://gateway:8000
- SETTINGS_AUTH_MECHANISM=mock_token
- SETTINGS_AUTH_MOCKPROVIDER_REGISTRY=test
- DATABASE_HOST=postgres
- DATABASE_PORT=5432
- DATABASE_NAME=serverlessdb
Expand Down
9 changes: 5 additions & 4 deletions gateway/api/v1/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,18 @@ def validate(self, attrs):
raise ValidationError(
"At least one of attributes (entrypoint, image) is required."
)

title = attrs.get("title")
provider = attrs.get("provider", None)
if provider and "/" in title:
raise ValidationError("Provider defined in title and in provider fields.")

title_split = title.split("/")
if len(title_split) > 2:
raise ValidationError(
"Qiskit Function title is malformed. It can only contain one slash."
)

if image is not None:
if provider is None and len(title_split) != 2:
raise ValidationError(
Expand All @@ -60,10 +63,8 @@ def validate(self, attrs):
provider = title_split[0]
provider_instance = Provider.objects.filter(name=provider).first()
if provider_instance is None:
raise ValidationError(
"Custom images are only available a valid provider."
)
if not provider_instance.registry or not image.startswith(
raise ValidationError(f"{provider} is not valid provider.")
if provider_instance.registry and not image.startswith(
provider_instance.registry
):
raise ValidationError(
Expand Down
2 changes: 1 addition & 1 deletion gateway/main/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@
# mock token value
SETTINGS_AUTH_MOCK_TOKEN = os.environ.get("SETTINGS_AUTH_MOCK_TOKEN", "awesome_token")
SETTINGS_AUTH_MOCKPROVIDER_REGISTRY = os.environ.get(
"SETTINGS_AUTH_MOCKPROVIDER_REGISTRY", "icr.io"
"SETTINGS_AUTH_MOCKPROVIDER_REGISTRY", None
)
# =============

Expand Down

0 comments on commit 65cda73

Please sign in to comment.