Skip to content

Commit 85b72a0

Browse files
committed
feat: add anonymization
1 parent 7f8639e commit 85b72a0

29 files changed

+3134
-3
lines changed

.anonymizer/.env.example

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
export bucket_access_key=
2+
export bucket_endpoint=
3+
export bucket_name=
4+
export bucket_region=
5+
export bucket_secret_key=
6+
7+
export PGHOST=
8+
export PGUSER=
9+
export PGPASSWORD=
10+
export PGDATABASE=
11+
12+
export PGHOST_RESTORE=
13+
export PGUSER_RESTORE=
14+
export PGPASSWORD_RESTORE=
15+
export PGDATABASE_RESTORE=

.anonymizer/.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.pnp.*
2+
.yarn/*
3+
!.yarn/patches
4+
!.yarn/plugins
5+
!.yarn/releases
6+
!.yarn/sdks
7+
!.yarn/versions
8+
9+
dist/

.anonymizer/.prettierrc.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"semi": false,
3+
"tabWidth": 2,
4+
"useTabs": false,
5+
"printWidth": 80,
6+
"singleQuote": false,
7+
"trailingComma": "es5"
8+
}

.anonymizer/.yarn/releases/yarn-4.2.2.cjs

Lines changed: 894 additions & 0 deletions
Large diffs are not rendered by default.

.anonymizer/.yarnrc.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
compressionLevel: mixed
2+
3+
enableGlobalCache: false
4+
5+
yarnPath: .yarn/releases/yarn-4.2.2.cjs

.anonymizer/anonymize-prod.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
exclude_tables="contact_support,contact_support_message,expired_token,message_email,monitor_batch_process,user_usager_login"
6+
7+
mkdir -p /tmp/pg_dump
8+
9+
cd /workspace/.anonymizer
10+
11+
cat config.yaml \
12+
| sed "s%{{tmp}}%/tmp/pg_dump%" \
13+
| sed "s%{{bucket_access_key}}%$bucket_access_key%" \
14+
| sed "s%{{bucket_secret_key}}%$bucket_secret_key%" \
15+
| sed "s%{{bucket_endpoint}}%$bucket_endpoint%" \
16+
| sed "s%{{bucket_name}}%$bucket_name%" \
17+
| sed "s%{{bucket_region}}%$bucket_region%" \
18+
| sed "s%{{type}}%directory%" \
19+
> config.local.yaml
20+
21+
yarn
22+
yarn build
23+
24+
greenmask dump --config config.local.yaml -j 1 --exclude-table-data $exclude_tables

.anonymizer/anonymize.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
exclude_tables="contact_support,contact_support_message,expired_token,message_email,monitor_batch_process,user_usager_login"
6+
7+
cd "$(dirname "$0")"
8+
9+
source .env
10+
pg_dump_directory=./tmp/pg_dump
11+
mkdir -p $pg_dump_directory
12+
13+
greenmask -v || (echo "You need to download greenmask from https://github.com/GreenmaskIO/greenmask/releases/tag/v0.1.14 in $directory" && exit)
14+
15+
cat config.yaml \
16+
| sed "s%{{tmp}}%$(pwd)/tmp/pg_dump%" \
17+
| sed "s%{{bucket_access_key}}%$bucket_access_key%" \
18+
| sed "s%{{bucket_secret_key}}%$bucket_secret_key%" \
19+
| sed "s%{{bucket_endpoint}}%$bucket_endpoint%" \
20+
| sed "s%{{bucket_name}}%$bucket_name%" \
21+
| sed "s%{{bucket_region}}%$bucket_region%" \
22+
| sed "s%{{type}}%directory%" \
23+
> config.local.yaml
24+
25+
greenmask dump --config config.local.yaml --log-level debug -j 10 --exclude-table-data $exclude_tables
26+
27+
export PGDATABASE=${PGDATABASE_RESTORE:-$PGDATABASE_anonymized}
28+
pg_restore --clean --if-exists --no-owner --no-acl --verbose -d $PGDATABASE $pg_dump_directory/$(ls $pg_dump_directory | tail -n 1)

0 commit comments

Comments
 (0)