masking 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +7 -0
  2. data/.codeclimate.yml +14 -0
  3. data/.gitignore +16 -0
  4. data/.mdlrc +1 -0
  5. data/.rubocop.yml +18 -0
  6. data/.ruby-version +1 -0
  7. data/.travis.yml +9 -0
  8. data/CODE_OF_CONDUCT.md +74 -0
  9. data/Gemfile +8 -0
  10. data/Gemfile.lock +119 -0
  11. data/LICENSE.txt +21 -0
  12. data/README.md +166 -0
  13. data/Rakefile +11 -0
  14. data/bin/console +11 -0
  15. data/bin/masking_profile +58 -0
  16. data/bin/setup +10 -0
  17. data/config/.keep +0 -0
  18. data/exe/masking +7 -0
  19. data/lib/masking.rb +31 -0
  20. data/lib/masking/cli.rb +42 -0
  21. data/lib/masking/cli/error_message.rb +36 -0
  22. data/lib/masking/cli/error_messages.yml +6 -0
  23. data/lib/masking/config.rb +33 -0
  24. data/lib/masking/config/target_columns.rb +52 -0
  25. data/lib/masking/config/target_columns/column.rb +32 -0
  26. data/lib/masking/config/target_columns/method.rb +41 -0
  27. data/lib/masking/config/target_columns/method/binary.rb +23 -0
  28. data/lib/masking/config/target_columns/method/boolean.rb +29 -0
  29. data/lib/masking/config/target_columns/method/date.rb +30 -0
  30. data/lib/masking/config/target_columns/method/float.rb +23 -0
  31. data/lib/masking/config/target_columns/method/integer.rb +23 -0
  32. data/lib/masking/config/target_columns/method/null.rb +17 -0
  33. data/lib/masking/config/target_columns/method/string.rb +33 -0
  34. data/lib/masking/config/target_columns/method/string_binary_distinctor.rb +31 -0
  35. data/lib/masking/config/target_columns/method/time.rb +28 -0
  36. data/lib/masking/config/target_columns/table.rb +24 -0
  37. data/lib/masking/data_mask_processor.rb +44 -0
  38. data/lib/masking/errors.rb +9 -0
  39. data/lib/masking/insert_statement.rb +74 -0
  40. data/lib/masking/insert_statement/sql_builder.rb +34 -0
  41. data/lib/masking/insert_statement/value.rb +30 -0
  42. data/lib/masking/sql_dump_line.rb +24 -0
  43. data/lib/masking/version.rb +5 -0
  44. data/masking.gemspec +46 -0
  45. data/masking.yml.sample +17 -0
  46. metadata +259 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 576c8dba2493be25e50f35cf561329440d8d06f95e6970082c7ba1f994fd0c9b
