Skip to content

Commit

Permalink
Update and fix doc
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonMellerin committed Nov 20, 2023
1 parent 5eefd79 commit e76ea8f
Show file tree
Hide file tree
Showing 10 changed files with 240 additions and 61 deletions.
4 changes: 2 additions & 2 deletions docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default defineConfig({
{ text: 'Home', link: '/' },
],
editLink: {
pattern: 'https://gitlab.makina-corpus.net/chalets/OMAE/-/tree/main/docs/content/:path',
pattern: 'https://github.com/makinacorpus/DbToolsBundle/blob/main/docs/content/:path',
text: 'Edit this page on Github'
},
docFooter: {
Expand All @@ -39,7 +39,7 @@ export default defineConfig({
copyright: 'Copyright © 2023-present <a href="https://makina-corpus.com">Makina Corpus</a>'
},
socialLinks: [
{ icon: 'github', link: 'https://github.com/makinacorpus/db-tools-bundle' }
{ icon: 'github', link: 'https://github.com/makinacorpus/DbToolsBundle' }
],
sidebar: [
{
Expand Down
20 changes: 10 additions & 10 deletions docs/content/anonymization/core-anonymizers.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Core Anonymizers

This page list the common purpose *Anonymizers* provided by the *DbToolsBundle*.
This page list all *Anonymizers* provided by *DbToolsBundle*.

[[toc]]

Expand Down Expand Up @@ -44,7 +44,7 @@ user:
```
:::

Or like this, with the domain option
Or, with the domain option:

::: code-group
```php [Attribute]
Expand Down Expand Up @@ -80,7 +80,7 @@ user:

## PasswordAnonymizer

This *Anonymizer* give you way to set the same password for each one of your users. It is based on
This *Anonymizer* give you a way to set the same password for each one of your users. It is based on
the [Symfony PasswordHasher Component](https://symfony.com/doc/current/security/passwords.html).

Options are :
Expand Down Expand Up @@ -281,9 +281,9 @@ user:
:::

:::warning
If you use the same sample on multiple columns or if you use a large sample, it could be more efficient and convinient
to create your own custom anonymizer, see the [Custom Anonymizers](/anonymization/custom-anonymizers) section to learn
how to do that.
If you use the same sample multiple times, if you use a large sample or if you use a generated one, it could be
more efficient and convinient to create your own custom anonymizer, see the [Custom Anonymizers](/anonymization/custom-anonymizers)
section to learn how to do that.
:::

## LastnameAnonymizer
Expand Down Expand Up @@ -322,7 +322,7 @@ user:

## FirstnameAnonymizer

Works like the StringAnonymizer, but with a provided sample of 1000 worldwide lastnames.
Works like the StringAnonymizer, but with a provided sample of 1000 worldwide firstnames.

::: code-group
```php [Attribute]
Expand Down Expand Up @@ -356,10 +356,10 @@ user:

## AddressAnonymizer

This *Anonymizer* is multi-column. It let you anonymize, at once, mutiple columns on one table
This *Anonymizer* is multicolumn. It let you anonymize, at once, mutiple columns on one table
that represent different parts of a postal address.

Each part will be fill with a coherent random address from a sample 300 addresses around the world.
Each part will be fill with a coherent random address from a sample of 300 addresses around the world.

Available parts are :

Expand Down Expand Up @@ -434,5 +434,5 @@ user:

:::tip
Note that you don't have to provide a column for each part. You can use this *Anonymizer* to
only anonymize some parts of an address. To do so, just remove options you don't want in the example below.
only anonymize some parts of an address. To do so, remove options you don't want in the example below.
:::
104 changes: 98 additions & 6 deletions docs/content/anonymization/custom-anonymizers.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# Custom Anonymizers

The *DbToolsBundle* allows you to create your own *Anonymizers*.
## Basics

To create one, you only have to add a class in the `src/Anonymizer` directory
that extends `AbstractAnonymizer` and add the `AsAnonymizer` attribute.
The *DbToolsBundle* allows you to create your own *Anonymizers*.

```php
// src/Anonymizer/MyAnonymizer.php
To create one, you will need to

declare(strict_types=1);
1. add a class in the `src/Anonymizer` directory extends `AbstractAnonymizer`
2. add the `AsAnonymizer` attribute on it

```php
namespace App\Anonymizer;

use MakinaCorpus\DbToolsBundle\Anonymizer\AbstractAnonymizer;
Expand Down Expand Up @@ -40,3 +40,95 @@ To inspire you, browse existing *Anonymizers* in:
You can tell the *DbToolsBundle* your *Custom Anonymizers* live in a different directory
with the [*Anonymizer paths* configuration](../configuration#anonymizer-paths).
:::

## Enum Anonymizers

A classic need is to anonymize a column filling it with a random value from a large sample.

For example, it's what is done by the *FirstNameAnonymizer* and the *LastNameAnonymizer* which use
a sample of 1000 items.
If you need to create such a anonymizer, extend the *AbstractEnumAnonymizer*.
Here is a complete example:
```php
namespace App\Anonymizer;
use MakinaCorpus\DbToolsBundle\Anonymizer\AbstractEnumAnonymizer;
use MakinaCorpus\DbToolsBundle\Attribute\AsAnonymizer;
#[AsAnonymizer(
name: 'my_enum_anonymizer',
pack: 'my_app',
description: <<<TXT
Describe here if you want how your anonymizer works.
TXT
)]
class MyEnumAnonymizer extends AbstractEnumAnonymizer
{
/**
* {@inheritdoc}
*/
protected function getSample(): array
{
// Generate here your sample.
return ['Foo', 'Bar', 'Baz'];
}
}
```
## Mutlicolumn Anonymizers
As for an enum anonymizer, if you need to create a mutlicolumn anonymizer based on a big sample, you can extend the
*AbstractMultipleColumnAnonymizer*.
Here is a complete example:
```php
namespace App\Anonymizer;
use MakinaCorpus\DbToolsBundle\Anonymizer\AbstractMultipleColumnAnonymizer;
use MakinaCorpus\DbToolsBundle\Attribute\AsAnonymizer;
#[AsAnonymizer(
name: 'my_multicolumn_anonymizer',
pack: 'my_app',
description: <<<TXT
Describe here if you want how your anonymizer works.
TXT
)]
class MyMulticolumnAnonymizer extends AbstractMultipleColumnAnonymizer
{
/**
* @inheritdoc
*/
protected function getColumnNames(): array
{
// Declare here name fo each part of your multicolumn
// anonymizer
return [
'part_one',
'part_two',
'part_three',
];
}
/**
* {@inheritdoc}
*/
protected function getSample(): array
{
// Generate here your sample.
return [
['Foo', 'Bar', 'Baz'],
['Foo1', 'Bar1', 'Baz1'],
['Foo2', 'Bar2', 'Baz2'],
['Foo3', 'Bar3', 'Baz3'],
];
}
}
```
93 changes: 79 additions & 14 deletions docs/content/anonymization/essentials.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ The *DbToolsBundle* provides a convinient way to anonymize data from your databa
After some configurations, launching `console db-tools:anonymize` will be all you need to
replace sensitive data by random and/or hashed ones in your database.

There is two ways to tell the DbToolsBundle how it should anonymize your data:
There is two ways to tell the *DbToolsBundle* how it should anonymize your data:

1. you can use **attributes** on class and properties on your Doctrine Entities
2. you can configure it with a **YAML** file
1. you can use **PHP attributes** on Doctrine Entities' classes and properties
2. you can declare it with a **YAML** file

::: tip
The *DbToolsBundle* does not only work with Doctrine Entities to anonymize data. **You can use it with
any database**, all you need is a DBAL connection, all you will need is
The *DbToolsBundle* does not only work with Doctrine Entities to anonymize data. You can use it with
*any* database, all you need is a DBAL connection.

In such case, the YAML configuration is the only available option.
In such case, the [YAML configuration](../configuration#anonymization) is the only available option.
:::

If Doctrine ORM is enabled, the *DbToolsBundle* will automatically look for attributes on your entities.
Expand All @@ -27,21 +27,22 @@ represents an email address.

Each *Anonymizer* could take options to specify how it should work.

All you need to do to configure Anonymization is map each column you want to anonymize with a specific anonymizer.
In others word, all you need to do to configure Anonymization is map each column you want to anonymize with a specific anonymizer.

## Example

The best way to understand how it works is to see a simple example: let's take an entity `User`.

This entity has several fields we want to anonymize, and others that do not represent sensitive data:
This entity has several fields we want to anonymize, and others that we don't:

- `id`: Serial
- `emailAddress`: An email address that we want to anonymize
- `age`: An integer that we want to randomize
- `level`: A string ('none', 'bad', 'good' or 'expert') that we want to randomize
- `secret`: A string that we want to hash
- `emailAddress`: An email address **that we want to anonymize**
- `age`: An integer **that we want to randomize**
- `level`: A string ('none', 'bad', 'good' or 'expert') **that we want to randomize**
- `secret`: A string **that we want to hash**
- `lastLogin`: A DateTime we want to keep intact

Here is how you can declare this configruation with PHP attributes and with YAML:

::: code-group
```php [Attribute]
Expand Down Expand Up @@ -99,7 +100,71 @@ user:

## Multicolumn Anonymizers

@todo
Some *Anonymizers* are mutlicolumn. For example the *AddressAnonymizer* can, by himself, anonymize 6 columns.

*Multicolumn anonymizers* are usefull when you want to keep coherent data after anonymization.

When using PHP attributes, those anonymizers should be put on class:

::: code-group
```php [Attribute]
namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;
use MakinaCorpus\DbToolsBundle\Attribute\Anonymize;

#[ORM\Entity()]
#[ORM\Table(name: '`user`')]
#[Anonymize(type: 'address', options: [ // [!code ++]
'street_address' => 'street', // [!code ++]
'secondary_address': 'street_second_line' // [!code ++]
'postal_code' => 'zip_code', // [!code ++]
'locality' => 'city', // [!code ++]
'region' => 'region' // [!code ++]
'country' => 'country', // [!code ++]
])] // [!code ++]
class User
{
// ...

#[ORM\Column(length: 255)]
private ?string $street = null;

#[ORM\Column(length: 255)]
private ?string $streetSecondLine = null;

#[ORM\Column(length: 255)]
private ?string $zipCode = null;

#[ORM\Column(length: 255)]
private ?string $city = null;

#[ORM\Column(length: 255)]
private ?string $region = null;

#[ORM\Column(length: 255)]
private ?string $country = null;

// ...
}
```

```yaml [YAML]
# config/anonymization.yaml
user:
address:
target: table
anonymizer: address
options:
street_address: 'street'
secondary_address: 'street_address_2'
postal_code: 'zip_code'
locality: 'city'
region: 'region'
country: 'country'
#...
```
:::

## Going further

Expand All @@ -109,7 +174,7 @@ complete description of each one of them in the next section.
You can also add *Anonymizers* from community packs. For example, to add the `PackFRFr` run:

```bash
composer dbtoolsbundle/pack-fr-fr
composer require db-tools-bundle/pack-fr-fr
```

If you can't find what you need from core anonymizers and in available packs, the *DbToolsBundle* allows
Expand Down
2 changes: 1 addition & 1 deletion docs/content/anonymization/pack-FR-Fr.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Pack FR_Fr

This page list *Anonymizers* provided by the *Fr_Fr pack*.
This page list *Anonymizers* provided by the *pack FR_Fr*.

[[toc]]

Expand Down
Loading

0 comments on commit e76ea8f

Please sign in to comment.