gratan 0.2.8.beta3 → 0.2.8

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: 22edc42504e84310b6c42cc258db604b12d2831a
4
- data.tar.gz: ca89f0381b6d73f36dc315cc168d4363004284fc
3
+ metadata.gz: 26d81b1a5184f5c95e9002747d235beaad84f713
4
+ data.tar.gz: e0b0e91ac5d80e0c8aadbfc5e193b3c80629db08
5
5
  SHA512:
6
- metadata.gz: 1745cfeaeead547a61bef90ce91ddad3ef7d456d57a95c537614e9653ee61fb606d7f3d3b2b9c6447e3fc26190e29757793a1cd55f1971912425fc7e9e71cdc3
7
- data.tar.gz: 065f25f9112d28bfb76ce6ec470e6d3c83ca5642443d764bce7712d3fb8b7d973265c88fdc0c174591b5491820c2de2b6f227bd3dc276cf52a4bd4729390ed57
6
+ metadata.gz: 856c82cf61377fa8b5c050ba1be616dd195a2c27591aebabadcc60ed190f920d1e50fef0d08b9a518afd456a3e2c45e630f4c09a7dd01f433283a01bab32682c
7
+ data.tar.gz: ceffb3c590345308b87a92d48f4065c4cebb8d9ea27d4be65d6c344fc611697ce1d6ebe642ecc51f37054c105991a99d05cd4fd47307a5b69b4d754472714a82
data/.gitignore CHANGED
@@ -15,3 +15,4 @@ mkmf.log
15
15
  test.rb
16
16
  Grantfile
17
17
  *.grant
18
+ /_site/
data/README.md CHANGED
@@ -6,7 +6,7 @@ It defines the state of MySQL permissions using Ruby DSL, and updates permission
6
6
 
