Skip to content

Commit

Permalink
OptionalSchemeURLValidator 🤥
Browse files Browse the repository at this point in the history
  • Loading branch information
Sibyx committed Feb 25, 2024
1 parent 570ff1c commit ba41dd2
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 1.11.1 : 2024-02-25

- **Fixed**: [Validate Docker image path #6](https://github.com/FIIT-Databases/tester/issues/6)

## 1.11.0 : 2024-02-11

Bunch of funky updates into an upcoming summer course! Some attempts were made to make the task result better readable.
Expand Down
24 changes: 24 additions & 0 deletions apps/core/migrations/0014_alter_task_image.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated by Django 5.0.2 on 2024-02-25 21:44

import apps.core.validators
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("core", "0013_alter_taskrecord_status"),
]

operations = [
migrations.AlterField(
model_name="task",
name="image",
field=models.CharField(
help_text="Path to GitHub hosted docker image. Example: ghcr.io/fiit-databases/dbs-python-example:master",
max_length=255,
validators=[apps.core.validators.OptionalSchemeURLValidator()],
verbose_name="Docker Image",
),
),
]
2 changes: 2 additions & 0 deletions apps/core/models/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from apps.core.models.assignment import Assignment
from apps.core.models.base import BaseModel
from apps.core.validators import OptionalSchemeURLValidator


class Task(BaseModel):
Expand All @@ -32,6 +33,7 @@ class Executor(models.TextChoices):
help_text=_("Path to GitHub hosted docker image. Example: ghcr.io/fiit-databases/dbs-python-example:master"),
verbose_name=_("Docker Image"),
max_length=255,
validators=[OptionalSchemeURLValidator()],
)
message = models.TextField(null=True, editable=False)
output = models.TextField(null=True, editable=False)
Expand Down
9 changes: 9 additions & 0 deletions apps/core/validators.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from django.core.validators import URLValidator


class OptionalSchemeURLValidator(URLValidator):
def __call__(self, value):
if "://" not in value:
# Validate as if it were http://
value = "http://" + value
super(OptionalSchemeURLValidator, self).__call__(value)
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "dbs_tester"
version = "1.11.0"
version = "1.11.1"
description = "DBS tester application"
authors = [
"Jakub Dubec <[email protected]>"
Expand Down

0 comments on commit ba41dd2

Please sign in to comment.