Skip to content

Commit

Permalink
Merge pull request #47 from nixys/feat/45
Browse files Browse the repository at this point in the history
feat(#45): Generating correct values ​​for types
  • Loading branch information
borisershov authored Sep 18, 2024
2 parents c14e6e2 + ddc3389 commit 3b480fa
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 86 deletions.
44 changes: 22 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -355,9 +355,9 @@ _Values to masquerade a columns in accordance with the types see below._
| `numeric` | `0.0` |
| `real` | `0.0` |
| `double` | `0.0` |
| `character` | `randomized string data` |
| `bpchar` | `randomized string data` |
| `text` | `randomized string data` |
| `character` | `randomized character data"` |
| `bpchar` | `randomized bpchar data` |
| `text` | `randomized text data` |

**MySQL:**

Expand All @@ -372,25 +372,25 @@ _Values to masquerade a columns in accordance with the types see below._
| `int` | `0` |
| `integer` | `0` |
| `bigint` | `0` |
| `float` | `0` |
| `double` | `0` |
| `double precision` | `0` |
| `decimal` | `0` |
| `dec` | `0` |
| `char` | `randomized string data` |
| `varchar` | `randomized string data` |
| `tinytext` | `randomized string data` |
| `text` | `randomized string data` |
| `mediumtext` | `randomized string data` |
| `longtext` | `randomized string data` |
| `enum` | `randomized string data` |
| `set` | `randomized string data` |
| `date` | `randomized string data` |
| `datetime` | `randomized string data` |
| `timestamp` | `randomized string data` |
| `time` | `randomized string data` |
| `year` | `randomized string data` |
| `json` | `randomized string data` |
| `float` | `0.0` |
| `double` | `0.0` |
| `double precision` | `0.0` |
| `decimal` | `0.0` |
| `dec` | `0.0` |
| `char` | `randomized char` (String will be truncated to "COLUMN_SIZE" length.)|
| `varchar` | `randomized varchar` (String will be truncated to "COLUMN_SIZE" length.) |
| `tinytext` | `randomized tinytext` |
| `text` | `randomized text` |
| `mediumtext` | `randomized mediumtext` |
| `longtext` | `randomized longtext` |
| `enum` | Last value from `enum` |
| `set` | Last value from `set` |
| `date` | `2024-01-01` |
| `datetime` | `2024-01-01 00:00:00` |
| `timestamp` | `2024-01-01 00:00:00` |
| `time` | `00:00:00` |
| `year` | `2024` |
| `json` | `{"randomized": "json_data"}` |
| `binary` | `cmFuZG9taXplZCBiaW5hcnkgZGF0YQo=` |
| `varbinary` | `cmFuZG9taXplZCBiaW5hcnkgZGF0YQo=` |
| `tinyblob` | `cmFuZG9taXplZCBiaW5hcnkgZGF0YQo=` |
Expand Down
84 changes: 39 additions & 45 deletions modules/anonymizers/mysql/security_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,124 +5,118 @@ import (
"github.com/nixys/nxs-data-anonymizer/modules/filters/relfilter"
)

const (
securityTypeString = "randomized string data"
securityTypeNum = "0"
securityTypeBinary = "cmFuZG9taXplZCBiaW5hcnkgZGF0YQo="
)

var typeRuleDefault = []relfilter.TypeRuleOpts{

// String
{
Selector: "(?i)^char\\((\\d+)\\)|^char ",
Selector: "(?i)^char\\((\\d+)\\)|^char",
Rule: relfilter.ColumnRuleOpts{
Type: misc.ValueTypeTemplate,
Value: securityTypeString,
Value: "{{ trunc (index .ColumnTypeGroups 0 1 | int ) \"randomized char\" }}",
Unique: false,
},
},
{
Selector: "(?i)^varchar",
Selector: "(?i)^varchar\\((\\d+)\\)|^varchar",
Rule: relfilter.ColumnRuleOpts{
Type: misc.ValueTypeTemplate,
Value: securityTypeString,
Value: "{{ trunc (index .ColumnTypeGroups 0 1 | int ) \"randomized varchar\" }}",
Unique: false,
},
},
{
Selector: "(?i)^tinytext",
Rule: relfilter.ColumnRuleOpts{
Type: misc.ValueTypeTemplate,
Value: securityTypeString,
Value: "randomized tinytext",
Unique: false,
},
},
{
Selector: "(?i)^text",
Rule: relfilter.ColumnRuleOpts{
Type: misc.ValueTypeTemplate,
Value: securityTypeString,
Value: "randomized text",
Unique: false,
},
},
{
Selector: "(?i)^mediumtext",
Rule: relfilter.ColumnRuleOpts{
Type: misc.ValueTypeTemplate,
Value: securityTypeString,
Value: "randomized mediumtext",
Unique: false,
},
},
{
Selector: "(?i)^longtext",
Rule: relfilter.ColumnRuleOpts{
Type: misc.ValueTypeTemplate,
Value: securityTypeString,
Value: "randomized longtext",
Unique: false,
},
},
{
Selector: "(?i)^enum",
Selector: "(?i)^enum\\(.*'(.*)'.*\\)",
Rule: relfilter.ColumnRuleOpts{
Type: misc.ValueTypeTemplate,
Value: securityTypeString,
Value: "{{ index .ColumnTypeGroups 0 1 }}",
Unique: false,
},
},
{
Selector: "(?i)^set",
Selector: "(?i)^set\\(.*'(.*)'.*\\)",
Rule: relfilter.ColumnRuleOpts{
Type: misc.ValueTypeTemplate,
Value: securityTypeString,
Value: "{{ index .ColumnTypeGroups 0 1 }}",
Unique: false,
},
},
{
Selector: "(?i)^date",
Selector: "(?i)^datetime",
Rule: relfilter.ColumnRuleOpts{
Type: misc.ValueTypeTemplate,
Value: securityTypeString,
Value: "2024-01-01 00:00:00",
Unique: false,
},
},
{
Selector: "(?i)^datetime",
Selector: "(?i)^date",
Rule: relfilter.ColumnRuleOpts{
Type: misc.ValueTypeTemplate,
Value: securityTypeString,
Value: "2024-01-01",
Unique: false,
},
},
{
Selector: "(?i)^timestamp",
Rule: relfilter.ColumnRuleOpts{
Type: misc.ValueTypeTemplate,
Value: securityTypeString,
Value: "2024-01-01 00:00:00",
Unique: false,
},
},
{
Selector: "(?i)^time",
Rule: relfilter.ColumnRuleOpts{
Type: misc.ValueTypeTemplate,
Value: securityTypeString,
Value: "00:00:00",
Unique: false,
},
},
{
Selector: "(?i)^year",
Rule: relfilter.ColumnRuleOpts{
Type: misc.ValueTypeTemplate,
Value: securityTypeString,
Value: "2024",
Unique: false,
},
},
{
Selector: "(?i)^json",
Rule: relfilter.ColumnRuleOpts{
Type: misc.ValueTypeTemplate,
Value: securityTypeString,
Value: "{\"randomized\": \"json_data\"}",
Unique: false,
},
},
Expand All @@ -132,103 +126,103 @@ var typeRuleDefault = []relfilter.TypeRuleOpts{
Selector: "(?i)^bit",
Rule: relfilter.ColumnRuleOpts{
Type: misc.ValueTypeTemplate,
Value: securityTypeNum,
Value: "0",
Unique: false,
},
},
{
Selector: "(?i)^bool",
Rule: relfilter.ColumnRuleOpts{
Type: misc.ValueTypeTemplate,
Value: securityTypeNum,
Value: "0",
Unique: false,
},
},
{
Selector: "(?i)^boolean",
Rule: relfilter.ColumnRuleOpts{
Type: misc.ValueTypeTemplate,
Value: securityTypeNum,
Value: "0",
Unique: false,
},
},
{
Selector: "(?i)^tinyint",
Rule: relfilter.ColumnRuleOpts{
Type: misc.ValueTypeTemplate,
Value: securityTypeNum,
Value: "0",
Unique: false,
},
},
{
Selector: "(?i)^smallint",
Rule: relfilter.ColumnRuleOpts{
Type: misc.ValueTypeTemplate,
Value: securityTypeNum,
Value: "0",
Unique: false,
},
},
{
Selector: "(?i)^mediumint",
Rule: relfilter.ColumnRuleOpts{
Type: misc.ValueTypeTemplate,
Value: securityTypeNum,
Value: "0",
Unique: false,
},
},
{
Selector: "(?i)^int",
Rule: relfilter.ColumnRuleOpts{
Type: misc.ValueTypeTemplate,
Value: securityTypeNum,
Value: "0",
Unique: false,
},
},
{
Selector: "(?i)^integer",
Rule: relfilter.ColumnRuleOpts{
Type: misc.ValueTypeTemplate,
Value: securityTypeNum,
Value: "0",
Unique: false,
},
},
{
Selector: "(?i)^bigint",
Rule: relfilter.ColumnRuleOpts{
Type: misc.ValueTypeTemplate,
Value: securityTypeNum,
Value: "0",
Unique: false,
},
},
{
Selector: "(?i)^float",
Rule: relfilter.ColumnRuleOpts{
Type: misc.ValueTypeTemplate,
Value: securityTypeNum,
Value: "0.0",
Unique: false,
},
},
{
Selector: "(?i)^double",
Rule: relfilter.ColumnRuleOpts{
Type: misc.ValueTypeTemplate,
Value: securityTypeNum,
Value: "0.0",
Unique: false,
},
},
{
Selector: "(?i)^decimal",
Rule: relfilter.ColumnRuleOpts{
Type: misc.ValueTypeTemplate,
Value: securityTypeNum,
Value: "0.0",
Unique: false,
},
},
{
Selector: "(?i)^dec",
Rule: relfilter.ColumnRuleOpts{
Type: misc.ValueTypeTemplate,
Value: securityTypeNum,
Value: "0.0",
Unique: false,
},
},
Expand All @@ -238,45 +232,45 @@ var typeRuleDefault = []relfilter.TypeRuleOpts{
Selector: "(?i)^binary",
Rule: relfilter.ColumnRuleOpts{
Type: misc.ValueTypeTemplate,
Value: securityTypeBinary,
Value: "cmFuZG9taXplZCBiaW5hcnkgZGF0YQo=",
Unique: false,
},
},
{
Selector: "(?i)^varbinary",
Rule: relfilter.ColumnRuleOpts{
Type: misc.ValueTypeTemplate,
Value: securityTypeBinary,
Value: "cmFuZG9taXplZCBiaW5hcnkgZGF0YQo=",
Unique: false,
},
}, {
Selector: "(?i)^tinyblob",
Rule: relfilter.ColumnRuleOpts{
Type: misc.ValueTypeTemplate,
Value: securityTypeBinary,
Value: "cmFuZG9taXplZCBiaW5hcnkgZGF0YQo=",
Unique: false,
},
},
{
Selector: "(?i)^blob",
Rule: relfilter.ColumnRuleOpts{
Type: misc.ValueTypeTemplate,
Value: securityTypeBinary,
Value: "cmFuZG9taXplZCBiaW5hcnkgZGF0YQo=",
Unique: false,
},
},
{
Selector: "(?i)^mediumblob",
Rule: relfilter.ColumnRuleOpts{
Type: misc.ValueTypeTemplate,
Value: securityTypeBinary,
Value: "cmFuZG9taXplZCBiaW5hcnkgZGF0YQo=",
Unique: false,
},
}, {
Selector: "(?i)^longblob",
Rule: relfilter.ColumnRuleOpts{
Type: misc.ValueTypeTemplate,
Value: securityTypeBinary,
Value: "cmFuZG9taXplZCBiaW5hcnkgZGF0YQo=",
Unique: false,
},
},
Expand Down
Loading

0 comments on commit 3b480fa

Please sign in to comment.