Compare commits
3 commits
39e0e4344f
...
5b941de748
Author | SHA1 | Date | |
---|---|---|---|
Simon Vieille | 5b941de748 | ||
Simon Vieille | 57733eaa3f | ||
Simon Vieille | 6fa443d62b |
|
@ -22,3 +22,13 @@ steps:
|
|||
image: *golang_image
|
||||
commands:
|
||||
- go build
|
||||
|
||||
"Publish":
|
||||
image: plugins/gitea-release
|
||||
settings:
|
||||
api_key:
|
||||
from_secret: gitnet_api_key
|
||||
base_url: https://gitnet.fr
|
||||
files: ./database-anonymizer
|
||||
when:
|
||||
event: [tag]
|
||||
|
|
|
@ -2,9 +2,9 @@
|
|||
|
||||
**Database Anonimizer** est un outil écrit en GO et qui permet **d'anonymiser ou supprimer des données** d'une base de données **MySQL** ou **PostgreSQL**.
|
||||
|
||||
Il répond à plusieurs cas d'usags comme le **permettre de transférer une copie de base de données anonymisée à des développeurs et des développeuses** ou répondre à la nécessité d'**anonymiser ou supprimer des données dans le cadre du RGPD** (Règlement général sur la protection des données) selon des durées de conservation définies dans un registre de traitement.
|
||||
Il répond à plusieurs cas d'usags comme le **permettre de transférer une copie de base de données anonymisée à des développeurs et des développeuses** ou répondre à la nécessité d'**anonymiser ou supprimer des données dans le cadre du RGPD** (Règlement général sur la protection des données) selon les durées de conservation définies dans le registre des traitements.
|
||||
|
||||
Le projet inclue une grande quantité de générateurs de données aléatoires. Il permet également de générer des données via des modèles écrits en Twig. Vous pouvez spécifier des règles précises pour chaque tables ou bien des règles globales appliquées sur chacunes des tables de votre configration.
|
||||
Le projet inclue une grande quantité de générateurs de données aléatoires. Il permet également de générer des données via des modèles écrits en Twig. Vous pouvez spécifier des règles précises pour chaque tables ou bien des règles globales appliquées sur chacunes des tables de votre configuration.
|
||||
|
||||
## Usage
|
||||
|
||||
|
|
15
app/app.go
15
app/app.go
|
@ -7,6 +7,8 @@ import (
|
|||
|
||||
"strings"
|
||||
|
||||
"github.com/schollz/progressbar/v3"
|
||||
|
||||
"gitnet.fr/deblan/database-anonymizer/config"
|
||||
"gitnet.fr/deblan/database-anonymizer/data"
|
||||
"gitnet.fr/deblan/database-anonymizer/database"
|
||||
|
@ -42,9 +44,13 @@ func (a *App) Run(
|
|||
}
|
||||
|
||||
func (a *App) TruncateTable(c config.SchemaConfigAction) error {
|
||||
bar := progressbar.Default(1, fmt.Sprintf("Truncating %s...", c.Table))
|
||||
|
||||
if c.Query == "" {
|
||||
_, err := a.Db.Exec(fmt.Sprintf("TRUNCATE %s", database.EscapeTable(a.DbConfig.Type, c.Table)))
|
||||
|
||||
bar.Add(1)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -52,6 +58,8 @@ func (a *App) TruncateTable(c config.SchemaConfigAction) error {
|
|||
rows := database.GetRows(a.Db, query, c.Table, a.DbConfig.Type)
|
||||
var scan any
|
||||
|
||||
bar.ChangeMax(len(rows))
|
||||
|
||||
for _, row := range rows {
|
||||
pkeys := []string{}
|
||||
values := make(map[int]string)
|
||||
|
@ -80,6 +88,8 @@ func (a *App) TruncateTable(c config.SchemaConfigAction) error {
|
|||
}
|
||||
|
||||
a.Db.QueryRow(sql, args...).Scan(&scan)
|
||||
|
||||
bar.Add(1)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -90,6 +100,9 @@ func (a *App) UpdateRows(c config.SchemaConfigAction, globalColumns map[string]s
|
|||
rows := database.GetRows(a.Db, query, c.Table, a.DbConfig.Type)
|
||||
var scan any
|
||||
|
||||
bar := progressbar.Default(int64(len(rows)))
|
||||
bar.Describe(fmt.Sprintf("Updating %s...", c.Table))
|
||||
|
||||
for key, row := range rows {
|
||||
if len(c.VirtualColumns) > 0 {
|
||||
for col, faker := range c.VirtualColumns {
|
||||
|
@ -194,6 +207,8 @@ func (a *App) UpdateRows(c config.SchemaConfigAction, globalColumns map[string]s
|
|||
logger.LogFatalExitIf(err)
|
||||
}
|
||||
}
|
||||
|
||||
bar.Add(1)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
8
go.mod
8
go.mod
|
@ -3,9 +3,10 @@ module gitnet.fr/deblan/database-anonymizer
|
|||
go 1.22.0
|
||||
|
||||
require (
|
||||
github.com/Knetic/go-namedParameterQuery v0.0.0-20150709205813-b7327e472dfd
|
||||
github.com/go-sql-driver/mysql v1.8.0
|
||||
github.com/jaswdr/faker v1.19.1
|
||||
github.com/lib/pq v1.10.9
|
||||
github.com/schollz/progressbar/v3 v3.14.2
|
||||
github.com/tyler-sommer/stick v1.0.6
|
||||
github.com/urfave/cli/v2 v2.27.1
|
||||
gopkg.in/yaml.v3 v3.0.1
|
||||
|
@ -14,8 +15,11 @@ require (
|
|||
require (
|
||||
filippo.io/edwards25519 v1.1.0 // indirect
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.3 // indirect
|
||||
github.com/jaswdr/faker v1.19.1 // indirect
|
||||
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect
|
||||
github.com/rivo/uniseg v0.4.7 // indirect
|
||||
github.com/russross/blackfriday/v2 v2.1.0 // indirect
|
||||
github.com/shopspring/decimal v1.3.1 // indirect
|
||||
github.com/xrash/smetrics v0.0.0-20231213231151-1d8dd44e695e // indirect
|
||||
golang.org/x/sys v0.18.0 // indirect
|
||||
golang.org/x/term v0.18.0 // indirect
|
||||
)
|
||||
|
|
25
go.sum
25
go.sum
|
@ -1,26 +1,47 @@
|
|||
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
|
||||
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
|
||||
github.com/Knetic/go-namedParameterQuery v0.0.0-20150709205813-b7327e472dfd h1:KSbQj+RcWtQeg6ndcvtUMGWNBY/RozpbJlKrAmS0TeY=
|
||||
github.com/Knetic/go-namedParameterQuery v0.0.0-20150709205813-b7327e472dfd/go.mod h1:GGnSKvb/jhWZffu3/izcawQDUkwwdMgddYUVxu9aLxs=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.3 h1:qMCsGGgs+MAzDFyp9LpAe1Lqy/fY/qCovCm0qnXZOBM=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/go-sql-driver/mysql v1.8.0 h1:UtktXaU2Nb64z/pLiGIxY4431SJ4/dR5cjMmlVHgnT4=
|
||||
github.com/go-sql-driver/mysql v1.8.0/go.mod h1:wEBSXgmK//2ZFJyE+qWnIsVGmvmEKlqwuVSjsCm7DZg=
|
||||
github.com/jaswdr/faker v1.19.1 h1:xBoz8/O6r0QAR8eEvKJZMdofxiRH+F0M/7MU9eNKhsM=
|
||||
github.com/jaswdr/faker v1.19.1/go.mod h1:x7ZlyB1AZqwqKZgyQlnqEG8FDptmHlncA5u2zY/yi6w=
|
||||
github.com/k0kubun/go-ansi v0.0.0-20180517002512-3bf9e2903213/go.mod h1:vNUNkEQ1e29fT/6vq2aBdFsgNPmy8qMdSay1npru+Sw=
|
||||
github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
|
||||
github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
|
||||
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db h1:62I3jR2EmQ4l5rM/4FEfDWcRD+abF5XlKShorW5LRoQ=
|
||||
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db/go.mod h1:l0dey0ia/Uv7NcFFVbCLtqEBQbrT4OCwCSKTEv6enCw=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
|
||||
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
|
||||
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
|
||||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||
github.com/schollz/progressbar/v3 v3.14.2 h1:EducH6uNLIWsr560zSV1KrTeUb/wZGAHqyMFIEa99ks=
|
||||
github.com/schollz/progressbar/v3 v3.14.2/go.mod h1:aQAZQnhF4JGFtRJiw/eobaXpsqpVQAftEQ+hLGXaRc4=
|
||||
github.com/shopspring/decimal v0.0.0-20180709203117-cd690d0c9e24/go.mod h1:M+9NzErvs504Cn4c5DxATwIqPbtswREoFCre64PpcG4=
|
||||
github.com/shopspring/decimal v1.3.1 h1:2Usl1nmF/WZucqkFZhnfFYxxxu8LG21F6nPQBE5gKV8=
|
||||
github.com/shopspring/decimal v1.3.1/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/tyler-sommer/stick v1.0.6 h1:LLdJ8oGotXCsAuVx2BRZZT6s3bYXHe0ImQ+azF4HtJg=
|
||||
github.com/tyler-sommer/stick v1.0.6/go.mod h1:rjBy3zi6GwoxExa6OSRPPPaLqUEKNsBxTeWckhIX1us=
|
||||
github.com/urfave/cli/v2 v2.27.1 h1:8xSQ6szndafKVRmfyeUMxkNUJQMjL1F2zmsZ+qHpfho=
|
||||
github.com/urfave/cli/v2 v2.27.1/go.mod h1:8qnjx1vcq5s2/wpsqoZFndg2CE5tNFyrTvS6SinrnYQ=
|
||||
github.com/xrash/smetrics v0.0.0-20231213231151-1d8dd44e695e h1:+SOyEddqYF09QP7vr7CgJ1eti3pY9Fn3LHO1M1r/0sI=
|
||||
github.com/xrash/smetrics v0.0.0-20231213231151-1d8dd44e695e/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
|
||||
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk=
|
||||
golang.org/x/term v0.18.0 h1:FcHjZXDMxI8mM3nwhX9HlKop4C0YQvCVCdwYl2wOtE8=
|
||||
golang.org/x/term v0.18.0/go.mod h1:ILwASektA3OnRv7amZ1xhE/KTR+u50pbXfZ03+6Nx58=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
|
|
Loading…
Reference in a new issue