From ddfd8bdcef112cf1386070d754ff90a73d2c32e2 Mon Sep 17 00:00:00 2001 From: Simon Vieille Date: Tue, 12 Mar 2024 06:59:49 +0100 Subject: [PATCH] [wip] configuration --- config/config.go | 40 ++++++++++++++++++++++++++++++++++++++++ go.mod | 8 ++++++++ go.sum | 8 ++++++++ main.go | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 103 insertions(+) create mode 100644 config/config.go create mode 100644 go.sum create mode 100644 main.go diff --git a/config/config.go b/config/config.go new file mode 100644 index 0000000..bef73c6 --- /dev/null +++ b/config/config.go @@ -0,0 +1,40 @@ +package config + +import ( + "errors" + "github.com/urfave/cli/v2" +) + +type DatabaseConfig struct { + Type string + Dsn string +} + +type AnonymizationConfig struct { +} + +func LoadDatabaseConfig(c *cli.Context) (error, DatabaseConfig) { + config := DatabaseConfig{ + Type: c.String("type"), + Dsn: c.String("dsn"), + } + + if config.Type == "" { + return errors.New("You must specify a database type"), config + } + + if config.Dsn == "" { + return errors.New("You must specify a database DSN"), config + } + + return nil, config +} + +func LoadAnonymizationConfig(c *cli.Context) (error, AnonymizationConfig) { + config := AnonymizationConfig{ + Type: c.String("type"), + Dsn: c.String("dsn"), + } + + return nil, config +} diff --git a/go.mod b/go.mod index b5c496d..53f012e 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,11 @@ module gitnet.fr/deblan/database-anonymizer go 1.22.0 + +require github.com/urfave/cli/v2 v2.27.1 + +require ( + github.com/cpuguy83/go-md2man/v2 v2.0.3 // indirect + github.com/russross/blackfriday/v2 v2.1.0 // indirect + github.com/xrash/smetrics v0.0.0-20231213231151-1d8dd44e695e // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..72a5de0 --- /dev/null +++ b/go.sum @@ -0,0 +1,8 @@ +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/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/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= diff --git a/main.go b/main.go new file mode 100644 index 0000000..05ef4fa --- /dev/null +++ b/main.go @@ -0,0 +1,47 @@ +package main + +import ( + "fmt" + "github.com/urfave/cli/v2" + "gitnet.fr/deblan/database-anonymizer/config" + "log" + "os" +) + +func main() { + app := &cli.App{ + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "type", + Value: "", + Usage: "type of database (eg: mysql)", + }, + &cli.StringFlag{ + Name: "dsn", + Value: "", + Usage: "DSN (eg: mysql://user:pass@host/dbname)", + }, + &cli.StringFlag{ + Name: "config", + Value: "config.yaml", + Usage: "Configuration file", + }, + }, + Action: func(c *cli.Context) error { + err, databaseConfig := config.LoadDatabaseConfig(c) + + if err != nil { + log.Fatalf(err.Error()) + os.Exit(1) + } + + fmt.Printf("%+v\n", databaseConfig) + + return nil + }, + } + + if err := app.Run(os.Args); err != nil { + fmt.Println(err) + } +}