diff --git a/.github/workflows/lint-and-test.yml b/.github/workflows/lint-and-test.yml index ee686ef..d23c565 100644 --- a/.github/workflows/lint-and-test.yml +++ b/.github/workflows/lint-and-test.yml @@ -26,7 +26,7 @@ jobs: test: strategy: matrix: - python_version: ['3.10', 3.11, 3.12] + python_version: ["3.10", 3.11, 3.12] django_version: [3.2, 4.0, 4.1.0, 4.2.2, 5.0, 5.1.4] exclude: - python_version: 3.12 @@ -34,24 +34,24 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v3 - - name: Set up Python ${{ matrix.python_version }} - uses: actions/setup-python@v3 - with: - python-version: ${{ matrix.python_version }} + - name: Set up Python ${{ matrix.python_version }} + uses: actions/setup-python@v3 + with: + python-version: ${{ matrix.python_version }} - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install -q Django==${{ matrix.django_version }} - pip install coverage pytest - if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -q Django==${{ matrix.django_version }} + pip install coverage pytest + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - - name: Run tests - run: | - coverage3 run --source='./encrypted_fields' manage.py test - coverage xml + - name: Run tests + run: | + coverage3 run --source='./encrypted_fields' manage.py test + coverage xml # - name: "Upload coverage to Artifact" # uses: actions/upload-artifact@v4 diff --git a/.gitignore b/.gitignore index f648e69..d229707 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,4 @@ dist/ .idea .pypirc .ruff_cache -.venv \ No newline at end of file +.venv diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..48dbd4f --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,50 @@ +# See https://pre-commit.com for more information +# See https://pre-commit.com/hooks.html for more hooks + +# exclude docs and static css +exclude: | + (?x)^( + package_test/.* + )$ +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.6.0 + hooks: + - id: trailing-whitespace # Trims trailing whitespace. + args: [--markdown-linebreak-ext=md] + - id: check-ast # Checks whether the files parse as valid python. + - id: check-case-conflict # Checks for files that would conflict in case-insensitive filesystems. + - id: check-json # Attempts to load all json files to verify syntax + - id: check-merge-conflict # Check for files that contain merge conflict strings + - id: check-xml # Attempts to load all xml files to verify syntax + - id: check-toml # Attempts to load all toml files to verify syntax + - id: check-yaml # Attempts to load all yaml files to verify syntax + args: [--unsafe] + - id: end-of-file-fixer # Makes sure files end in a newline and only a newline. + - id: check-symlinks # Checks for symlinks which do not point to anything + - id: debug-statements # Check for debugger imports and py37+ breakpoint() calls in python source + - id: check-added-large-files # Prevent giant files from being committed + + - repo: https://github.com/Lucas-C/pre-commit-hooks.git + rev: v1.5.5 + hooks: + - id: remove-crlf # Replace CRLF end-lines by LF ones before committing + - id: remove-tabs # Replace tabs by whitespaces before committing + + - repo: https://github.com/pre-commit/pygrep-hooks + rev: v1.10.0 + hooks: + - id: python-use-type-annotations + + - repo: https://github.com/pre-commit/mirrors-prettier + rev: v3.1.0 + hooks: + - id: prettier # Autoformat yaml and markdown files + types_or: [yaml, markdown] + + - repo: https://github.com/asottile/pyupgrade + rev: v3.16.0 + hooks: + - id: pyupgrade + name: pyupgrade + args: [--py312-plus] diff --git a/LICENCE.txt b/LICENCE.txt index 5b922ab..bf8f300 100644 --- a/LICENCE.txt +++ b/LICENCE.txt @@ -17,4 +17,4 @@ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md index dfd9e44..9c89443 100644 --- a/README.md +++ b/README.md @@ -1,31 +1,36 @@ [![Pypi Package](https://badge.fury.io/py/django-fernet-encrypted-fields.png)](http://badge.fury.io/py/django-fernet-encrypted-fields) [![Jazzband](https://jazzband.co/static/img/badge.svg)](https://jazzband.co/) - ### Django Fernet Encrypted Fields This package was created as a successor to [django-encrypted-fields](https://github.com/defrex/django-encrypted-fields). #### Getting Started + ```shell $ pip install django-fernet-encrypted-fields ``` + In your `settings.py`, set random SALT_KEY + ```python SALT_KEY = '0123456789abcdefghijklmnopqrstuvwxyz' ``` Then, in `models.py` + ```python from encrypted_fields.fields import EncryptedTextField class MyModel(models.Model): text_field = EncryptedTextField() ``` + Use your model as normal and your data will be encrypted in the database. #### Rotating SALT keys -You can rotate salt keys by turning the ```SALT_KEY``` settings.py entry into a list. The first key will be used to encrypt all new data, and decryption of existing values will be attempted with all given keys in order. This is useful for key rotation: place a new key at the head of the list for use with all new or changed data, but existing values encrypted with old keys will still be accessible + +You can rotate salt keys by turning the `SALT_KEY` settings.py entry into a list. The first key will be used to encrypt all new data, and decryption of existing values will be attempted with all given keys in order. This is useful for key rotation: place a new key at the head of the list for use with all new or changed data, but existing values encrypted with old keys will still be accessible ```python SALT_KEY = [ @@ -41,7 +46,6 @@ for obj in MuModel.objects.all(): obj.save() ``` - #### Available Fields Currently build in and unit-tested fields. They have the same APIs as their non-encrypted counterparts. @@ -57,11 +61,11 @@ Currently build in and unit-tested fields. They have the same APIs as their non- ### Compatible Django Version -| Compatible Django Version |Specifically tested| -|---------------------------|---| -| `3.2` |:heavy_check_mark:| -| `4.0` |:heavy_check_mark:| -| `4.1` |:heavy_check_mark:| -| `4.2` |:heavy_check_mark:| -| `5.0` |:heavy_check_mark:| -| `5.1` |:heavy_check_mark:| +| Compatible Django Version | Specifically tested | +| ------------------------- | ------------------- | +| `3.2` | :heavy_check_mark: | +| `4.0` | :heavy_check_mark: | +| `4.1` | :heavy_check_mark: | +| `4.2` | :heavy_check_mark: | +| `5.0` | :heavy_check_mark: | +| `5.1` | :heavy_check_mark: | diff --git a/pyproject.toml b/pyproject.toml index 5754d10..8a2f802 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -22,4 +22,4 @@ strict = true warn_unreachable = true warn_no_return = true ignore_missing_imports = true -disallow_untyped_decorators = false \ No newline at end of file +disallow_untyped_decorators = false diff --git a/setup.py b/setup.py index 3ee0343..74190ba 100644 --- a/setup.py +++ b/setup.py @@ -1,4 +1,3 @@ -from __future__ import print_function from setuptools import setup setup(