mirror of
https://github.com/jazzband/django-fernet-encrypted-fields.git
synced 2026-03-16 22:40:27 +00:00
Add pre-commit config and fix for it
This commit is contained in:
parent
a422d6c4b8
commit
63362d5804
7 changed files with 84 additions and 31 deletions
32
.github/workflows/lint-and-test.yml
vendored
32
.github/workflows/lint-and-test.yml
vendored
|
|
@ -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
|
||||
|
|
|
|||
50
.pre-commit-config.yaml
Normal file
50
.pre-commit-config.yaml
Normal file
|
|
@ -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]
|
||||
26
README.md
26
README.md
|
|
@ -1,31 +1,36 @@
|
|||
[](http://badge.fury.io/py/django-fernet-encrypted-fields)
|
||||
[](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: |
|
||||
|
|
|
|||
1
setup.py
1
setup.py
|
|
@ -1,4 +1,3 @@
|
|||
from __future__ import print_function
|
||||
from setuptools import setup
|
||||
|
||||
setup(
|
||||
|
|
|
|||
Loading…
Reference in a new issue