Skip to content

Commit da18fc1

Browse files
authored
New auto decryption (#65)
* Refactored lookups and mixins * Added support for auto decryption without crazy managers extra sql. The old custom manager broke support for defer() and only() which this restores. This also adds support for filtering on encrypted fields with any supported built-in WITHOUT having to use annotate / aggregates. * Added support for auto decryption of foreign key tables without additional queries or annotations / aggregations * Added test demostrating support for get_by_natural_key(). Fixes #23 * Added tests demonstrating support for get_or_create() and update_or_create() * Added tests demonstrating support for get_or_create() and update_or_create() * Fix flake8 errors * Updated CHANGELOG * * Updated CHANGELOG to include upgrade instructions * Removed admin, manager, aggregates * Updated tests * Fixes to tests * Improved make file * Fix flake8 * Fixes per feedback on PR #65 (tests for aggregate, distinct, annotate) * Added test for `distinct()` and related documentation for workaround for 2.0.x and lower * Updated CHANGELOG, fixed spelling typo * Added additional assertions for test_aggregates() * Fixed issue with relabel_clone calling DecryptCol which "had" a different constructor signature than Col. Extract the decyrpt sql and cast type from the target instead. django/db/models/expressions.py", line 745, in relabeled_clone return self.__class__(relabels.get(self.alias, self.alias), self.target, self.output_field) * Removed unneed use_for_related_fields = True, use_in_migrations = True * Test for alias of get_col() for DecryptedCol * Code cleanup * Added PyUp safety checks * Separated out dev/maintainers requirements into requirements_dev.txt so it simplifies what is needed for install * * Updated packaging / setup.py to include long description * Added AUTHORS and updated CONTRIBUTING * Fixed makefile * Updated TravisCI to use Xenial to gain Python 3.7 in the matrix * Removed compatibility code for Django 1.7 and lower. The lowest version we support is Django 1.11. * Added HTML for coverage
1 parent aef1c4b commit da18fc1

21 files changed

+680
-448
lines changed

.travis.yml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
language: python
2+
sudo: required
3+
dist: xenial
24
python:
35
- 3.5
46
- 3.6
5-
script: make test
7+
- 3.7
8+
script: make test-coverage
69
notifications:
710
email: false
8-
install:
11+
services:
12+
- postgresql
13+
before_script:
914
- psql -c 'CREATE DATABASE pgcrypto_fields' -U postgres
10-
- pip install -r requirements.txt
15+
install:
16+
- pip install -e .
17+
- pip install -r requirements_dev.txt
1118
- pip install $DJANGO
1219
env:
1320
matrix:

AUTHORS.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Credits
2+
3+
4+
## Development Lead
5+
6+
* Charlie Denton <[email protected]>
7+
* Kévin Etienne <[email protected]>
8+
* Peter J. Farrell <[email protected]>
9+
* Max Peterson <[email protected]>
10+
11+
## Contributors
12+
13+
None yet. Why not be the first?

CHANGELOG.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,17 @@
1-
### 2.3.0
1+
## 2.4.0
2+
3+
* Added auto-decryption of all encrypted fields including FK tables
4+
* Removed django-pgcrypto-fields `aggregates`, `PGPManager` and `PGPAdmin` as they are no longer needed
5+
* Added support for `get_or_create()` and `update_or_create()` (#27)
6+
* Added support for `get_by_natural_key()` (#23)
7+
* Added support for `only()` and `defer()` as they were not supported with `PGPManager`
8+
* Added support for `distinct()` (Django 2.1+ with workaround available for 2.0 and lower)
9+
* Separated out dev requirements from setup.py requirements
10+
* Updated packaging / setup.py to include long description
11+
* Added AUTHORS and updated CONTRIBUTING
12+
* Updated TravisCI to use Xenial to gain Python 3.7 in the matrix
13+
14+
## 2.3.1
215

316
* Added `__range` lookup for Date / DateTime fields (#59)
417
* Remove compatibility for `Django 1.8, 1.9, and 1.10` (#62)
@@ -10,6 +23,10 @@
1023
* Updated Travis config to include Python 3.5 and 3.6
1124
* Refactored lookups and mixins
1225

26+
## 2.3.0
27+
28+
* Invalid release, bump to 2.3.1
29+
1330
## 2.2.0
1431

1532
* Merge `.coveragerc` into `setup.cfg`

CONTRIBUTING.md

Lines changed: 104 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,117 @@
11
# Contributing to Django-PGCrypto-Fields
22

3-
We welcome contributions in many forms:
3+
Contributions are welcome, and they are greatly appreciated! Every little bit
4+
helps, and credit will always be given.
5+
6+
You can contribute in many ways:
47

58
* Code patches and enhancements
69
* Documentation improvements
710
* Bug reports and patch reviews
811

9-
## Running Tests
12+
## Types of Contributions
13+
14+
### Report Bugs
15+
16+
Report bugs at https://github.com/incuna/django-pgcrypto-fields/issues
17+
18+
If you are reporting a bug, please include:
19+
20+
* Your operating system name and version.
21+
* Any details about your local setup that might be helpful in troubleshooting.
22+
* Detailed steps to reproduce the bug.
23+
24+
### Fix Bugs
25+
26+
Look through the GitHub issues for bugs. Anything tagged with "bug" and "help
27+
wanted" is open to whoever wants to implement it.
28+
29+
### Implement Features
30+
31+
Look through the GitHub issues for features. Anything tagged with "enhancement"
32+
and "help wanted" is open to whoever wants to implement it.
33+
34+
### Write Documentation
35+
36+
django-pgcrypto-fields could always use more documentation, whether as part of the
37+
official django-pgcrypto-fields docs, in docstrings, or even on the web in blog posts,
38+
articles, and such.
39+
40+
### Submit Feedback
41+
42+
The best way to send feedback is to file an issue at https://github.com/incuna/django-pgcrypto-fields/issues
43+
44+
If you are proposing a feature:
45+
46+
* Explain in detail how it would work.
47+
* Keep the scope as narrow as possible, to make it easier to implement.
48+
* Remember that this is a volunteer-driven project, and that contributions
49+
are welcome :-)
50+
51+
## Get Started!
52+
53+
Ready to contribute? Here's how to set up `django-pgcrypto-fields` for local development.
54+
55+
1. Fork the `django-pgcrypto-fields` repo on GitHub.
56+
2. Clone your fork locally:
57+
58+
```bash
59+
$ git clone [email protected]:your_name_here/pgcrypto.git
60+
```
61+
62+
3. Install your local copy into a virtualenv. Assuming you have virtualenvwrapper installed, this is how you set up your fork for local development:
63+
64+
```bash
65+
$ mkvirtualenv django-pgcrypto-fields
66+
$ cd django-pgcrypto-fields/
67+
$ pip install -r requirements_dev.txt --upgrade
68+
```
69+
70+
4. Create a branch for local development:
71+
72+
```bash
73+
$ git checkout -b name-of-your-bugfix-or-feature
74+
```
75+
76+
Now you can make your changes locally.
77+
78+
5. When you're done making changes, check that your changes pass flake8 and the
79+
tests:
80+
81+
```bash
82+
$ make test
83+
```
84+
85+
To get flake8 and tox, just pip install them into your virtualenv.
86+
87+
6. Commit your changes and push your branch to GitHub:
88+
89+
```bash
90+
$ git add .
91+
$ git commit -m "Your detailed description of your changes."
92+
$ git push origin name-of-your-bugfix-or-feature
93+
```
94+
95+
7. Submit a pull request through the GitHub website.
1096
11-
* Install requirements to a virtual environment
12-
* Setup a local PostgreSQL server
13-
* Create a PostreSQL database named `pgcrypto_fields`
14-
* In a terminal, run `make test`
97+
### Pull Request Guidelines
1598
99+
Before you submit a pull request, check that it meets these guidelines:
16100
17-
## Releasing to PyPI
101+
1. The pull request should include tests.
102+
2. If the pull request adds functionality, the docs should be updated. Put
103+
your new functionality into a function with a docstring, and add the
104+
feature to the list in README.rst.
105+
3. The pull request should work for Python 3.4, 3.5 and 3.7. Check
106+
https://travis-ci.org/incuna/django-pgcrypto-fields/pull_requests
107+
and make sure that the tests pass for all supported Python versions.
18108
19-
This section only applies to maintainers.
109+
### Deploying
20110
21-
In your virtual environment, run
111+
A reminder for the maintainers on how to deploy.
112+
Make sure all your changes are committed (including an entry in CHANGELOG.md).
113+
Then run:
22114
23-
* `pip install pip --upgrade`
24-
* `pip install setuptools wheel twine`
25-
* `make release`
115+
```bash
116+
$ make release
117+
```

Makefile

Lines changed: 48 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,55 @@
11
SHELL := /bin/bash
22

3+
define BROWSER_PYSCRIPT
4+
import os, webbrowser, sys
5+
6+
try:
7+
from urllib import pathname2url
8+
except:
9+
from urllib.request import pathname2url
10+
11+
webbrowser.open("file://" + pathname2url(os.path.abspath(sys.argv[1])))
12+
endef
13+
export BROWSER_PYSCRIPT
14+
15+
define PRINT_HELP_PYSCRIPT
16+
import re, sys
17+
18+
for line in sys.stdin:
19+
match = re.match(r'^([a-zA-Z_-]+):.*?## (.*)$$', line)
20+
if match:
21+
target, help = match.groups()
22+
print("%-20s %s" % (target, help))
23+
endef
24+
export PRINT_HELP_PYSCRIPT
25+
26+
BROWSER := python -c "$$BROWSER_PYSCRIPT"
27+
328
help:
4-
@echo "Usage:"
5-
@echo " make release | Release to pypi."
6-
@echo " make test | Run the tests."
29+
@python -c "$$PRINT_HELP_PYSCRIPT" < $(MAKEFILE_LIST)
730

8-
release:
31+
lint: ## Check style with flake8
32+
@flake8 .
33+
34+
clean-build: ## Remove build artifacts
35+
rm -r -f dist/*
36+
rm -r -f build/*
37+
rm -fr htmlcov/
38+
39+
build: clean-build ## Builds source and wheel package
940
python setup.py sdist bdist_wheel
41+
ls -l dist
42+
43+
release: ## Package and upload a release
1044
twine upload dist/*
1145

12-
test:
13-
@coverage run ./tests/run.py
14-
@coverage report
15-
@flake8 .
46+
test: clean-build lint ## Run tests quickly with the default Python
47+
./tests/run.py
48+
49+
test-coverage: ## Check code coverage quickly with the default Python
50+
coverage run ./tests/run.py
51+
coverage report -m
52+
53+
test-coverage-html: test-coverage ## Check code coverage quickly with the default Python and show report
54+
coverage html
55+
$(BROWSER) htmlcov/index.html

0 commit comments

Comments
 (0)