4
+ data.tar.gz: e7eca576c298dab4271096a54412fe6c9e0e77c9df8d56469d6c37c1805efb20
5
+ SHA512:
6
+ metadata.gz: 552d7be10143a0f3e71c3f8bc77e51eaa56f596ce94cd105a079a57ab4d1010e57ca0b0a847e8f6105e7aa65f9aeba569304bf273d612ca626bc9e1aa8f4b8e7
7
+ data.tar.gz: b465c88f260b24836f4a7bb2d51e0c956d65a1b6b950673b2a0e672c37ed2bcb1edab0115b86f9ae4c3506fc3b0e2ed0f5d6757e9aa8be900a738aafc3b4e0c6
@@ -0,0 +1,14 @@
1
+ version: "2"
2
+ plugins:
3
+ bundler-audit:
4
+ enabled: true
5
+ markdownlint:
6
+ enabled: true
7
+ checks:
8
+ # below 3 checks are disabled because Codeclimate's Markdownlint is not latest version
9
+ MD023:
10
+ enabled: false
11
+ MD034:
12
+ enabled: false
13
+ MD036:
14
+ enabled: false
@@ -0,0 +1,16 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /profile/
10
+ /.rspec
11
+
12
+ # rspec failure tracking
13
+ .rspec_status
14
+
15
+ # config
16
+ /masking.yml
data/.mdlrc ADDED
@@ -0,0 +1 @@
1
+ rules "~MD013"
@@ -0,0 +1,18 @@
1
+ AllCops:
2
+ Exclude:
3
+ - 'vendor/**/*'
4
+ - 'spec/fixtures/**/*'
5
+ - 'tmp/**/*'
6
+ TargetRubyVersion: 2.5
7
+
8
+ Metrics/LineLength:
9
+ Max: 120
10
+
11
+ Metrics/BlockLength:
12
+ Max: 75
13
+
14
+ Style/Documentation:
15
+ Enabled: false
16
+
17
+ Style/CharacterLiteral:
18
+ Enabled: false
@@ -0,0 +1 @@
1
+ 2.6.0
@@ -0,0 +1,9 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.5.3
5
+ - 2.6.0
6
+ before_install: gem install bundler -v 1.17.3
7
+
8
+ script:
9
+ - bundle exec rspec
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at uzukifirst@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
+
7
+ # Specify your gem's dependencies in masking.gemspec
8
+ gemspec
@@ -0,0 +1,119 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ masking (0.0.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.0)
10
+ byebug (10.0.2)
11
+ coderay (1.1.2)
12
+ colored (1.2)
13
+ coveralls (0.7.1)
14
+ multi_json (~> 1.3)
15
+ rest-client
16
+ simplecov (>= 0.7)
17
+ term-ansicolor
18
+ thor
19
+ diff-lcs (1.3)
20
+ docile (1.3.1)
21
+ domain_name (0.5.20180417)
22
+ unf (>= 0.0.5, < 1.0.0)
23
+ http-cookie (1.0.3)
24
+ domain_name (~> 0.5)
25
+ jaro_winkler (1.5.1)
26
+ json (2.1.0)
27
+ kramdown (1.17.0)
28
+ mdl (0.5.0)
29
+ kramdown (~> 1.12, >= 1.12.0)
30
+ mixlib-cli (~> 1.7, >= 1.7.0)
31
+ mixlib-config (~> 2.2, >= 2.2.1)
32
+ method_source (0.9.2)
33
+ mime-types (3.2.2)
34
+ mime-types-data (~> 3.2015)
35
+ mime-types-data (3.2018.0812)
36
+ mixlib-cli (1.7.0)
37
+ mixlib-config (2.2.18)
38
+ tomlrb
39
+ multi_json (1.13.1)
40
+ netrc (0.11.0)
41
+ parallel (1.12.1)
42
+ parser (2.5.3.0)
43
+ ast (~> 2.4.0)
44
+ powerpack (0.1.2)
45
+ pry (0.12.2)
46
+ coderay (~> 1.1.0)
47
+ method_source (~> 0.9.0)
48
+ pry-byebug (3.6.0)
49
+ byebug (~> 10.0)
50
+ pry (~> 0.10)
51
+ rainbow (3.0.0)
52
+ rake (10.5.0)
53
+ rake-notes (0.2.2)
54
+ colored
55
+ rake
56
+ rest-client (2.0.2)
57
+ http-cookie (>= 1.0.2, < 2.0)
58
+ mime-types (>= 1.16, < 4.0)
59
+ netrc (~> 0.8)
60
+ rspec (3.8.0)
61
+ rspec-core (~> 3.8.0)
62
+ rspec-expectations (~> 3.8.0)
63
+ rspec-mocks (~> 3.8.0)
64
+ rspec-core (3.8.0)
65
+ rspec-support (~> 3.8.0)
66
+ rspec-expectations (3.8.2)
67
+ diff-lcs (>= 1.2.0, < 2.0)
68
+ rspec-support (~> 3.8.0)
69
+ rspec-mocks (3.8.0)
70
+ diff-lcs (>= 1.2.0, < 2.0)
71
+ rspec-support (~> 3.8.0)
72
+ rspec-support (3.8.0)
73
+ rubocop (0.61.1)
74
+ jaro_winkler (~> 1.5.1)
75
+ parallel (~> 1.10)
76
+ parser (>= 2.5, != 2.5.1.1)
77
+ powerpack (~> 0.1)
78
+ rainbow (>= 2.2.2, < 4.0)
79
+ ruby-progressbar (~> 1.7)
80
+ unicode-display_width (~> 1.4.0)
81
+ ruby-prof (0.17.0)
82
+ ruby-progressbar (1.10.0)
83
+ simplecov (0.16.1)
84
+ docile (~> 1.1)
85
+ json (>= 1.8, < 3)
86
+ simplecov-html (~> 0.10.0)
87
+ simplecov-html (0.10.2)
88
+ tapp (1.5.1)
89
+ thor
90
+ term-ansicolor (1.7.0)
91
+ tins (~> 1.0)
92
+ thor (0.20.3)
93
+ tins (1.20.2)
94
+ tomlrb (1.2.8)
95
+ unf (0.1.4)
96
+ unf_ext
97
+ unf_ext (0.0.7.5)
98
+ unicode-display_width (1.4.1)
99
+
100
+ PLATFORMS
101
+ ruby
102
+
103
+ DEPENDENCIES
104
+ bundler (~> 1.16)
105
+ coveralls
106
+ masking!
107
+ mdl
108
+ pry
109
+ pry-byebug
110
+ rake (~> 10.0)
111
+ rake-notes
112
+ rspec (~> 3.0)
113
+ rubocop
114
+ ruby-prof
115
+ simplecov
116
+ tapp
117
+
118
+ BUNDLED WITH
119
+ 1.17.3
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 kibitan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,166 @@
1
+ # MasKING🤴
2
+
3
+ [![Build Status](https://travis-ci.org/kibitan/masking.svg?branch=master)](https://travis-ci.org/kibitan/masking)
4
+ [![Coverage Status](https://coveralls.io/repos/github/kibitan/masking/badge.svg?branch=master)](https://coveralls.io/github/kibitan/masking?branch=master)
5
+ [![Maintainability](https://api.codeclimate.com/v1/badges/290b3005ecc193a3d138/maintainability)](https://codeclimate.com/github/kibitan/masking/maintainability)
6
+
7
+ The command line tool for anonymizing database records by parsing a SQL dump file and build new SQL dump file with masking sensitive/credential data.
8
+
9
+ ## Installation
10
+
11
+ ```bash
12
+ git clone git@github.com:kibitan/masking.git
13
+ bin/setup
14
+ ```
15
+
16
+ or install it yourself as:
17
+
18
+ ```bash
19
+ gem install masking
20
+ ```
21
+
22
+ ## Requirement
23
+
24
+ * Ruby 2.5/2.6
25
+
26
+ ## Supported RDBMS
27
+
28
+ * MySQL 5.7...(TBC)
29
+
30
+ ## Usage
31
+
32
+ 1. setup configuration of target columns to `masking.yml`
33
+
34
+ ```yaml
35
+ # table_name:
36
+ # column_name: masked_value
37
+
38
+ users:
39
+ string: anonymized string
40
+ email: anonymized+%{n}@example.com # %{n} will be replaced with sequential number
41
+ integer: 12345
42
+ float: 123.45
43
+ boolean: true
44
+ null: null
45
+ date: 2018-08-24
46
+ time: 2018-08-24 15:54:06
47
+ binary_or_blob: !binary | # Binary Data Language-Independent Type for YAML™ Version 1.1: http://yaml.org/type/binary.html
48
+ R0lGODlhDAAMAIQAAP//9/X17unp5WZmZgAAAOfn515eXvPz7Y6OjuDg4J+fn5
49
+ OTk6enp56enmlpaWNjY6Ojo4SEhP/++f/++f/++f/++f/++f/++f/++f/++f/+
50
+ +f/++f/++f/++f/++f/++SH+Dk1hZGUgd2l0aCBHSU1QACwAAAAADAAMAAAFLC
51
+ AgjoEwnuNAFOhpEMTRiggcz4BNJHrv/zCFcLiwMWYNG84BwwEeECcgggoBADs=
52
+ ```
53
+
54
+ A value will be implicitly converted to compatible type. If you prefer to explicitly convert, you could use a tag as defined in [YAML Version 1.1](http://yaml.org/spec/current.html#id2503753)
55
+
56
+ ```yaml
57
+ not-date: !!str 2002-04-28
58
+ ```
59
+
60
+ String should be matched with [MySQL String Type]( https://dev.mysql.com/doc/refman/8.0/en/string-type-overview.html). Integer/Float should be matched with [MySQL Numeric Type](https://dev.mysql.com/doc/refman/8.0/en/numeric-type-overview.html). Date/Time should be matched with [MySQL Date and Time Type](https://dev.mysql.com/doc/refman/8.0/en/date-and-time-type-overview.html).
61
+
62
+ *NOTE: MasKING doesn't check actual schema's type from dump. If you put uncomaptible value it will cause error during restoring to database.*
63
+
64
+ 1. dump with mask
65
+
66
+ MasKING works with `mysqldump --complete-insert`
67
+
68
+ ```bash
69
+ mysqldump --complete-insert -u USERNAME DATABASE_NAME | masking > masked_dump.sql
70
+ ```
71
+
72
+ 1. restore
73
+
74
+ ```bash
75
+ mysql -u USERNAME MASKED_DATABASE_NAME < masked_dump.sql
76
+ ```
77
+
78
+ ### options
79
+
80
+ ```bash
81
+ $ masking -h
82
+ Usage: masking [options]
83
+ -c, --config=FILE_PATH specify config file. default: masking.yml
84
+ ```
85
+
86
+ ## Run test & rubocop & notes
87
+
88
+ ```bash
89
+ bundle exec rake
90
+ ```
91
+
92
+ ### Protip
93
+
94
+ It's useful that set `rake` on [Git hooks](https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks).
95
+
96
+ ```bash
97
+ touch .git/hooks/pre-commit && chmod +x .git/hooks/pre-commit && cat << EOF > .git/hooks/pre-commit
98
+ #!/usr/bin/env bash
99
+ bundle exec rake
100
+ EOF
101
+ ```
102
+
103
+ ### [Markdown lint](https://github.com/markdownlint/markdownlint)
104
+
105
+ ```bash
106
+ bundle exec mdl *.md
107
+ ```
108
+
109
+ ## Development
110
+
111
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
112
+
113
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
114
+
115
+ ### Profiling
116
+
117
+ use `bin/masking_profile`
118
+
119
+ ```bash
120
+ $ cat your_sample.sql | bin/masking_profile
121
+ flat result is saved at /your/repo/profile/flat.txt
122
+ graph result is saved at /your/repo/profile/graph.txt
123
+ graph html is saved at /your/repo/profile/graph.html
124
+
125
+ $ open profile/flat.txt
126
+ ```
127
+
128
+ see also: [ruby-prof/ruby-prof: ruby-prof: a code profiler for MRI rubies](https://github.com/ruby-prof/ruby-prof)
129
+
130
+ ## Design Concept
131
+
132
+ ### KISS ~ keep it simple, stupid ~
133
+
134
+ No connection to database, No handling file, Only dealing with stdin/stdout. ~ Do One Thing and Do It Well ~
135
+
136
+ ### No External Dependency
137
+
138
+ Depend on only pure language standard libraries, no external libraries. (except development/test environment)
139
+
140
+ ### High Code Quality
141
+
142
+ 100% of code coverage [![Coverage Status](https://coveralls.io/repos/github/kibitan/masking/badge.svg?branch=master)](https://coveralls.io/github/kibitan/masking?branch=master) and low complexity [![Maintainability](https://api.codeclimate.com/v1/badges/290b3005ecc193a3d138/maintainability)](https://codeclimate.com/github/kibitan/masking/maintainability)
143
+
144
+ ## Future Todo
145
+
146
+ * Pluguable/customizable for a mask way e.g. integrate with [Faker](https://github.com/stympy/faker)
147
+ * Compatible with other RDBMS e.g. PostgreSQL, Oracle, SQL Server
148
+ * Parse the schema type information and validate target columns value
149
+ * Integration test with real database
150
+ * Performance optimization
151
+ * Write in streaming process
152
+ * rewrite by another language?
153
+ * Well-documentation
154
+
155
+ ## Contributing
156
+
157
+ Bug reports and pull requests are welcome on GitHub at [https://github.com/kibitan/masking](https://github.com/kibitan/masking).
158
+ This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
159
+
160
+ ## License
161
+
162
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
163
+
164
+ ## Code of Conduct
165
+
166
+ Everyone interacting in the Masking project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/kibitan/masking/blob/master/CODE_OF_CONDUCT.md).