From 4c055ac236b242c600166e4681ec38251927461d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20D=C3=B6tsch?= Date: Wed, 15 May 2024 16:50:42 +0200 Subject: [PATCH] Allow trailing "_" in hostname attribute. (#354) Needed e.g. for domains like "_acme-challenge.example.com" --- .docker/web/entrypoint.sh | 2 +- serveradmin.sql | 2 +- .../migrations/0018_alter_server_hostname.py | 34 +++++++++++++++++++ serveradmin/serverdb/models.py | 2 +- 4 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 serveradmin/serverdb/migrations/0018_alter_server_hostname.py diff --git a/.docker/web/entrypoint.sh b/.docker/web/entrypoint.sh index b1f6b779..02631a63 100755 --- a/.docker/web/entrypoint.sh +++ b/.docker/web/entrypoint.sh @@ -7,7 +7,7 @@ python3 -m pipenv install --dev # Wait for database to be available before running migrations until pg_isready -h "$POSTGRES_HOST" -U "$POSTGRES_USER" &> /dev/null; do - echo "Waiting for database to be ready ..." + echo "Waiting for database to be ready on ${POSTGRES_HOST} ..." sleep 5 done diff --git a/serveradmin.sql b/serveradmin.sql index d20ebae2..4517425f 100644 --- a/serveradmin.sql +++ b/serveradmin.sql @@ -885,7 +885,7 @@ CREATE TABLE public.server ( hostname character varying(254) NOT NULL, intern_ip inet, servertype_id character varying(32) NOT NULL, - CONSTRAINT server_hostname_check CHECK (((hostname)::text ~ '\A(\*\.)?([a-z0-9]+(\.|-+))*[a-z0-9]+\Z'::text)) + CONSTRAINT server_hostname_check CHECK (((hostname)::text ~ '\A(\*\.)?([a-z0-9_]+(\.|-+))*[a-z0-9]+\Z'::text)) ); diff --git a/serveradmin/serverdb/migrations/0018_alter_server_hostname.py b/serveradmin/serverdb/migrations/0018_alter_server_hostname.py new file mode 100644 index 00000000..bcc3aad1 --- /dev/null +++ b/serveradmin/serverdb/migrations/0018_alter_server_hostname.py @@ -0,0 +1,34 @@ +# Generated by Django 3.2.23 on 2024-01-04 08:23 + +import django.core.validators +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('serverdb', '0017_inet_family_choice'), + ] + + operations = [ + migrations.AlterField( + model_name='server', + name='hostname', + field=models.CharField(max_length=254, unique=True, validators=[django.core.validators.RegexValidator('\\A(\\*\\.)?([a-z0-9_]+(\\.|-+))*[a-z0-9]+\\Z', 'Invalid hostname')]), + ), + migrations.RunSQL( + sql=( + "ALTER TABLE server " + "DROP CONSTRAINT server_hostname_check, " + "ADD CONSTRAINT server_hostname_check " + "CHECK (hostname::text ~ '\A(\*\.)?([a-z0-9_]+(\.|-+))*[a-z0-9]+\Z'::text);" + ), + reverse_sql=( + "ALTER TABLE server " + "DROP CONSTRAINT server_hostname_check, " + "ADD CONSTRAINT server_hostname_check " + "CHECK (hostname::text ~ '\A(\*\.)?([a-z0-9]+(\.|-+))*[a-z0-9]+\Z'::text);" + ) + ), + ] + diff --git a/serveradmin/serverdb/models.py b/serveradmin/serverdb/models.py index ffb0cc12..ef20f870 100644 --- a/serveradmin/serverdb/models.py +++ b/serveradmin/serverdb/models.py @@ -58,7 +58,7 @@ HOSTNAME_VALIDATORS = [ RegexValidator( - r'\A(\*\.)?([a-z0-9]+(\.|-+))*[a-z0-9]+\Z', 'Invalid hostname' + r'\A(\*\.)?([a-z0-9_]+(\.|-+))*[a-z0-9]+\Z', 'Invalid hostname' ), ]