Skip to content

Commit

Permalink
feat: support URLField with EncryptedURLField #23
Browse files Browse the repository at this point in the history
  • Loading branch information
tcitry committed Dec 25, 2021
1 parent 0e76046 commit d8ec0fc
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 10 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

## Introduce

A Django model field that encrypt your data when save to DB and decrypt when get from DB. It keeps data always encrypted in DB. Base on AES, it supports query method like `get()` and `filter()` in Django.
A Django model fields collection that encrypt your data when save to and decrypt when get from database. It keeps data always encrypted in database. Base on AES, it supports query method like `get()` and `filter()` in Django.

Mirage can also migrate data from origin column to encrypted column in database with a good performance.

Expand Down Expand Up @@ -83,6 +83,7 @@ Mirage will get the `settings.MIRAGE_SECRET_KEY` first, if not set, mirage will
2. EncryptedCharField
3. EncryptedEmailField
4. EncryptedIntegerField
5. EncryptedURLField(v1.3.0+)

## Data Migrate

Expand Down
4 changes: 4 additions & 0 deletions mirage/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ class EncryptedCharField(EncryptedMixin, models.CharField):
prepared_max_length = 255


class EncryptedURLField(EncryptedMixin, models.URLField):
prepared_max_length = 200


class EncryptedEmailField(EncryptedMixin, models.EmailField):
prepared_max_length = 254

Expand Down
14 changes: 5 additions & 9 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
os.chdir(os.path.normpath(os.path.join(os.path.abspath(__file__), os.pardir)))
setup(
name='django-mirage-field',
version='1.2.4',
version='1.3.0',
install_requires=[
"cryptography",
"tqdm",
],
packages=find_packages(exclude=["tests*"]),
include_package_data=True,
license='MIT License',
description='A Django model field that encrypt your data when save to and decrypt when get from database. It keeps data always encrypted in database.',
description='A Django model fields collection that encrypt your data when save to and decrypt when get from database. It keeps data always encrypted in database.',
long_description_content_type="text/markdown",
long_description=README,
url='https://github.com/luojilab/django-mirage-field',
Expand All @@ -24,19 +24,15 @@
classifiers=[
'Environment :: Web Environment',
'Framework :: Django',
'Framework :: Django :: 1.8',
'Framework :: Django :: 1.9',
'Framework :: Django :: 1.10',
'Framework :: Django :: 1.11',
'Framework :: Django :: 2.0',
'Framework :: Django :: 2.1',
'Framework :: Django :: 2.2',
'Framework :: Django :: 3.0',
'Framework :: Django :: 3.2',
'Framework :: Django :: 4.0',
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.9',
'Topic :: Internet :: WWW/HTTP',
],
)
19 changes: 19 additions & 0 deletions tests/apps/migrations/0003_testmodel_url.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 4.0 on 2021-12-25 03:30

from django.db import migrations
import mirage.fields


class Migration(migrations.Migration):

dependencies = [
('apps', '0002_testmodel_textraw'),
]

operations = [
migrations.AddField(
model_name='testmodel',
name='url',
field=mirage.fields.EncryptedURLField(blank=True, null=True),
),
]
1 change: 1 addition & 0 deletions tests/apps/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ class TestModel(models.Model):
textraw = models.TextField(blank=True, null=True)
integer = fields.EncryptedIntegerField(blank=True, null=True)
email = fields.EncryptedEmailField(blank=True, null=True)
url = fields.EncryptedURLField(blank=True, null=True)
5 changes: 5 additions & 0 deletions tests/test_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class TestField(TestCase):
TEXT = 'hello,text'
INTEGER = 1234567890
EMAIL = 'hello@email.com'
URL = 'https://yindongliang.com'

@classmethod
def setUpTestData(cls):
Expand Down Expand Up @@ -35,3 +36,7 @@ def test_int_field(self):
def test_email_field(self):
self.assertEqual(self.obj.email, self.EMAIL)
self.assertEqual(type(self.obj.email), str)

def test_url_field(self):
self.assertEqual(self.obj.url, self.URL)
self.assertEqual(type(self.obj.url), str)

0 comments on commit d8ec0fc

Please sign in to comment.