gratan 0.3.1.beta2 → 0.3.1.beta3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +23 -21
- data/README.md +12 -1
- data/bin/gratan +2 -0
- data/docker-compose.yml +12 -0
- data/lib/gratan/client.rb +1 -0
- data/lib/gratan/driver.rb +10 -0
- data/lib/gratan/exporter.rb +5 -1
- data/lib/gratan/grant_parser.rb +16 -4
- data/lib/gratan/version.rb +1 -1
- data/spec/change/change_grants_2_spec.rb +5 -5
- data/spec/change/change_grants_3_spec.rb +3 -3
- data/spec/change/change_grants_expired_spec.rb +3 -3
- data/spec/change/change_grants_ignore_not_exist_spec.rb +1 -1
- data/spec/change/change_grants_multi_hosts_spec.rb +2 -2
- data/spec/change/change_grants_regexp_spec.rb +2 -2
- data/spec/change/change_grants_spec.rb +4 -4
- data/spec/change/change_grants_target_spec.rb +2 -2
- data/spec/change/change_grants_with_ignore_object_spec.rb +2 -2
- data/spec/create/create_user_2_spec.rb +2 -2
- data/spec/create/create_user_3_spec.rb +1 -1
- data/spec/create/create_user_multi_hosts_spec.rb +1 -1
- data/spec/create/create_user_regexp_spec.rb +1 -1
- data/spec/create/create_user_spec.rb +3 -3
- data/spec/create/create_user_target_spec.rb +1 -1
- data/spec/create/create_user_with_ignore_object_spec.rb +2 -2
- data/spec/create/create_user_with_template_spec.rb +1 -1
- data/spec/drop/drop_user_2_spec.rb +2 -2
- data/spec/drop/expire_user_spec.rb +2 -2
- data/spec/misc/misc_spec.rb +3 -2
- data/spec/misc/require_spec.rb +2 -2
- data/spec/spec_helper.rb +36 -2
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: adaa06d400536360b941da3222d0ae6530087401
|
4
|
+
data.tar.gz: e479b4afd4f858d641dbe8e99c21734db7d771b4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0ccef9c558666e71ae5ba4c4acd3a43a7475bdcc047fe030e19cee7b7d7e1af8086100f55c191f5112fdbadc89fb3b1ec18d05276cb276f87df069b0c62d4895
|
7
|
+
data.tar.gz: 4f713f1a7e9c57d0bb6f1874f03d4d79f602ebdc25972212d2af2d96fd1d80e4ad38e98e9d6abe0d3dd9d71953394464180fc678af085199643a315e9648c179
|
data/.travis.yml
CHANGED
@@ -1,26 +1,28 @@
|
|
1
1
|
sudo: true
|
2
2
|
language: ruby
|
3
3
|
rvm:
|
4
|
-
- 2.
|
5
|
-
- 2.
|
6
|
-
- 2.
|
7
|
-
|
4
|
+
- 2.3
|
5
|
+
- 2.4
|
6
|
+
- 2.5
|
7
|
+
cache:
|
8
|
+
- bundler
|
9
|
+
- apt
|
10
|
+
env:
|
11
|
+
matrix:
|
12
|
+
- MYSQL57=0 MYSQ_PORT=14406 # MySQL 5.6
|
13
|
+
- MYSQL57=1 MYSQ_PORT=14407 # MySQL 5.7
|
14
|
+
before_script:
|
15
|
+
- sudo service mysql stop
|
8
16
|
- bundle install
|
17
|
+
- docker-compose up -d
|
18
|
+
- function mysql_ping { mysqladmin -u root -h 127.0.0.1 -P $MYSQ_PORT ping; }
|
19
|
+
- for i in {1..60}; do mysql_ping && break; sleep 1; done
|
20
|
+
script:
|
9
21
|
- bundle exec rake
|
10
|
-
|
11
|
-
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
- "sudo apt-get -y install libaio1"
|
18
|
-
- "wget -O mysql-$MYSQL_VERSION.deb http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-$MYSQL_VERSION-debian6.0-x86_64.deb/from/http://cdn.mysql.com/"
|
19
|
-
- "sudo dpkg -i mysql-$MYSQL_VERSION.deb"
|
20
|
-
- "sudo cp -f /opt/mysql/server-5.6/support-files/mysql.server /etc/init.d/mysql.server"
|
21
|
-
- "sudo ln -sf /opt/mysql/server-5.6/bin/* /usr/bin/"
|
22
|
-
- "sudo sed -i'' 's/table_cache/table_open_cache/' /etc/mysql/my.cnf"
|
23
|
-
- "sudo sed -i'' 's/log_slow_queries/slow_query_log/' /etc/mysql/my.cnf"
|
24
|
-
- "sudo sed -i'' 's/basedir[^=]\\+=.*$/basedir = \\/opt\\/mysql\\/server-5.6/' /etc/mysql/my.cnf"
|
25
|
-
- "sudo sed -i'' 's/^socket *=.*$/socket = \\/tmp\\/mysql.sock/' /etc/mysql/my.cnf"
|
26
|
-
- "sudo /etc/init.d/mysql.server start"
|
22
|
+
services:
|
23
|
+
- docker
|
24
|
+
addons:
|
25
|
+
apt:
|
26
|
+
packages:
|
27
|
+
- mysql-client-core-5.6
|
28
|
+
- mysql-client-5.6
|
data/README.md
CHANGED
@@ -65,6 +65,8 @@ Usage: gratan [options]
|
|
65
65
|
--ignore-not-exist
|
66
66
|
--ignore-password-secret
|
67
67
|
--skip-disable-log-bin
|
68
|
+
--override-sql-mode
|
69
|
+
--use-show-create-user
|
68
70
|
--no-color
|
69
71
|
--debug
|
70
72
|
--auto-identify OUTPUT
|
@@ -73,7 +75,7 @@ Usage: gratan [options]
|
|
73
75
|
-h, --help
|
74
76
|
```
|
75
77
|
|
76
|
-
A default connection to a database can be established by setting the following environment variables:
|
78
|
+
A default connection to a database can be established by setting the following environment variables:
|
77
79
|
- `GRATAN_DB_HOST`: database host
|
78
80
|
- `GRATAN_DB_PORT`: database port
|
79
81
|
- `GRATAN_DB_SOCKET`: database socket
|
@@ -136,6 +138,15 @@ user 'scott', 'localhost', identified: 'tiger' do
|
|
136
138
|
end
|
137
139
|
```
|
138
140
|
|
141
|
+
## Run tests
|
142
|
+
|
143
|
+
```sh
|
144
|
+
bundle install
|
145
|
+
docker-compose up -d
|
146
|
+
bundle exec rake
|
147
|
+
# MYSQL57=1 bundle exec rake
|
148
|
+
```
|
149
|
+
|
139
150
|
## Similar tools
|
140
151
|
* [Codenize.tools](http://codenize.tools/)
|
141
152
|
|
data/bin/gratan
CHANGED
@@ -56,6 +56,8 @@ ARGV.options do |opt|
|
|
56
56
|
opt.on('' , '--ignore-not-exist') {|v| options[:ignore_not_exist] = true }
|
57
57
|
opt.on('' , '--ignore-password-secret') {|v| options[:ignore_password_secret] = true }
|
58
58
|
opt.on('' , '--skip-disable-log-bin') { options[:skip_disable_log_bin] = true }
|
59
|
+
opt.on('' , '--override-sql-mode') { options[:override_sql_mode] = true }
|
60
|
+
opt.on('' , '--use-show-create-user') { options[:use_show_create_user] = true }
|
59
61
|
opt.on('' , '--no-color') { options[:color] = false }
|
60
62
|
opt.on('' , '--debug') { options[:debug] = true }
|
61
63
|
opt.on('' , '--auto-identify OUTPUT') {|v| options[:identifier] = Gratan::Identifier::Auto.new(v, options) }
|
data/docker-compose.yml
ADDED
data/lib/gratan/client.rb
CHANGED
data/lib/gratan/driver.rb
CHANGED
@@ -20,6 +20,10 @@ class Gratan::Driver
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
+
def show_create_user(user, host)
|
24
|
+
query("SHOW CREATE USER #{quote_user(user, host)}").first.values.first
|
25
|
+
end
|
26
|
+
|
23
27
|
def show_databases
|
24
28
|
query("SHOW DATABASES").map {|i| i.values.first }
|
25
29
|
end
|
@@ -205,6 +209,12 @@ class Gratan::Driver
|
|
205
209
|
end
|
206
210
|
end
|
207
211
|
|
212
|
+
def override_sql_mode
|
213
|
+
if @options[:override_sql_mode]
|
214
|
+
query('SET SQL_MODE = ""')
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
208
218
|
private
|
209
219
|
|
210
220
|
def query(sql)
|
data/lib/gratan/exporter.rb
CHANGED
@@ -18,8 +18,12 @@ class Gratan::Exporter
|
|
18
18
|
next unless user =~ @options[:target_user]
|
19
19
|
end
|
20
20
|
|
21
|
+
if @options[:use_show_create_user]
|
22
|
+
create_user = @driver.show_create_user(user, host)
|
23
|
+
end
|
24
|
+
|
21
25
|
@driver.show_grants(user, host) do |stmt|
|
22
|
-
grants << Gratan::GrantParser.parse(stmt)
|
26
|
+
grants << Gratan::GrantParser.parse(stmt, create_user)
|
23
27
|
end
|
24
28
|
end
|
25
29
|
|
data/lib/gratan/grant_parser.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
class Gratan::GrantParser
|
2
|
-
def initialize(stmt)
|
2
|
+
def initialize(stmt, create_user = nil)
|
3
3
|
@stmt = stmt.strip
|
4
|
+
@create_user = create_user
|
4
5
|
@parsed = {}
|
5
6
|
end
|
6
7
|
|
7
|
-
def self.parse(stmt)
|
8
|
-
parser = self.new(stmt)
|
8
|
+
def self.parse(stmt, create_user = nil)
|
9
|
+
parser = self.new(stmt, create_user)
|
9
10
|
parser.parse!
|
10
11
|
end
|
11
12
|
|
@@ -32,7 +33,12 @@ class Gratan::GrantParser
|
|
32
33
|
@stmt.slice!(/\s+REQUIRE\s+(.+?)\z/)
|
33
34
|
required = $1
|
34
35
|
|
35
|
-
if
|
36
|
+
if @create_user
|
37
|
+
@create_user.slice!(/\s+REQUIRE\s+(\S+(?:\s+'[^']+')?)(?:\s+.+)?\s+PASSWORD\s+.+\z/)
|
38
|
+
required = $1
|
39
|
+
end
|
40
|
+
|
41
|
+
if required && required != 'NONE'
|
36
42
|
@parsed[:require] = required.strip
|
37
43
|
end
|
38
44
|
end
|
@@ -41,6 +47,12 @@ class Gratan::GrantParser
|
|
41
47
|
@stmt.slice!(/\s+IDENTIFIED BY\s+(.+?)\z/)
|
42
48
|
identified = $1
|
43
49
|
|
50
|
+
if @create_user
|
51
|
+
@create_user.slice!(/\s+IDENTIFIED\s+WITH\s+'[^']+'\s+AS\s+('[^']+')/)
|
52
|
+
identified = $1
|
53
|
+
identified = "PASSWORD #{identified}" if identified
|
54
|
+
end
|
55
|
+
|
44
56
|
if identified
|
45
57
|
@parsed[:identified] = identified.strip
|
46
58
|
end
|
data/lib/gratan/version.rb
CHANGED
@@ -40,7 +40,7 @@ end
|
|
40
40
|
expect(show_grants).to match_array [
|
41
41
|
"GRANT ALL PRIVILEGES ON *.* TO 'bob'@'localhost' IDENTIFIED BY PASSWORD '*531E182E2F72080AB0740FE2F2D689DBE0146E04' WITH GRANT OPTION",
|
42
42
|
"GRANT USAGE ON *.* TO 'scott'@'localhost' IDENTIFIED BY PASSWORD '*23AE809DDACAF96AF0FD78ED04B6A265E05AA257' REQUIRE SSL",
|
43
|
-
]
|
43
|
+
].normalize
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
@@ -67,7 +67,7 @@ end
|
|
67
67
|
expect(show_grants).to match_array [
|
68
68
|
"GRANT ALL PRIVILEGES ON *.* TO 'bob'@'localhost' WITH GRANT OPTION",
|
69
69
|
"GRANT USAGE ON *.* TO 'scott'@'localhost' REQUIRE SSL",
|
70
|
-
]
|
70
|
+
].normalize
|
71
71
|
end
|
72
72
|
end
|
73
73
|
|
@@ -94,7 +94,7 @@ end
|
|
94
94
|
expect(show_grants).to match_array [
|
95
95
|
"GRANT ALL PRIVILEGES ON *.* TO 'bob'@'localhost' WITH GRANT OPTION",
|
96
96
|
"GRANT USAGE ON *.* TO 'scott'@'localhost' IDENTIFIED BY PASSWORD '*F2F68D0BB27A773C1D944270E5FAFED515A3FA40' REQUIRE SSL",
|
97
|
-
]
|
97
|
+
].normalize
|
98
98
|
end
|
99
99
|
end
|
100
100
|
|
@@ -121,7 +121,7 @@ end
|
|
121
121
|
expect(show_grants).to match_array [
|
122
122
|
"GRANT ALL PRIVILEGES ON *.* TO 'bob'@'localhost' REQUIRE SSL WITH GRANT OPTION",
|
123
123
|
"GRANT USAGE ON *.* TO 'scott'@'localhost' IDENTIFIED BY PASSWORD '*F2F68D0BB27A773C1D944270E5FAFED515A3FA40' REQUIRE X509",
|
124
|
-
]
|
124
|
+
].normalize
|
125
125
|
end
|
126
126
|
end
|
127
127
|
|
@@ -148,7 +148,7 @@ end
|
|
148
148
|
expect(show_grants).to match_array [
|
149
149
|
"GRANT ALL PRIVILEGES ON *.* TO 'bob'@'localhost'",
|
150
150
|
"GRANT USAGE ON *.* TO 'scott'@'localhost' IDENTIFIED BY PASSWORD '*F2F68D0BB27A773C1D944270E5FAFED515A3FA40' REQUIRE SSL WITH GRANT OPTION MAX_QUERIES_PER_HOUR 1 MAX_UPDATES_PER_HOUR 2 MAX_CONNECTIONS_PER_HOUR 3 MAX_USER_CONNECTIONS 4",
|
151
|
-
]
|
151
|
+
].normalize
|
152
152
|
end
|
153
153
|
end
|
154
154
|
end
|
@@ -76,7 +76,7 @@ end
|
|
76
76
|
"GRANT SELECT, INSERT ON *.* TO 'scott'@'localhost' IDENTIFIED BY PASSWORD '*F2F68D0BB27A773C1D944270E5FAFED515A3FA40' REQUIRE SSL",
|
77
77
|
"GRANT UPDATE, DELETE ON `test`.* TO 'scott'@'localhost'",
|
78
78
|
"GRANT USAGE ON *.* TO 'bob'@'localhost'",
|
79
|
-
]
|
79
|
+
].normalize
|
80
80
|
end
|
81
81
|
end
|
82
82
|
|
@@ -114,7 +114,7 @@ end
|
|
114
114
|
"GRANT SELECT, INSERT ON *.* TO 'scott'@'localhost' IDENTIFIED BY PASSWORD '*F2F68D0BB27A773C1D944270E5FAFED515A3FA40' REQUIRE SSL",
|
115
115
|
"GRANT UPDATE, DELETE ON `test`.* TO 'scott'@'localhost'",
|
116
116
|
"GRANT USAGE ON *.* TO 'bob'@'localhost'",
|
117
|
-
]
|
117
|
+
].normalize
|
118
118
|
end
|
119
119
|
end
|
120
120
|
|
@@ -158,7 +158,7 @@ end
|
|
158
158
|
"GRANT SELECT, INSERT ON *.* TO 'scott'@'localhost' IDENTIFIED BY PASSWORD '*F2F68D0BB27A773C1D944270E5FAFED515A3FA40' REQUIRE SSL",
|
159
159
|
"GRANT UPDATE, DELETE ON `test`.* TO 'scott'@'localhost'",
|
160
160
|
"GRANT USAGE ON *.* TO 'bob'@'localhost'",
|
161
|
-
]
|
161
|
+
].normalize
|
162
162
|
end
|
163
163
|
end
|
164
164
|
end
|
@@ -61,7 +61,7 @@ end
|
|
61
61
|
expect(show_grants).to match_array [
|
62
62
|
"GRANT SELECT (user) ON `mysql`.`user` TO 'scott'@'localhost'",
|
63
63
|
"GRANT SELECT, INSERT ON *.* TO 'scott'@'localhost' IDENTIFIED BY PASSWORD '*F2F68D0BB27A773C1D944270E5FAFED515A3FA40' REQUIRE SSL",
|
64
|
-
]
|
64
|
+
].normalize
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
@@ -96,7 +96,7 @@ end
|
|
96
96
|
"GRANT SELECT (user) ON `mysql`.`user` TO 'scott'@'localhost'",
|
97
97
|
"GRANT SELECT, INSERT ON *.* TO 'scott'@'localhost' IDENTIFIED BY PASSWORD '*F2F68D0BB27A773C1D944270E5FAFED515A3FA40' REQUIRE SSL",
|
98
98
|
"GRANT UPDATE, DELETE ON `test`.* TO 'scott'@'localhost'",
|
99
|
-
]
|
99
|
+
].normalize
|
100
100
|
end
|
101
101
|
end
|
102
102
|
|
@@ -132,7 +132,7 @@ end
|
|
132
132
|
"GRANT SELECT (user) ON `mysql`.`user` TO 'scott'@'localhost'",
|
133
133
|
"GRANT SELECT, INSERT ON *.* TO 'scott'@'localhost' IDENTIFIED BY PASSWORD '*F2F68D0BB27A773C1D944270E5FAFED515A3FA40' REQUIRE SSL",
|
134
134
|
"GRANT UPDATE, DELETE ON `test`.* TO 'scott'@'localhost'",
|
135
|
-
]
|
135
|
+
].normalize
|
136
136
|
end
|
137
137
|
end
|
138
138
|
end
|
@@ -64,7 +64,7 @@ end
|
|
64
64
|
"GRANT SELECT, DELETE ON *.* TO 'scott'@'%' IDENTIFIED BY PASSWORD '*F2F68D0BB27A773C1D944270E5FAFED515A3FA40' REQUIRE SSL",
|
65
65
|
"GRANT SELECT, DELETE ON *.* TO 'scott'@'127.0.0.1' REQUIRE SSL",
|
66
66
|
"GRANT SELECT, DELETE ON *.* TO 'scott'@'localhost' IDENTIFIED BY PASSWORD '*F2F68D0BB27A773C1D944270E5FAFED515A3FA40' REQUIRE SSL",
|
67
|
-
]
|
67
|
+
].normalize
|
68
68
|
end
|
69
69
|
end
|
70
70
|
|
@@ -139,7 +139,7 @@ end
|
|
139
139
|
"GRANT SELECT, INSERT ON *.* TO 'scott'@'localhost' IDENTIFIED BY PASSWORD '*F2F68D0BB27A773C1D944270E5FAFED515A3FA40' REQUIRE SSL",
|
140
140
|
"GRANT UPDATE, DELETE ON `test`.* TO 'scott'@'%'",
|
141
141
|
"GRANT UPDATE, DELETE ON `test`.* TO 'scott'@'localhost'",
|
142
|
-
]
|
142
|
+
].normalize
|
143
143
|
end
|
144
144
|
end
|
145
145
|
end
|
@@ -80,7 +80,7 @@ end
|
|
80
80
|
"GRANT UPDATE, DELETE ON `gratan_test`.`zoo` TO 'bob'@'localhost'",
|
81
81
|
"GRANT UPDATE, DELETE ON `test`.* TO 'scott'@'localhost'",
|
82
82
|
"GRANT USAGE ON *.* TO 'bob'@'localhost'",
|
83
|
-
]
|
83
|
+
].normalize
|
84
84
|
end
|
85
85
|
end
|
86
86
|
end
|
@@ -137,7 +137,7 @@ end
|
|
137
137
|
"GRANT SELECT, INSERT ON *.* TO 'scott'@'localhost' IDENTIFIED BY PASSWORD '*F2F68D0BB27A773C1D944270E5FAFED515A3FA40' REQUIRE SSL",
|
138
138
|
"GRANT UPDATE, DELETE ON `test`.* TO 'scott'@'localhost'",
|
139
139
|
"GRANT USAGE ON *.* TO 'bob'@'localhost'",
|
140
|
-
]
|
140
|
+
].normalize
|
141
141
|
end
|
142
142
|
end
|
143
143
|
end
|
@@ -76,7 +76,7 @@ end
|
|
76
76
|
"GRANT SELECT, INSERT, UPDATE, DELETE ON *.* TO 'scott'@'localhost' IDENTIFIED BY PASSWORD '*F2F68D0BB27A773C1D944270E5FAFED515A3FA40' REQUIRE SSL",
|
77
77
|
"GRANT SELECT, INSERT, UPDATE, DELETE ON `test`.* TO 'scott'@'localhost'",
|
78
78
|
"GRANT USAGE ON *.* TO 'bob'@'localhost'",
|
79
|
-
]
|
79
|
+
].normalize
|
80
80
|
end
|
81
81
|
end
|
82
82
|
|
@@ -113,7 +113,7 @@ end
|
|
113
113
|
"GRANT SELECT ON *.* TO 'scott'@'localhost' IDENTIFIED BY PASSWORD '*F2F68D0BB27A773C1D944270E5FAFED515A3FA40' REQUIRE SSL",
|
114
114
|
"GRANT UPDATE (host) ON `mysql`.`user` TO 'scott'@'localhost'",
|
115
115
|
"GRANT USAGE ON *.* TO 'bob'@'localhost'",
|
116
|
-
]
|
116
|
+
].normalize
|
117
117
|
end
|
118
118
|
end
|
119
119
|
|
@@ -157,7 +157,7 @@ end
|
|
157
157
|
"GRANT UPDATE (host) ON `mysql`.`user` TO 'scott'@'localhost'",
|
158
158
|
"GRANT UPDATE, DELETE ON *.* TO 'scott'@'localhost' IDENTIFIED BY PASSWORD '*F2F68D0BB27A773C1D944270E5FAFED515A3FA40' REQUIRE SSL",
|
159
159
|
"GRANT USAGE ON *.* TO 'mary'@'localhost'",
|
160
|
-
]
|
160
|
+
].normalize
|
161
161
|
end
|
162
162
|
end
|
163
163
|
|
@@ -203,7 +203,7 @@ end
|
|
203
203
|
"GRANT SELECT, INSERT ON *.* TO 'scott'@'localhost' IDENTIFIED BY PASSWORD '*F2F68D0BB27A773C1D944270E5FAFED515A3FA40' REQUIRE SSL",
|
204
204
|
"GRANT UPDATE, DELETE ON `test`.* TO 'scott'@'localhost'",
|
205
205
|
"GRANT USAGE ON *.* TO 'bob'@'localhost'",
|
206
|
-
]
|
206
|
+
].normalize
|
207
207
|
end
|
208
208
|
end
|
209
209
|
end
|
@@ -76,7 +76,7 @@ end
|
|
76
76
|
"GRANT SELECT, INSERT ON *.* TO 'scott'@'localhost' IDENTIFIED BY PASSWORD '*F2F68D0BB27A773C1D944270E5FAFED515A3FA40' REQUIRE SSL",
|
77
77
|
"GRANT UPDATE, DELETE ON `test`.* TO 'scott'@'localhost'",
|
78
78
|
"GRANT USAGE ON *.* TO 'bob'@'localhost'",
|
79
|
-
]
|
79
|
+
].normalize
|
80
80
|
end
|
81
81
|
end
|
82
82
|
|
@@ -126,7 +126,7 @@ end
|
|
126
126
|
"GRANT SELECT, INSERT ON *.* TO 'scott'@'localhost' IDENTIFIED BY PASSWORD '*F2F68D0BB27A773C1D944270E5FAFED515A3FA40' REQUIRE SSL",
|
127
127
|
"GRANT UPDATE, DELETE ON `test`.* TO 'scott'@'localhost'",
|
128
128
|
"GRANT USAGE ON *.* TO 'bob'@'localhost'",
|
129
|
-
]
|
129
|
+
].normalize
|
130
130
|
end
|
131
131
|
end
|
132
132
|
end
|
@@ -76,7 +76,7 @@ end
|
|
76
76
|
"GRANT SELECT, INSERT, UPDATE, DELETE ON *.* TO 'scott'@'localhost' IDENTIFIED BY PASSWORD '*F2F68D0BB27A773C1D944270E5FAFED515A3FA40' REQUIRE SSL",
|
77
77
|
"GRANT SELECT, INSERT, UPDATE, DELETE ON `test`.* TO 'scott'@'localhost'",
|
78
78
|
"GRANT USAGE ON *.* TO 'bob'@'localhost'",
|
79
|
-
]
|
79
|
+
].normalize
|
80
80
|
end
|
81
81
|
end
|
82
82
|
|
@@ -125,7 +125,7 @@ end
|
|
125
125
|
"GRANT SELECT, INSERT, UPDATE, DELETE ON *.* TO 'scott'@'localhost' IDENTIFIED BY PASSWORD '*F2F68D0BB27A773C1D944270E5FAFED515A3FA40' REQUIRE SSL",
|
126
126
|
"GRANT SELECT, INSERT, UPDATE, DELETE ON `test`.* TO 'scott'@'localhost'",
|
127
127
|
"GRANT USAGE ON *.* TO 'bob'@'localhost'",
|
128
|
-
]
|
128
|
+
].normalize
|
129
129
|
end
|
130
130
|
end
|
131
131
|
end
|
@@ -32,7 +32,7 @@ end
|
|
32
32
|
expect(show_grants).to match_array [
|
33
33
|
"GRANT SELECT, INSERT, UPDATE, DELETE ON *.* TO 'scott'@'localhost' IDENTIFIED BY PASSWORD '*6F498C84277BCC2089932690304BD4EDABC74547'",
|
34
34
|
"GRANT SELECT, INSERT, UPDATE, DELETE ON `test`.* TO 'scott'@'localhost'",
|
35
|
-
]
|
35
|
+
].normalize
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
@@ -111,7 +111,7 @@ end
|
|
111
111
|
expect(show_grants).to match_array [
|
112
112
|
"GRANT SELECT, INSERT, UPDATE, DELETE ON *.* TO 'scott'@'localhost' IDENTIFIED BY PASSWORD '*6F498C84277BCC2089932690304BD4EDABC74547'",
|
113
113
|
"GRANT SELECT, INSERT, UPDATE, DELETE ON `test`.* TO 'scott'@'localhost'",
|
114
|
-
]
|
114
|
+
].normalize
|
115
115
|
end
|
116
116
|
end
|
117
117
|
|
@@ -30,7 +30,7 @@ end
|
|
30
30
|
"GRANT SELECT, INSERT, UPDATE, DELETE ON `test`.* TO 'scott'@'127.0.0.1'",
|
31
31
|
"GRANT SELECT, INSERT, UPDATE, DELETE ON *.* TO 'scott'@'192.168.%' IDENTIFIED BY PASSWORD '*F2F68D0BB27A773C1D944270E5FAFED515A3FA40'",
|
32
32
|
"GRANT SELECT, INSERT, UPDATE, DELETE ON `test`.* TO 'scott'@'192.168.%'",
|
33
|
-
]
|
33
|
+
].normalize
|
34
34
|
end
|
35
35
|
end
|
36
36
|
end
|
@@ -33,7 +33,7 @@ end
|
|
33
33
|
"GRANT SELECT, INSERT, UPDATE, DELETE ON `test`.* TO 'scott'@'localhost'",
|
34
34
|
"GRANT UPDATE, DELETE ON `gratan_test`.`zoo` TO 'scott'@'localhost'",
|
35
35
|
"GRANT USAGE ON *.* TO 'scott'@'localhost' IDENTIFIED BY PASSWORD '*F2F68D0BB27A773C1D944270E5FAFED515A3FA40'",
|
36
|
-
]
|
36
|
+
].normalize
|
37
37
|
end
|
38
38
|
end
|
39
39
|
end
|
@@ -38,7 +38,7 @@ end
|
|
38
38
|
expect(show_grants).to match_array [
|
39
39
|
"GRANT SELECT, INSERT, UPDATE, DELETE ON *.* TO 'scott'@'localhost' IDENTIFIED BY PASSWORD '*F2F68D0BB27A773C1D944270E5FAFED515A3FA40'",
|
40
40
|
"GRANT SELECT, INSERT, UPDATE, DELETE ON `test`.* TO 'scott'@'localhost'",
|
41
|
-
]
|
41
|
+
].normalize
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
@@ -97,7 +97,7 @@ end
|
|
97
97
|
"GRANT SELECT ON `test`.* TO 'bob'@'%'",
|
98
98
|
"GRANT SELECT, INSERT, UPDATE, DELETE ON *.* TO 'scott'@'localhost' IDENTIFIED BY PASSWORD '*F2F68D0BB27A773C1D944270E5FAFED515A3FA40'",
|
99
99
|
"GRANT SELECT, INSERT, UPDATE, DELETE ON `test`.* TO 'scott'@'localhost'",
|
100
|
-
]
|
100
|
+
].normalize
|
101
101
|
end
|
102
102
|
end
|
103
103
|
|
@@ -128,7 +128,7 @@ end
|
|
128
128
|
expect(show_grants).to match_array [
|
129
129
|
"GRANT SELECT, INSERT, UPDATE, DELETE ON *.* TO 'scott'@'localhost' IDENTIFIED BY PASSWORD '*F2F68D0BB27A773C1D944270E5FAFED515A3FA40' WITH GRANT OPTION",
|
130
130
|
"GRANT SELECT, INSERT, UPDATE, DELETE ON `test`.* TO 'scott'@'localhost'",
|
131
|
-
]
|
131
|
+
].normalize
|
132
132
|
end
|
133
133
|
end
|
134
134
|
|
@@ -36,7 +36,7 @@ end
|
|
36
36
|
expect(show_grants).to match_array [
|
37
37
|
"GRANT SELECT, INSERT, UPDATE, DELETE ON *.* TO 'scott'@'localhost' IDENTIFIED BY PASSWORD '*F2F68D0BB27A773C1D944270E5FAFED515A3FA40'",
|
38
38
|
"GRANT SELECT, INSERT, UPDATE, DELETE ON `test`.* TO 'scott'@'localhost'",
|
39
|
-
]
|
39
|
+
].normalize
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
@@ -37,7 +37,7 @@ end
|
|
37
37
|
|
38
38
|
expect(show_grants).to match_array [
|
39
39
|
"GRANT SELECT, INSERT, UPDATE, DELETE ON *.* TO 'scott'@'localhost' IDENTIFIED BY PASSWORD '*F2F68D0BB27A773C1D944270E5FAFED515A3FA40'",
|
40
|
-
]
|
40
|
+
].normalize
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
@@ -70,7 +70,7 @@ end
|
|
70
70
|
expect(show_grants).to match_array [
|
71
71
|
"GRANT SELECT, INSERT, UPDATE, DELETE ON *.* TO 'scott'@'localhost' IDENTIFIED BY PASSWORD '*F2F68D0BB27A773C1D944270E5FAFED515A3FA40'",
|
72
72
|
"GRANT SELECT, INSERT, UPDATE, DELETE ON `test`.* TO 'scott'@'localhost'",
|
73
|
-
]
|
73
|
+
].normalize
|
74
74
|
end
|
75
75
|
end
|
76
76
|
end
|
@@ -35,7 +35,7 @@ end
|
|
35
35
|
expect(show_grants).to match_array [
|
36
36
|
"GRANT SELECT ON *.* TO 'scott'@'localhost' IDENTIFIED BY PASSWORD '*F2F68D0BB27A773C1D944270E5FAFED515A3FA40'",
|
37
37
|
"GRANT SELECT, INSERT, UPDATE ON `test`.* TO 'scott'@'localhost'",
|
38
|
-
]
|
38
|
+
].normalize
|
39
39
|
end
|
40
40
|
end
|
41
41
|
end
|
@@ -55,7 +55,7 @@ end
|
|
55
55
|
"GRANT SELECT, INSERT ON *.* TO 'scott'@'localhost' IDENTIFIED BY PASSWORD '*F2F68D0BB27A773C1D944270E5FAFED515A3FA40' REQUIRE SSL",
|
56
56
|
"GRANT UPDATE, DELETE ON `test`.* TO 'scott'@'localhost'",
|
57
57
|
"GRANT USAGE ON *.* TO 'bob'@'localhost'",
|
58
|
-
]
|
58
|
+
].normalize
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
@@ -71,7 +71,7 @@ end
|
|
71
71
|
"GRANT SELECT, INSERT ON *.* TO 'scott'@'localhost' IDENTIFIED BY PASSWORD '*F2F68D0BB27A773C1D944270E5FAFED515A3FA40' REQUIRE SSL",
|
72
72
|
"GRANT UPDATE, DELETE ON `test`.* TO 'scott'@'localhost'",
|
73
73
|
"GRANT USAGE ON *.* TO 'bob'@'localhost'",
|
74
|
-
]
|
74
|
+
].normalize
|
75
75
|
end
|
76
76
|
end
|
77
77
|
end
|
@@ -127,7 +127,7 @@ end
|
|
127
127
|
"GRANT SELECT, INSERT ON *.* TO 'scott'@'localhost' IDENTIFIED BY PASSWORD '*F2F68D0BB27A773C1D944270E5FAFED515A3FA40' REQUIRE SSL",
|
128
128
|
"GRANT UPDATE, DELETE ON `test`.* TO 'scott'@'localhost'",
|
129
129
|
"GRANT USAGE ON *.* TO 'bob'@'localhost'",
|
130
|
-
]
|
130
|
+
].normalize
|
131
131
|
end
|
132
132
|
end
|
133
133
|
|
@@ -173,7 +173,7 @@ end
|
|
173
173
|
"GRANT SELECT, INSERT ON *.* TO 'scott'@'localhost' IDENTIFIED BY PASSWORD '*F2F68D0BB27A773C1D944270E5FAFED515A3FA40' REQUIRE SSL",
|
174
174
|
"GRANT UPDATE, DELETE ON `test`.* TO 'scott'@'localhost'",
|
175
175
|
"GRANT USAGE ON *.* TO 'bob'@'localhost'",
|
176
|
-
]
|
176
|
+
].normalize
|
177
177
|
end
|
178
178
|
end
|
179
179
|
end
|
data/spec/misc/misc_spec.rb
CHANGED
@@ -31,7 +31,7 @@ end
|
|
31
31
|
expect(show_grants).to match_array [
|
32
32
|
"GRANT SELECT, INSERT, UPDATE, DELETE ON *.* TO 'scott'@'localhost' IDENTIFIED BY PASSWORD '*F2F68D0BB27A773C1D944270E5FAFED515A3FA40'",
|
33
33
|
"GRANT SELECT, INSERT, UPDATE, DELETE ON `test`.* TO 'scott'@'localhost'",
|
34
|
-
]
|
34
|
+
].normalize
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
@@ -40,6 +40,7 @@ end
|
|
40
40
|
logger = Gratan::Logger.send(:new)
|
41
41
|
logger.set_debug(true)
|
42
42
|
expect(logger).to receive(:debug).with("[DEBUG] SET SQL_LOG_BIN = 0")
|
43
|
+
allow(logger).to receive(:debug).with('[DEBUG] SET SQL_MODE = ""')
|
43
44
|
expect(logger).to receive(:debug).with("[DEBUG] SELECT user, host FROM mysql.user")
|
44
45
|
expect(logger).to receive(:info).with("GRANT SELECT, INSERT, UPDATE, DELETE ON *.* TO 'scott'@'localhost' IDENTIFIED BY 'tiger'")
|
45
46
|
expect(logger).to receive(:info).with("GRANT SELECT, INSERT, UPDATE, DELETE ON `test`.* TO 'scott'@'localhost' IDENTIFIED BY 'tiger'")
|
@@ -73,7 +74,7 @@ end
|
|
73
74
|
expect(show_grants).to match_array [
|
74
75
|
"GRANT SELECT, INSERT, UPDATE, DELETE ON *.* TO 'scott'@'localhost' IDENTIFIED BY PASSWORD '*F2F68D0BB27A773C1D944270E5FAFED515A3FA40'",
|
75
76
|
"GRANT SELECT, INSERT, UPDATE, DELETE ON `test`.* TO 'scott'@'localhost'",
|
76
|
-
]
|
77
|
+
].normalize
|
77
78
|
end
|
78
79
|
end
|
79
80
|
end
|
data/spec/misc/require_spec.rb
CHANGED
@@ -33,7 +33,7 @@ require '#{f.path}'
|
|
33
33
|
expect(show_grants).to match_array [
|
34
34
|
"GRANT SELECT, INSERT, UPDATE, DELETE ON *.* TO 'scott'@'localhost' IDENTIFIED BY PASSWORD '*F2F68D0BB27A773C1D944270E5FAFED515A3FA40'",
|
35
35
|
"GRANT SELECT, INSERT, UPDATE, DELETE ON `test`.* TO 'scott'@'localhost'",
|
36
|
-
]
|
36
|
+
].normalize
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
@@ -71,7 +71,7 @@ require '#{f.path.sub(/\.rb\z/, '')}'
|
|
71
71
|
expect(show_grants).to match_array [
|
72
72
|
"GRANT SELECT, INSERT, UPDATE, DELETE ON *.* TO 'scott'@'localhost' IDENTIFIED BY PASSWORD '*F2F68D0BB27A773C1D944270E5FAFED515A3FA40'",
|
73
73
|
"GRANT SELECT, INSERT, UPDATE, DELETE ON `test`.* TO 'scott'@'localhost'",
|
74
|
-
]
|
74
|
+
].normalize
|
75
75
|
end
|
76
76
|
end
|
77
77
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -23,12 +23,18 @@ RSpec.configure do |config|
|
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
+
def mysql57?
|
27
|
+
ENV['MYSQL57'] == '1'
|
28
|
+
end
|
29
|
+
|
30
|
+
MYSQL_PORT = mysql57? ? 14407 : 14406
|
31
|
+
|
26
32
|
def mysql
|
27
33
|
client = nil
|
28
34
|
retval = nil
|
29
35
|
|
30
36
|
begin
|
31
|
-
client = Mysql2::Client.new(host: '
|
37
|
+
client = Mysql2::Client.new(host: '127.0.0.1', username: 'root', port: MYSQL_PORT)
|
32
38
|
retval = yield(client)
|
33
39
|
ensure
|
34
40
|
client.close if client
|
@@ -127,6 +133,12 @@ def show_grants
|
|
127
133
|
client.query("SHOW GRANTS FOR #{user_host}").each do |row|
|
128
134
|
grants << row.values.first
|
129
135
|
end
|
136
|
+
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
if mysql57?
|
141
|
+
grants.each do |grant|
|
130
142
|
end
|
131
143
|
end
|
132
144
|
|
@@ -139,12 +151,20 @@ def client(user_options = {})
|
|
139
151
|
end
|
140
152
|
|
141
153
|
options = {
|
142
|
-
host: '
|
154
|
+
host: '127.0.0.1',
|
143
155
|
username: 'root',
|
156
|
+
port: MYSQL_PORT,
|
144
157
|
ignore_user: IGNORE_USER,
|
145
158
|
logger: Logger.new('/dev/null'),
|
146
159
|
}
|
147
160
|
|
161
|
+
if mysql57?
|
162
|
+
options.update(
|
163
|
+
override_sql_mode: true,
|
164
|
+
use_show_create_user: true,
|
165
|
+
)
|
166
|
+
end
|
167
|
+
|
148
168
|
if ENV['DEBUG']
|
149
169
|
logger = Gratan::Logger.instance
|
150
170
|
logger.set_debug(true)
|
@@ -176,3 +196,17 @@ def apply(cli = client)
|
|
176
196
|
cli.apply(f.path)
|
177
197
|
end
|
178
198
|
end
|
199
|
+
|
200
|
+
class Array
|
201
|
+
def normalize
|
202
|
+
if mysql57?
|
203
|
+
self.map do |i|
|
204
|
+
i.sub(/ IDENTIFIED BY PASSWORD '[^']+'/, '')
|
205
|
+
.sub(/ REQUIRE \w+\b/, '')
|
206
|
+
.sub(/ WITH GRANT OPTION [\w ]+\z/, ' WITH GRANT OPTION')
|
207
|
+
end
|
208
|
+
else
|
209
|
+
self
|
210
|
+
end
|
211
|
+
end
|
212
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gratan
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.1.
|
4
|
+
version: 0.3.1.beta3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Genki Sugawara
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-11-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mysql2
|
@@ -152,6 +152,7 @@ files:
|
|
152
152
|
- README.md
|
153
153
|
- Rakefile
|
154
154
|
- bin/gratan
|
155
|
+
- docker-compose.yml
|
155
156
|
- gratan.gemspec
|
156
157
|
- lib/gratan.rb
|
157
158
|
- lib/gratan/client.rb
|
@@ -222,7 +223,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
222
223
|
version: 1.3.1
|
223
224
|
requirements: []
|
224
225
|
rubyforge_project:
|
225
|
-
rubygems_version: 2.
|
226
|
+
rubygems_version: 2.6.14.1
|
226
227
|
signing_key:
|
227
228
|
specification_version: 4
|
228
229
|
summary: Gratan is a tool to manage MySQL permissions using Ruby DSL.
|