diff --git a/integration/dbanon_test.go b/integration/dbanon_test.go index b5e1658..e9d6ef5 100644 --- a/integration/dbanon_test.go +++ b/integration/dbanon_test.go @@ -15,7 +15,7 @@ var version string func TestDbanon(t *testing.T) { os.Chdir("..") dir, _ := os.Getwd() - + cmd1 := exec.Command(path.Join(dir, binaryName)) out1, _ := cmd1.CombinedOutput() res1 := strings.TrimSpace(string(out1)) @@ -34,7 +34,6 @@ func TestDbanon(t *testing.T) { t.Errorf("Got %s expected %s", res2, versRes) } - cmdStr3 := "cat integration/magento_raw.sql | ./dbanon -config=magento2" cmd3 := exec.Command("bash", "-c", cmdStr3) out3, _ := cmd3.CombinedOutput() @@ -68,4 +67,4 @@ func TestDbanon(t *testing.T) { if strings.Contains(res5, "Bob Smith") { t.Error("Expected no Bob Smith") } -} \ No newline at end of file +} diff --git a/main.go b/main.go index 44c09ab..df380a2 100644 --- a/main.go +++ b/main.go @@ -5,13 +5,13 @@ import ( "flag" "fmt" "github.com/blang/semver" - "github.com/sirupsen/logrus" "github.com/mpchadwick/dbanon/src" "github.com/rhysd/go-github-selfupdate/selfupdate" + "github.com/sirupsen/logrus" "io/ioutil" "log" - "runtime/pprof" "os" + "runtime/pprof" ) var version string @@ -85,7 +85,6 @@ func main() { } } - config, err := dbanon.NewConfig(*requested) if err != nil { fmt.Fprintln(os.Stderr, err) @@ -97,7 +96,7 @@ func main() { // We don't want to hear about it log.SetOutput(ioutil.Discard) reader := bufio.NewReader(os.Stdin) - + args := flag.Args() mode := "anonymize" if len(args) > 0 && args[0] == "map-eav" { @@ -108,7 +107,6 @@ func main() { eav := dbanon.NewEav(config) processor := dbanon.NewLineProcessor(mode, config, provider, eav) - for { text, err := reader.ReadString('\n') result := processor.ProcessLine(text) @@ -126,4 +124,4 @@ func main() { fmt.Print(string(out)) os.Exit(0) } -} \ No newline at end of file +} diff --git a/src/config.go b/src/config.go index d37f0ca..c20bb52 100644 --- a/src/config.go +++ b/src/config.go @@ -10,11 +10,11 @@ import ( type Config struct { Tables []struct { - Name string `yaml:"name"` + Name string `yaml:"name"` Columns map[string]string `yaml:"columns"` } Eav []struct { - Name string `yaml:"name"` + Name string `yaml:"name"` Attributes map[string]string `yaml:"attributes"` } } @@ -48,10 +48,9 @@ func (c Config) String() ([]byte, error) { return yaml.Marshal(c) } - func (c Config) ProcessTable(t string) string { for _, table := range c.Tables { - if (table.Name == t) { + if table.Name == t { return "table" } } @@ -74,7 +73,7 @@ func (c Config) ProcessTable(t string) string { func (c Config) ProcessColumn(t string, col string) (bool, string) { for _, table := range c.Tables { - if (table.Name != t) { + if table.Name != t { continue } @@ -102,4 +101,4 @@ func (c Config) ProcessEav(t string, attributeId string) (bool, string) { } return false, "" -} \ No newline at end of file +} diff --git a/src/config_test.go b/src/config_test.go index 3f209bf..06f6f2c 100644 --- a/src/config_test.go +++ b/src/config_test.go @@ -89,4 +89,4 @@ func TestProcessEav(t *testing.T) { if format2 != "" { t.Errorf("Got %s want empty string", format2) } -} \ No newline at end of file +} diff --git a/src/create_table.go b/src/create_table.go index f695145..f05a6c1 100644 --- a/src/create_table.go +++ b/src/create_table.go @@ -39,4 +39,4 @@ func findNextTable(s string) { if k == 0 { nextTable += s } -} \ No newline at end of file +} diff --git a/src/eav.go b/src/eav.go index 02d7c32..ea10d01 100644 --- a/src/eav.go +++ b/src/eav.go @@ -1,7 +1,7 @@ package dbanon -type Eav struct{ - Config *Config +type Eav struct { + Config *Config entityMap map[string]string } @@ -10,4 +10,4 @@ func NewEav(c *Config) *Eav { e := &Eav{Config: c, entityMap: made} return e -} \ No newline at end of file +} diff --git a/src/logger.go b/src/logger.go index 273800a..2f6fb33 100644 --- a/src/logger.go +++ b/src/logger.go @@ -16,4 +16,4 @@ func SetLogger(l *logrus.Logger) { func GetLogger() *logrus.Logger { return logger -} \ No newline at end of file +} diff --git a/src/processor.go b/src/processor.go index 9aca370..c067a6b 100644 --- a/src/processor.go +++ b/src/processor.go @@ -6,10 +6,10 @@ import ( ) type LineProcessor struct { - Mode string - Config *Config + Mode string + Config *Config Provider ProviderInterface - Eav *Eav + Eav *Eav } func NewLineProcessor(m string, c *Config, p ProviderInterface, e *Eav) *LineProcessor { @@ -44,7 +44,7 @@ func (p LineProcessor) processInsert(s string) string { var dataType string var entityTypeId string - + rows := insert.Rows.(sqlparser.Values) for _, vt := range rows { for i, e := range vt { @@ -65,7 +65,7 @@ func (p LineProcessor) processInsert(s string) string { } else { if column == "attribute_id" { attributeId = string(v.Val) - if (p.Mode == "anonymize") { + if p.Mode == "anonymize" { result, dataType = p.Config.ProcessEav(table, attributeId) } } @@ -97,4 +97,4 @@ func (p LineProcessor) processInsert(s string) string { } return sqlparser.String(insert) + ";\n" -} \ No newline at end of file +} diff --git a/src/processor_test.go b/src/processor_test.go index 0dc94b4..3957136 100644 --- a/src/processor_test.go +++ b/src/processor_test.go @@ -33,7 +33,7 @@ func TestProcessLine(t *testing.T) { processor.ProcessLine(" `firstname` varchar(32) DEFAULT NULL COMMENT 'User First Name'") processor.ProcessLine(") ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COMMENT='Admin User Table'") processor.ProcessLine("/*!40101 SET character_set_client = @saved_cs_client */;") - + r2 := processor.ProcessLine("INSERT INTO `admin_user` (`firstname`) VALUES ('bob');") if strings.Contains(r2, "bob") { t.Error("Got bob wanted no bob") @@ -89,14 +89,13 @@ func TestEavProcessLine(t *testing.T) { eav := NewEav(config) processor := NewLineProcessor(mode, config, provider, eav) - processor.ProcessLine("CREATE TABLE `eav_entity_type` (") processor.ProcessLine(" `entity_type_id` smallint(5) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Entity Type ID',") processor.ProcessLine(" `entity_type_code` varchar(50) NOT NULL COMMENT 'Entity Type Code'") processor.ProcessLine(") ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8 COMMENT='Eav Entity Type';") processor.ProcessLine("/*!40101 SET character_set_client = @saved_cs_client */;") processor.ProcessLine("INSERT INTO `eav_entity_type` (`entity_type_id`, `entity_type_code`) VALUES (1, 'customer');") - + processor.ProcessLine("CREATE TABLE `eav_attribute` (") processor.ProcessLine(" `attribute_id` smallint(5) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Attribute ID',") processor.ProcessLine(" `entity_type_id` smallint(5) unsigned NOT NULL DEFAULT '0' COMMENT 'Entity Type ID',") @@ -124,6 +123,6 @@ func TestEavProcessLine(t *testing.T) { if !r2 { t.Errorf("Got false wanted true") - } + } -} \ No newline at end of file +} diff --git a/src/provider.go b/src/provider.go index a944128..39b6e13 100644 --- a/src/provider.go +++ b/src/provider.go @@ -9,15 +9,15 @@ import ( var fakeEmail = faker.Internet().Email -var rawProviders = map[string]interface{} { - "Lorem()": faker.Lorem(), +var rawProviders = map[string]interface{}{ + "Lorem()": faker.Lorem(), "Internet()": faker.Internet(), "Commerce()": faker.Commerce(), - "Code()": faker.Code(), - "Number()": faker.Number(), + "Code()": faker.Code(), + "Number()": faker.Number(), } -type Provider struct{ +type Provider struct { providedUniqueEmails map[string]int } @@ -107,7 +107,7 @@ func (p Provider) Get(s string) string { return "" } -func (p Provider) raw (s string) string { +func (p Provider) raw(s string) string { logger := GetLogger() parts := strings.Split(s, ".") @@ -132,7 +132,7 @@ func (p Provider) raw (s string) string { return "" } - args := parts[2][argsStart + 1 : argsEnd] + args := parts[2][argsStart+1 : argsEnd] if args == "" { out := method.Call(nil) return out[0].String() @@ -147,4 +147,4 @@ func (p Provider) raw (s string) string { out := method.Call(in) return out[0].String() } -} \ No newline at end of file +} diff --git a/src/provider_test.go b/src/provider_test.go index 2819226..c5479eb 100644 --- a/src/provider_test.go +++ b/src/provider_test.go @@ -46,8 +46,8 @@ func TestGet(t *testing.T) { t.Errorf("Unsupported method not handled correctly") } - _ = provider.Get("faker.Internet().Slug") + _ = provider.Get("faker.Internet().Slug") if hook.LastEntry().Message != "Could not identify arguments for Slug" { t.Errorf("Malformed arguments not handled correctly") } -} \ No newline at end of file +}