From d587f8185bf046cd6d0bf86dd4da26dbe44b4b3f Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Tue, 10 Mar 2020 16:40:42 +0200 Subject: [PATCH] Uids: change uids to be much shorter and base62 for non-chunks. --- .../migrations/0020_auto_20200310_1438.py | 29 +++++++++++++++++++ .../migrations/0021_auto_20200310_1439.py | 24 +++++++++++++++ django_etesync/models.py | 5 ++-- 3 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 django_etesync/migrations/0020_auto_20200310_1438.py create mode 100644 django_etesync/migrations/0021_auto_20200310_1439.py diff --git a/django_etesync/migrations/0020_auto_20200310_1438.py b/django_etesync/migrations/0020_auto_20200310_1438.py new file mode 100644 index 0000000..6949145 --- /dev/null +++ b/django_etesync/migrations/0020_auto_20200310_1438.py @@ -0,0 +1,29 @@ +# Generated by Django 3.0.3 on 2020-03-10 14:38 + +import django.core.validators +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('django_etesync', '0019_collectionmember'), + ] + + operations = [ + migrations.AlterField( + model_name='collection', + name='uid', + field=models.CharField(db_index=True, max_length=44, validators=[django.core.validators.RegexValidator(message='Not a valid UID', regex='[a-zA-Z0-9]{24}')]), + ), + migrations.AlterField( + model_name='collectionitem', + name='uid', + field=models.CharField(db_index=True, max_length=44, validators=[django.core.validators.RegexValidator(message='Not a valid UID', regex='[a-zA-Z0-9]{24}')]), + ), + migrations.AlterField( + model_name='collectionitemchunk', + name='uid', + field=models.CharField(db_index=True, max_length=44, validators=[django.core.validators.RegexValidator(message='Expected a 256bit base64url.', regex='^[a-zA-Z0-9\\-_]{43}=?$')]), + ), + ] diff --git a/django_etesync/migrations/0021_auto_20200310_1439.py b/django_etesync/migrations/0021_auto_20200310_1439.py new file mode 100644 index 0000000..3f1341e --- /dev/null +++ b/django_etesync/migrations/0021_auto_20200310_1439.py @@ -0,0 +1,24 @@ +# Generated by Django 3.0.3 on 2020-03-10 14:39 + +import django.core.validators +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('django_etesync', '0020_auto_20200310_1438'), + ] + + operations = [ + migrations.AlterField( + model_name='collection', + name='uid', + field=models.CharField(db_index=True, max_length=44, validators=[django.core.validators.RegexValidator(message='Not a valid UID', regex='[a-zA-Z0-9]')]), + ), + migrations.AlterField( + model_name='collectionitem', + name='uid', + field=models.CharField(db_index=True, max_length=44, validators=[django.core.validators.RegexValidator(message='Not a valid UID', regex='[a-zA-Z0-9]')]), + ), + ] diff --git a/django_etesync/models.py b/django_etesync/models.py index 3be7b06..7eebd1a 100644 --- a/django_etesync/models.py +++ b/django_etesync/models.py @@ -20,7 +20,8 @@ from django.core.validators import RegexValidator from django.utils.functional import cached_property -UidValidator = RegexValidator(regex=r'[a-zA-Z0-9\-_=]{43}', message='Not a valid UID. Expected a 256bit base64url.') +Base64Url256BitValidator = RegexValidator(regex=r'^[a-zA-Z0-9\-_]{43}=?$', message='Expected a 256bit base64url.') +UidValidator = RegexValidator(regex=r'[a-zA-Z0-9]', message='Not a valid UID') class Collection(models.Model): @@ -61,7 +62,7 @@ def chunk_directory_path(instance, filename): class CollectionItemChunk(models.Model): uid = models.CharField(db_index=True, blank=False, null=False, - max_length=44, validators=[UidValidator]) + max_length=44, validators=[Base64Url256BitValidator]) item = models.ForeignKey(CollectionItem, related_name='chunks', on_delete=models.CASCADE) order = models.CharField(max_length=100, blank=False, null=False) chunkFile = models.FileField(upload_to=chunk_directory_path, max_length=150, unique=True)