Skip to content

Commit b470625

Browse files
committed
Merge branch 'development'
2 parents 055e64a + f41ab70 commit b470625

16 files changed

+584
-253
lines changed

.github/workflows/python_test.yml .github/workflows/test.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: Test
22

3-
on: [push, pull_request]
3+
on: [push]
44

55
jobs:
66

@@ -11,7 +11,7 @@ jobs:
1111
strategy:
1212
max-parallel: 4
1313
matrix:
14-
python-version: [2.7, 3.5, 3.6, 3.7, 3.8, 3.9]
14+
python-version: ['2.7', '3.6', '3.7', '3.8', '3.9']
1515

1616
steps:
1717
- uses: actions/checkout@v2

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
## Development
44

5+
* [#34](https://github.com/rheinwerk-verlag/postgresql-anonymizer/issues/34): Subprocess "run" being used on Python2.7
6+
* [#35](https://github.com/rheinwerk-verlag/postgresql-anonymizer/issues/35): parmap no longer supports Python 2.7
7+
* Dropped Python 3.5 support
8+
* Pinned libraries Python 2.7
9+
* [#32](https://github.com/rheinwerk-verlag/postgresql-anonymizer/pull/32): Fixed pg_dump arguments ([korsar182](https://github.com/korsar182))
10+
* Simplified provider registration (no metaclass usage anymore)
11+
512
## 0.6.1 (2021-07-13)
613

714
* Added missing dependencies for the `setup.py`

CONTRIBUTING.rst

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
Contributing to PostgreSQL Anonymizer
2+
=====================================
3+
4+
First of all: thanks for your interest in this project and taking the time to contribute.
5+
6+
The following document is a small set of guidelines for contributing to this project. They are guidelines and no rules.
7+
8+
Reporting bugs
9+
---------------
10+
11+
If you have found a bug, please check the project's `issue`_ page first and feel free to create a `new issue`_, if no
12+
one else has reported it yet.
13+
14+
Making changes
15+
--------------
16+
17+
Create a fork if you want to make changes or clone the repo if you want a readonly access to the current development
18+
version:
19+
20+
.. code-block:: sh
21+
22+
$ git clone [email protected]:rheinwerk-verlag/postgresql-anonymizer.git
23+
$ cd postgresql-anonymizer
24+
25+
We are using `poetry`_ for development, you may need to install it first:
26+
27+
.. code-block:: sh
28+
29+
$ sudo pip install poetry
30+
31+
Now you can install all development requirements and activate the virtualenv:
32+
33+
.. code-block:: sh
34+
35+
$ poetry install
36+
$ poetry shell
37+
38+
Coding style
39+
------------
40+
41+
We have created an `EditorConfig`_ file for this project that should be usable for most IDEs. Otherwise please make
42+
sure to adhere to the specifications from the config file.
43+
44+
Creating a pull request
45+
-----------------------
46+
47+
Before creating a pull request make sure to check:
48+
49+
* existing docstrings have been updated
50+
* new code has valid docstrings
51+
* whether existing `tests`_ have to be fixed
52+
* new tests have to be written first
53+
* the documentation (in particular the `Sphinx documentation`_) has to be modified
54+
55+
.. _issue: https://github.com/rheinwerk-verlag/postgresql-anonymizer/issues
56+
.. _new issue: https://github.com/rheinwerk-verlag/postgresql-anonymizer/issues/new
57+
.. _poetry: https://python-poetry.org/
58+
.. _EditorConfig: https://editorconfig.org/
59+
.. _tests: https://github.com/rheinwerk-verlag/postgresql-anonymizer/tree/development/tests
60+
.. _Sphinx documentation: https://github.com/rheinwerk-verlag/postgresql-anonymizer/tree/development/docs

README.rst

+24-31
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,12 @@ It uses a YAML file to define which tables and fields should be anonymized and p
1111

1212
.. contents::
1313

14-
.. section-numbering::
15-
1614
Features
1715
--------
1816

1917
* Intentionally compatible with Python 2.7 (for old, productive platforms)
20-
* Anonymize PostgreSQL tables on data level entry with various methods (s. table below)
21-
* Exclude data for anonymization depending on regular expressions
18+
* Anonymize PostgreSQL tables on data level entry with various providers (some examples in the table below)
19+
* Exclude data for anonymization depending on regular expressions or SQL ``WHERE`` clauses
2220
* Truncate entire tables for unwanted data
2321

2422
+----------------+----------------------+-------------------------+----------------------------------+
@@ -43,22 +41,24 @@ Features
4341
| ``uuid_col`` | 00010203-0405-...... | ``uuid4`` | f7c1bd87-4d.... |
4442
+----------------+----------------------+-------------------------+----------------------------------+
4543

46-
* Note: ``faker.unique.[provider]`` only supported on Python 3.5+ (Faker library min. supported python version)
44+
* Note: ``faker.unique.[provider]`` only supported on Python 3.6+ (Faker library min. supported python version)
4745
* Note: ``uuid4`` - only for (native `uuid4`_) columns
4846

4947
See the `documentation`_ for a more detailed description of the provided anonymization methods.
5048

5149
Installation
5250
------------
5351

54-
The default installation method is to use ``pip``::
52+
The default installation method is to use ``pip``:
53+
54+
.. code-block:: sh
5555
5656
$ pip install pganonymize
5757
5858
Usage
5959
-----
6060

61-
::
61+
.. code-block:: sh
6262
6363
usage: pganonymize [-h] [-v] [-l] [--schema SCHEMA] [--dbname DBNAME]
6464
[--user USER] [--password PASSWORD] [--host HOST]
@@ -87,7 +87,9 @@ all anonymization rules for that database. Take a look at the `schema documentat
8787
`YAML sample schema`_.
8888
8989
90-
Example call::
90+
Example calls:
91+
92+
.. code-block:: sh
9193
9294
$ pganonymize --schema=myschema.yml \
9395
--dbname=test_database \
@@ -109,11 +111,15 @@ Database dump
109111
110112
With the ``--dump-file`` argument it is possible to create a dump file after anonymizing the database. Please note,
111113
that the ``pg_dump`` command from the ``postgresql-client-common`` library is necessary to create the dump file for the
112-
database, e.g. under Linux::
114+
database, e.g. under Linux:
115+
116+
.. code-block:: sh
113117
114-
sudo apt-get install postgresql-client-common
118+
$ sudo apt-get install postgresql-client-common
115119
116-
Example call::
120+
Example call:
121+
122+
.. code-block:: sh
117123
118124
$ pganonymize --schema=myschema.yml \
119125
--dbname=test_database \
@@ -123,31 +129,18 @@ Example call::
123129
--dump-file=/tmp/dump.gz \
124130
-v
125131
126-
Quickstart
127-
----------
128-
129-
Clone repo::
130-
131-
$ git clone [email protected]:rheinwerk-verlag/postgresql-anonymizer.git
132-
$ cd postgresql-anonymizer
133-
134-
For making changes and developing pganonymizer, you need to install ``poetry``::
135-
136-
$ sudo pip install poetry
137-
138-
Now you can install all requirements and activate the virtualenv::
139-
140-
$ poetry install
141-
$ poetry shell
142-
143132
Docker
144-
------
133+
~~~~~~
134+
135+
If you want to run the anonymizer within a Docker container you first have to build the image:
145136
146-
If you want to run the anonymizer within a Docker container you first have to build the image::
137+
.. code-block:: sh
147138
148139
$ docker build -t pganonymizer .
149140
150-
After that you can pass a schema file to the container, using Docker volumes, and call the anonymizer::
141+
After that you can pass a schema file to the container, using Docker volumes, and call the anonymizer:
142+
143+
.. code-block:: sh
151144
152145
$ docker run \
153146
-v <path to your schema>:/schema.yml \

pganonymizer/cli.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import yaml
1010

1111
from pganonymizer.constants import DATABASE_ARGS, DEFAULT_SCHEMA_FILE
12-
from pganonymizer.providers import PROVIDERS
12+
from pganonymizer.providers import provider_registry
1313
from pganonymizer.utils import anonymize_tables, create_database_dump, get_connection, truncate_tables
1414

1515

@@ -28,8 +28,8 @@ def get_pg_args(args):
2828
def list_provider_classes():
2929
"""List all available provider classes."""
3030
print('Available provider classes:\n')
31-
for provider_cls in PROVIDERS:
32-
print('{:<10} {}'.format(provider_cls.id, provider_cls.__doc__))
31+
for key, provider_cls in provider_registry.providers.items():
32+
print('{:<10} {}'.format(key, provider_cls.__doc__))
3333

3434

3535
def get_arg_parser():

pganonymizer/exceptions.py

+4
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,9 @@ class InvalidProviderArgument(PgAnonymizeException):
1414
"""Raised if an argument is unknown or invalid for a provider."""
1515

1616

17+
class ProviderAlreadyRegistered(PgAnonymizeException):
18+
"""Raised if another provider with the same id has already been registered."""
19+
20+
1721
class BadDataFormat(PgAnonymizeException):
1822
"""Raised if the anonymized data cannot be copied."""

0 commit comments

Comments
 (0)