7
7
  [![Gem Version](https://badge.fury.io/rb/gratan.svg)](http://badge.fury.io/rb/gratan)
8
8
  [![Build Status](https://travis-ci.org/winebarrel/gratan.svg?branch=master)](https://travis-ci.org/winebarrel/gratan)
9
- [![Coverage Status](https://coveralls.io/repos/winebarrel/gratan/badge.png?branch=master)](https://coveralls.io/r/winebarrel/gratan?branch=master)
9
+ [![Coverage Status](https://coveralls.io/repos/winebarrel/gratan/badge.svg?branch=master)](https://coveralls.io/r/winebarrel/gratan?branch=master)
10
10
 
11
11
  ## Installation
12
12
 
@@ -56,6 +56,7 @@ Usage: gratan [options]
56
56
  --ignore-object REGEXP
57
57
  --enable-expired
58
58
  --ignore-not-exist
59
+ --skip-disable-log-bin
59
60
  --no-color
60
61
  --debug
61
62
  --auto-identify OUTPUT
@@ -73,7 +74,7 @@ user "scott", "%" do
73
74
  grant "USAGE"
74
75
  end
75
76
 
76
- on "test.*", expired: '2014/10/08' do
77
+ on "test.*", expired: '2014/10/08', identified: "PASSWORD '*ABCDEF'" do
77
78
  grant "SELECT"
78
79
  grant "INSERT"
79
80
  end
data/lib/gratan/driver.rb CHANGED
@@ -207,7 +207,14 @@ class Gratan::Driver
207
207
  end
208
208
 
209
209
  def quote_object(object)
210
- object.split('.', 2).map {|i| i == '*' ? i : "`#{i}`" }.join('.')
210
+ if object =~ /\A(FUNCTION|PROCEDURE)\s+/i
211
+ object_type, object = object.split(/\s+/, 2)
212
+ object_type << ' '
213
+ else
214
+ object_type = ''
215
+ end
216
+
217
+ object_type + object.split('.', 2).map {|i| i == '*' ? i : "`#{i}`" }.join('.')
211
218
  end
212
219
 
213
220
  def quote_identifier(identifier)
@@ -1,3 +1,3 @@
1
1
  module Gratan
2
- VERSION = '0.2.8.beta3'
2
+ VERSION = '0.2.8'
3
3
  end
@@ -0,0 +1,94 @@
1
+ describe 'Gratan::Client#apply' do
2
+ before(:each) do
3
+ mysql do |cli|
4
+ drop_database(cli)
5
+ create_database(cli)
6
+ create_function(cli, :my_func)
7
+ create_procedure(cli, :my_prcd)
8
+ end
9
+ end
10
+
11
+ context 'when func -> prcd' do
12
+ subject { client }
13
+
14
+ before do
15
+ apply(subject) {
16
+ <<-RUBY
17
+ user "scott", "%" do
18
+ on "*.*" do
19
+ grant "USAGE"
20
+ end
21
+
22
+ on "FUNCTION #{TEST_DATABASE}.my_func" do
23
+ grant "EXECUTE"
24
+ end
25
+ end
26
+ RUBY
27
+ }
28
+
29
+ end
30
+
31
+ it do
32
+ apply(subject) {
33
+ <<-RUBY
34
+ user "scott", "%" do
35
+ on "*.*" do
36
+ grant "USAGE"
37
+ end
38
+
39
+ on "PROCEDURE #{TEST_DATABASE}.my_prcd" do
40
+ grant "EXECUTE"
41
+ end
42
+ end
43
+ RUBY
44
+ }
45
+
46
+ expect(show_grants).to match_array [
47
+ "GRANT USAGE ON *.* TO 'scott'@'%'",
48
+ "GRANT EXECUTE ON PROCEDURE `#{TEST_DATABASE}`.`my_prcd` TO 'scott'@'%'"
49
+ ]
50
+ end
51
+ end
52
+
53
+ context 'when prcd -> func' do
54
+ subject { client }
55
+
56
+ before do
57
+ apply(subject) {
58
+ <<-RUBY
59
+ user "scott", "%" do
60
+ on "*.*" do
61
+ grant "USAGE"
62
+ end
63
+
64
+ on "PROCEDURE #{TEST_DATABASE}.my_prcd" do
65
+ grant "EXECUTE"
66
+ end
67
+ end
68
+ RUBY
69
+ }
70
+
71
+ end
72
+
73
+ it do
74
+ apply(subject) {
75
+ <<-RUBY
76
+ user "scott", "%" do
77
+ on "*.*" do
78
+ grant "USAGE"
79
+ end
80
+
81
+ on "FUNCTION #{TEST_DATABASE}.my_func" do
82
+ grant "EXECUTE"
83
+ end
84
+ end
85
+ RUBY
86
+ }
87
+
88
+ expect(show_grants).to match_array [
89
+ "GRANT USAGE ON *.* TO 'scott'@'%'",
90
+ "GRANT EXECUTE ON FUNCTION `#{TEST_DATABASE}`.`my_func` TO 'scott'@'%'"
91
+ ]
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,59 @@
1
+ describe 'Gratan::Client#apply' do
2
+ context 'when create user with function' do
3
+ subject { client }
4
+
5
+ it do
6
+ create_functions(:foo) do
7
+ result = apply(subject) {
8
+ <<-RUBY
9
+ user 'scott', 'localhost' do
10
+ on '*.*' do
11
+ grant 'USAGE'
12
+ end
13
+
14
+ on 'FUNCTION #{TEST_DATABASE}.foo' do
15
+ grant 'EXECUTE'
16
+ end
17
+ end
18
+ RUBY
19
+ }
20
+
21
+ expect(result).to be_truthy
22
+
23
+ expect(show_grants).to match_array [
24
+ "GRANT USAGE ON *.* TO 'scott'@'localhost'",
25
+ "GRANT EXECUTE ON FUNCTION `#{TEST_DATABASE}`.`foo` TO 'scott'@'localhost'"
26
+ ]
27
+ end
28
+ end
29
+ end
30
+
31
+ context 'when create user with procedure' do
32
+ subject { client }
33
+
34
+ it do
35
+ create_procedures(:foo) do
36
+ result = apply(subject) {
37
+ <<-RUBY
38
+ user 'scott', 'localhost' do
39
+ on '*.*' do
40
+ grant 'USAGE'
41
+ end
42
+
43
+ on 'PROCEDURE #{TEST_DATABASE}.foo' do
44
+ grant 'EXECUTE'
45
+ end
46
+ end
47
+ RUBY
48
+ }
49
+
50
+ expect(result).to be_truthy
51
+
52
+ expect(show_grants).to match_array [
53
+ "GRANT USAGE ON *.* TO 'scott'@'localhost'",
54
+ "GRANT EXECUTE ON PROCEDURE `#{TEST_DATABASE}`.`foo` TO 'scott'@'localhost'"
55
+ ]
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,69 @@
1
+ describe 'Gratan::Client#export' do
2
+ context 'when function exists' do
3
+ let(:grantfile) {
4
+ <<-RUBY
5
+ user "scott", "%" do
6
+ on "*.*" do
7
+ grant "USAGE"
8
+ end
9
+
10
+ on "FUNCTION #{TEST_DATABASE}.my_func" do
11
+ grant "EXECUTE"
12
+ end
13
+ end
14
+ RUBY
15
+ }
16
+
17
+ subject { client }
18
+
19
+ before do
20
+ mysql do |cli|
21
+ drop_database(cli)
22
+ create_database(cli)
23
+ create_function(cli, :my_func)
24
+ end
25
+
26
+ apply(subject) do
27
+ grantfile
28
+ end
29
+ end
30
+
31
+ it do
32
+ expect(subject.export.strip).to eq grantfile.strip
33
+ end
34
+ end
35
+
36
+ context 'when procedure exists' do
37
+ let(:grantfile) {
38
+ <<-RUBY
39
+ user "scott", "%" do
40
+ on "*.*" do
41
+ grant "USAGE"
42
+ end
43
+
44
+ on "PROCEDURE #{TEST_DATABASE}.my_prcd" do
45
+ grant "EXECUTE"
46
+ end
47
+ end
48
+ RUBY
49
+ }
50
+
51
+ subject { client }
52
+
53
+ before do
54
+ mysql do |cli|
55
+ drop_database(cli)
56
+ create_database(cli)
57
+ create_procedure(cli, :my_prcd)
58
+ end
59
+
60
+ apply(subject) do
61
+ grantfile
62
+ end
63
+ end
64
+
65
+ it do
66
+ expect(subject.export.strip).to eq grantfile.strip
67
+ end
68
+ end
69
+ end
data/spec/spec_helper.rb CHANGED
@@ -49,6 +49,14 @@ def create_table(client, table)
49
49
  client.query("CREATE TABLE #{TEST_DATABASE}.#{table} (id INT)")
50
50
  end
51
51
 
52
+ def create_function(client, func)
53
+ client.query("CREATE FUNCTION #{TEST_DATABASE}.#{func}() RETURNS INT RETURN 1")
54
+ end
55
+
56
+ def create_procedure(client, prcd)
57
+ client.query("CREATE PROCEDURE #{TEST_DATABASE}.#{prcd}() SELECT 1")
58
+ end
59
+
52
60
  def create_tables(*tables)
53
61
  mysql do |client|
54
62
  begin
@@ -62,6 +70,32 @@ def create_tables(*tables)
62
70
  end
63
71
  end
64
72
 
73
+ def create_functions(*funcs)
74
+ mysql do |client|
75
+ begin
76
+ drop_database(client)
77
+ create_database(client)
78
+ funcs.each {|i| create_function(client, i) }
79
+ yield
80
+ ensure
81
+ drop_database(client)
82
+ end
83
+ end
84
+ end
85
+
86
+ def create_procedures(*prcds)
87
+ mysql do |client|
88
+ begin
89
+ drop_database(client)
90
+ create_database(client)
91
+ prcds.each {|i| create_procedure(client, i) }
92
+ yield
93
+ ensure
94
+ drop_database(client)
95
+ end
96
+ end
97
+ end
98
+
65
99
  def select_users(client)
66
100
  users = []
67
101
 
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.2.8.beta3
4
+ version: 0.2.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Genki Sugawara
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-06 00:00:00.000000000 Z
11
+ date: 2015-05-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mysql2
@@ -161,6 +161,7 @@ files:
161
161
  - spec/change/change_grants_3_spec.rb
162
162
  - spec/change/change_grants_4_spec.rb
163
163
  - spec/change/change_grants_expired_spec.rb
164
+ - spec/change/change_grants_func_prcd_spec.rb
164
165
  - spec/change/change_grants_ignore_not_exist_spec.rb
165
166
  - spec/change/change_grants_multi_hosts_spec.rb
166
167
  - spec/change/change_grants_regexp_spec.rb
@@ -173,11 +174,13 @@ files:
173
174
  - spec/create/create_user_regexp_spec.rb
174
175
  - spec/create/create_user_spec.rb
175
176
  - spec/create/create_user_target_spec.rb
177
+ - spec/create/create_user_with_func_prcd_spec.rb
176
178
  - spec/create/create_user_with_ignore_object_spec.rb
177
179
  - spec/drop/drop_user_2_spec.rb
178
180
  - spec/drop/drop_user_spec.rb
179
181
  - spec/drop/expire_user_spec.rb
180
182
  - spec/export/export_chunk_spec.rb
183
+ - spec/export/export_func_prcd_spec.rb
181
184
  - spec/export/export_spec.rb
182
185
  - spec/export/export_with_ignore_object_spec.rb
183
186
  - spec/misc/misc_spec.rb
@@ -198,9 +201,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
198
201
  version: '0'
199
202
  required_rubygems_version: !ruby/object:Gem::Requirement
200
203
  requirements:
201
- - - '>'
204
+ - - '>='
202
205
  - !ruby/object:Gem::Version
203
- version: 1.3.1
206
+ version: '0'
204
207
  requirements: []
205
208
  rubyforge_project:
206
209
  rubygems_version: 2.0.14
@@ -212,6 +215,7 @@ test_files:
212
215
  - spec/change/change_grants_3_spec.rb
213
216
  - spec/change/change_grants_4_spec.rb
214
217
  - spec/change/change_grants_expired_spec.rb
218
+ - spec/change/change_grants_func_prcd_spec.rb
215
219
  - spec/change/change_grants_ignore_not_exist_spec.rb
216
220
  - spec/change/change_grants_multi_hosts_spec.rb
217
221
  - spec/change/change_grants_regexp_spec.rb
@@ -224,11 +228,13 @@ test_files:
224
228
  - spec/create/create_user_regexp_spec.rb
225
229
  - spec/create/create_user_spec.rb
226
230
  - spec/create/create_user_target_spec.rb
231
+ - spec/create/create_user_with_func_prcd_spec.rb
227
232
  - spec/create/create_user_with_ignore_object_spec.rb
228
233
  - spec/drop/drop_user_2_spec.rb
229
234
  - spec/drop/drop_user_spec.rb
230
235
  - spec/drop/expire_user_spec.rb
231
236
  - spec/export/export_chunk_spec.rb
237
+ - spec/export/export_func_prcd_spec.rb
232
238
  - spec/export/export_spec.rb
233
239
  - spec/export/export_with_ignore_object_spec.rb
234
240
  - spec/misc/misc_spec.rb