Skip to content

Commit

Permalink
rename package, update for python 3, switch tests to tox/travis-ci
Browse files Browse the repository at this point in the history
  • Loading branch information
lanshark committed Mar 14, 2017
1 parent 72abb28 commit 46be00d
Show file tree
Hide file tree
Showing 26 changed files with 181 additions and 83 deletions.
5 changes: 5 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[run]
include = encrypted_fields/*
omit = *migrations*, *tests*
plugins =
django_coverage_plugin
32 changes: 28 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,35 @@
# Logs
logs
*.log

# Basics
*.py[cod]
__pycache__

# Translations
*.mo
*.pot
*.pyc

# sqlite
*.sqlite
.DS_Store
*~
*.sqlite3
.idea

# Windows
.DS_Store

# Python Setup
dist
*.egg-info
build

# Unit test / coverage reports
.coverage
.tox

# Vim
*~
*.swp
*.swo

# pyenv
.python-version
19 changes: 19 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
sudo: true
before_install:
- sudo apt-get update -qq
- sudo apt-get install -qq build-essential gettext python-dev zlib1g-dev libpq-dev xvfb
- sudo apt-get install -qq libtiff4-dev libjpeg8-dev libfreetype6-dev liblcms1-dev libwebp-dev
- sudo apt-get install -qq graphviz-dev python-setuptools python3-dev python-virtualenv python-pip
- sudo apt-get install -qq firefox automake libtool libreadline6 libreadline6-dev libreadline-dev
- sudo apt-get install -qq libsqlite3-dev libxml2 libxml2-dev libssl-dev libbz2-dev wget curl llvm
language: python
cache:
pip
install:
pip install -r requirements.txt
python:
- "2.7"
- "3.5"
- "3.6"
script:
python manage.py test
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2015 FounderTherapy
Copyright (c) 2015 FounderTherapy, 2017 LANshark Consulting Group, LLC.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
29 changes: 16 additions & 13 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
Django Cryptographic Fields
===========================
Django Encrypted Fields
=======================

.. image:: https://circleci.com/gh/foundertherapy/django-cryptographic-fields.png
:target: https://circleci.com/gh/foundertherapy/django-cryptographic-fields
.. image:: https://travis-ci.org/lanshark/django-encrypted-fields.png
:target: https://travis-ci.org/lanshark/django-encrypted-fields

About
-----

``django-cryptographic-fields`` is set of fields that wrap standard Django
This is a fork of https://github.com/foundertherapy/django-cryptographic-fields.
It has been renamed, and updated to properly support Python3 and latest versions
of Django.

``django-encrypted-fields`` is set of fields that wrap standard Django
fields with encryption provided by the python cryptography library. These
fields are much more compatible with a 12-factor design since they take their
encryption key from the settings file instead of a file on disk used by
Expand All @@ -22,16 +26,16 @@ into a file that keyczar can read.
Getting Started
---------------

$ pip install django-cryptographic-fields
$ pip install django-encrypted-fields

Add "cryptographic_fields" to your INSTALLED_APPS setting like this:
Add "encrypted_fields" to your INSTALLED_APPS setting like this:

INSTALLED_APPS = (
...
'cryptographic_fields',
'encrypted_fields',
)

``django-cryptographic-fields`` expects the encryption key to be specified
``django-encrypted-fields`` expects the encryption key to be specified
using ``FIELD_ENCRYPTION_KEY`` in your project's ``settings.py`` file. For
example, to load it from the local environment:

Expand All @@ -40,9 +44,9 @@ example, to load it from the local environment:
FIELD_ENCRYPTION_KEY = os.environ.get('FIELD_ENCRYPTION_KEY', '')

To use an encrypted field in a Django model, use one of the fields from the
``cryptographic_fields`` module:
``encrypted_fields`` module:

from cryptographic_fields.fields import EncryptedCharField
from encrypted_fields.fields import EncryptedCharField

class EncryptedFieldModel(models.Model):
encrypted_char_field = EncryptedCharField(max_length=100)
Expand All @@ -60,11 +64,10 @@ Generating an Encryption Key
----------------------------

There is a Django management command ``generate_encryption_key`` provided
with the ``cryptographic_fields`` library. Use this command to generate a new
with the ``encrypted_fields`` library. Use this command to generate a new
encryption key to set as ``settings.FIELD_ENCRYPTION_KEY``.

./manage.py generate_encryption_key

Running this command will print an encryption key to the terminal, which can
be configured in your environment or settings file.

3 changes: 0 additions & 3 deletions circle.yml

This file was deleted.

1 change: 0 additions & 1 deletion cryptographic_fields/__init__.py

This file was deleted.

1 change: 1 addition & 0 deletions encrypted_fields/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = '0.5.2'
16 changes: 11 additions & 5 deletions cryptographic_fields/fields.py → encrypted_fields/fields.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from __future__ import unicode_literals

import sys

import django.db
import django.db.models
from django.utils.six import PY2, string_types
Expand All @@ -13,6 +11,15 @@
import cryptography.fernet


def parse_key(key):
"""
If the key is a string we need to ensure that it can be decoded
:param key:
:return:
"""
return cryptography.fernet.Fernet(key)


def get_crypter():
configured_keys = getattr(settings, 'FIELD_ENCRYPTION_KEY')

Expand All @@ -22,10 +29,10 @@ def get_crypter():
try:
# Allow the use of key rotation
if isinstance(configured_keys, (tuple, list)):
keys = [cryptography.fernet.Fernet(str(k)) for k in configured_keys]
keys = [parse_key(k) for k in configured_keys]
else:
# else turn the single key into a list of one
keys = [cryptography.fernet.Fernet(str(configured_keys)), ]
keys = [parse_key(configured_keys), ]
except Exception as e:
raise ImproperlyConfigured(
'FIELD_ENCRYPTION_KEY defined incorrectly: {}'.format(str(e)))
Expand Down Expand Up @@ -97,7 +104,6 @@ def deconstruct(self):


class EncryptedCharField(EncryptedMixin, django.db.models.CharField):

pass


Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.core.management.base import BaseCommand
from django.utils.six import PY2

import cryptography.fernet

Expand All @@ -8,5 +9,7 @@ class Command(BaseCommand):

def handle(self, *args, **options):
key = cryptography.fernet.Fernet.generate_key()
# SAS - how to properly do for both Python 2 and Python 3
self.stdout.write(key, ending=b'\n')
if PY2:
self.stdout.write(key)
else:
self.stdout.write(key, ending=b'\n')
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import cryptography.fernet

import fields
from . import fields


class TestSettings(TestCase):
Expand Down
24 changes: 11 additions & 13 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
setuptools
coverage
cryptography
setuptools==34.3.2
cryptography==1.8.1
Django>=1.9.4
django_coverage
flake8
ipython
mock
pep8
psycopg2
pyflakes
pytz
yolk
freezegun
freezegun==0.3.8
six==1.10.0
# for testing...
coverage==4.3.4
django_coverage==1.2.4
mccabe==0.6.1
mock==2.0.0
psycopg2==2.7.1
tox==2.6.0
11 changes: 1 addition & 10 deletions settings_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
'django.contrib.contenttypes',
'django.contrib.admin',
'django_coverage',
'cryptographic_fields',
'encrypted_fields',
'testapp',
)

Expand All @@ -23,15 +23,6 @@
'NAME': 'testapp.sqlite3',
}
}
# DATABASES = {
# 'default': {
# 'ENGINE': 'django.db.backends.postgresql_psycopg2',
# 'USERNAME': 'dana',
# 'HOST': '127.0.0.1',
# 'PORT': 5432,
# 'NAME': 'test',
# }
# }

MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
Expand Down
4 changes: 2 additions & 2 deletions settings_circleci.py → settings_travis.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
'django.contrib.contenttypes',
'django.contrib.admin',
'django_coverage',
'cryptographic_fields',
'encrypted_fields',
'testapp',
)

Expand All @@ -23,7 +23,7 @@
'USERNAME': 'ubuntu',
'HOST': '127.0.0.1',
'PORT': 5432,
'NAME': 'circle_test',
'NAME': 'travis_test',
}
}

Expand Down
7 changes: 7 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[flake8]
max-line-length = 120
exclude = .tox,.git,*/migrations/*,*/static/CACHE/*,docs,node_modules

[pep8]
max-line-length = 120
exclude=.tox,.git,*/migrations/*,*/static/CACHE/*,docs,node_modules
40 changes: 34 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from setuptools import setup, find_packages


with open('cryptographic_fields/__init__.py', 'r') as init_file:
with open('encrypted_fields/__init__.py', 'r') as init_file:
version = re.search(
'^__version__ = [\'"]([^\'"]+)[\'"]',
init_file.read(),
Expand All @@ -17,7 +17,7 @@
os.chdir(os.path.normpath(os.path.join(os.path.abspath(__file__), os.pardir)))

setup(
name='django-cryptographic-fields',
name='django-encrypted-fields',
version=version,
packages=find_packages(),
license='MIT',
Expand All @@ -26,13 +26,41 @@
'A set of django fields that internally are encrypted using the '
'cryptography.io native python encryption library.'
),
url='http://github.com/foundertherapy/django-cryptographic-fields/',
download_url='https://github.com/foundertherapy/django-cryptographic-fields/archive/' + version + '.tar.gz',
author='Dana Spiegel',
author_email='[email protected]',
long_description=open('README.rst').read(),
url='http://github.com/lanshark/django-encrypted-fields/',
download_url='https://github.com/lanshark/django-encrypted-fields/archive/' + version + '.tar.gz',
author='Scott Sharkey',
author_email='[email protected]',
maintainer="Scott Sharkey",
maintainer_email="[email protected]",
install_requires=[
'Django>=1.7',
'cryptography>=0.8.2',
'six',
],
tests_require=['tox'],
keywords=['encryption', 'django', 'fields', ],
classifiers=[
'Development Status :: 5 - Production/Stable',
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
'Environment :: Web Environment',
'Operating System :: OS Independent',
"Operating System :: POSIX",
"Operating System :: Unix",
"Topic :: Internet :: WWW/HTTP",
'Topic :: Security',
'Topic :: System :: Systems Administration :: Authentication/Directory',
"Programming Language :: Python",
'Programming Language :: Python :: 2',
"Programming Language :: Python :: 2.7",
'Programming Language :: Python :: 3',
"Programming Language :: Python :: 3.4",
"Programming Language :: Python :: 3.5",
'Programming Language :: Python :: 3.6',
'Framework :: Django',
'Framework :: Django :: 1.8',
'Framework :: Django :: 1.9',
'Framework :: Django :: 1.10',
],
)
2 changes: 2 additions & 0 deletions testapp/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# -*- coding: utf-8 -*-

1 change: 1 addition & 0 deletions testapp/admin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
from django.contrib import admin

# Register your models here.
Loading

0 comments on commit 46be00d

Please sign in to comment.