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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5425c0a9aa38492a759347509b0d2b85d2d1f2da
4
- data.tar.gz: 11d798dab701b73a2d32ed932022df154b07e494
3
+ metadata.gz: adaa06d400536360b941da3222d0ae6530087401
4
+ data.tar.gz: e479b4afd4f858d641dbe8e99c21734db7d771b4
5
5
  SHA512:
6
- metadata.gz: 6d7eea32c84fc8679e390bc02a536b1218a617250c7e2b9359eaf70a9fc4c3aeeae31aab313833f4871619110a9e43812fedbf2fd5074df90e330e1d0d2e2747
7
- data.tar.gz: 62bbd5a36c27d1d69ad0c80f6fdfb1283544338a2688c933a66b2ff1c1712ebbac45e742c01dd6a145a1579ad9b7b0bf36a92800966265dd05b75fd49a4cd111
6
+ metadata.gz: 0ccef9c558666e71ae5ba4c4acd3a43a7475bdcc047fe030e19cee7b7d7e1af8086100f55c191f5112fdbadc89fb3b1ec18d05276cb276f87df069b0c62d4895
7
+ data.tar.gz: 4f713f1a7e9c57d0bb6f1874f03d4d79f602ebdc25972212d2af2d96fd1d80e4ad38e98e9d6abe0d3dd9d71953394464180fc678af085199643a315e9648c179
@@ -1,26 +1,28 @@
1
1
  sudo: true
2
2
  language: ruby
3
3
  rvm:
4
- - 2.0.0
5
- - 2.1
6
- - 2.2
7
- script:
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
- env:
11
- - MYSQL_VERSION=5.6.27
12
- before_install:
13
- - gem update bundler
14
- install:
15
- - "sudo apt-get -y remove mysql-common mysql-server-5.5 mysql-server-core-5.5 mysql-client-5.5 mysql-client-core-5.5"
16
- - "sudo apt-get -y autoremove"
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) }
@@ -0,0 +1,12 @@
1
+ mysql56:
2
+ image: "mysql:5.6"
3
+ ports:
4
+ - "14406:3306"
5
+ environment:
6
+ MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
7
+ mysql57:
8
+ image: "mysql:5.7"
9
+ ports:
10
+ - "14407:3306"
11
+ environment:
12
+ MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
@@ -245,6 +245,7 @@ class Gratan::Client
245
245
 
246
246
  begin
247
247
  @driver.disable_log_bin_local
248
+ @driver.override_sql_mode
248
249
  @updated = false
249
250
  yield
250
251
  updated = @updated
@@ -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)
@@ -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
 
@@ -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 required
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
@@ -1,3 +1,3 @@
1
1
  module Gratan
2
- VERSION = '0.3.1.beta2'
2
+ VERSION = '0.3.1.beta3'
3
3
  end
@@ -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
@@ -49,7 +49,7 @@ end
49
49
 
50
50
  expect(show_grants).to match_array [
51
51
  "GRANT SELECT, INSERT, UPDATE, DELETE ON *.* TO 'scott'@'localhost' IDENTIFIED BY PASSWORD '*F2F68D0BB27A773C1D944270E5FAFED515A3FA40' REQUIRE SSL",
52
- ]
52
+ ].normalize
53
53
  end
54
54
  end
55
55
 
@@ -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
 
@@ -81,7 +81,7 @@ end
81
81
  expect(show_grants).to match_array [
82
82
  "GRANT ALL PRIVILEGES ON *.* TO 'bob'@'%' REQUIRE SSL",
83
83
  "GRANT SELECT ON `test`.* TO 'bob'@'%'",
84
- ]
84
+ ].normalize
85
85
  end
86
86
  end
87
87
 
@@ -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
@@ -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
@@ -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
@@ -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: 'localhost', username: 'root')
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: 'localhost',
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.beta2
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: 2016-12-11 00:00:00.000000000 Z
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.5.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.