gratan 0.2.3 → 0.2.4

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: 0a2b2f0b324787b466435a74790f4c028e32578c
4
- data.tar.gz: 6cc2d13824a99016c8845ba5ed4b6eb231695d65
3
+ metadata.gz: e05682c907c1fe62bbe627e89029656293f73cee
4
+ data.tar.gz: 4fc1a578ad94f8acbf50bfc006a2187bffb53ec8
5
5
  SHA512:
6
- metadata.gz: 93faec5b23265a98288d318efca14aea6a226713c96af145238b8bfb5f405f24c5741894f7a7547b83ed423f49086aa967e7f16c53c7461d99962218511d161b
7
- data.tar.gz: 65964c219ade408dd5d1d4435aa4ab9d297874c844462f50b7de727ef7d8a216659101d0675be60c5942043142faaabc2f4abcd47752d33c9cad8f47cfd43f3a
6
+ metadata.gz: a3c03ecaa3d3f4d4b17778e1ea324e62ad50eaccad230fb5bacea75b4b9b6e80cabd7e904138db0f227120685ebe2565c01c8c41587921c4b6b592b30f7f239c
7
+ data.tar.gz: e2b836e3061aeeb482a7e879578670527777b7dd89441020f5b89a4d6503c20f2234a4d28cee1047db390c2e49e857b08502ccfa5198bada0b3b8556cf5e114e
data/README.md CHANGED
@@ -53,6 +53,7 @@ Usage: gratan [options]
53
53
  --ignore-user REGEXP
54
54
  --target-user REGEXP
55
55
  --enable-expired
56
+ --ignore-not-exist
56
57
  --no-color
57
58
  --debug
58
59
  --auto-identify OUTPUT
data/bin/gratan CHANGED
@@ -26,24 +26,25 @@ options = {
26
26
 
27
27
  ARGV.options do |opt|
28
28
  begin
29
- opt.on('' , '--host HOST') {|v| mysql_options[:host] = v }
30
- opt.on('' , '--port PORT', Integer) {|v| mysql_options[:port] = v }
31
- opt.on('' , '--socket SOCKET') {|v| mysql_options[:socket] = v }
32
- opt.on('' , '--username USERNAME') {|v| mysql_options[:username] = v }
33
- opt.on('' , '--password PASSWORD') {|v| mysql_options[:password] = v }
34
- opt.on('' , '--database DATABASE') {|v| mysql_options[:database] = v }
35
- opt.on('-a', '--apply') { mode = :apply }
36
- opt.on('-f', '--file FILE') {|v| file = v }
37
- opt.on('' , '--dry-run') { options[:dry_run] = true }
38
- opt.on('-e', '--export') { mode = :export }
39
- opt.on('' , '--with-identifier') { options[:with_identifier] = true }
40
- opt.on('' , '--split') { split = true }
41
- opt.on('-o', '--output FILE') {|v| output_file = v }
42
- opt.on('' , '--ignore-user REGEXP') {|v| options[:ignore_user] = Regexp.new(v) }
43
- opt.on('' , '--target-user REGEXP') {|v| options[:target_user] = Regexp.new(v) }
44
- opt.on('' , '--enable-expired') { options[:enable_expired] = true }
45
- opt.on('' , '--no-color') { options[:color] = false }
46
- opt.on('' , '--debug') { options[:debug] = true }
29
+ opt.on('' , '--host HOST') {|v| mysql_options[:host] = v }
30
+ opt.on('' , '--port PORT', Integer) {|v| mysql_options[:port] = v }
31
+ opt.on('' , '--socket SOCKET') {|v| mysql_options[:socket] = v }
32
+ opt.on('' , '--username USERNAME') {|v| mysql_options[:username] = v }
33
+ opt.on('' , '--password PASSWORD') {|v| mysql_options[:password] = v }
34
+ opt.on('' , '--database DATABASE') {|v| mysql_options[:database] = v }
35
+ opt.on('-a', '--apply') { mode = :apply }
36
+ opt.on('-f', '--file FILE') {|v| file = v }
37
+ opt.on('' , '--dry-run') { options[:dry_run] = true }
38
+ opt.on('-e', '--export') { mode = :export }
39
+ opt.on('' , '--with-identifier') { options[:with_identifier] = true }
40
+ opt.on('' , '--split') { split = true }
41
+ opt.on('-o', '--output FILE') {|v| output_file = v }
42
+ opt.on('' , '--ignore-user REGEXP') {|v| options[:ignore_user] = Regexp.new(v) }
43
+ opt.on('' , '--target-user REGEXP') {|v| options[:target_user] = Regexp.new(v) }
44
+ opt.on('' , '--enable-expired') { options[:enable_expired] = true }
45
+ opt.on('' , '--ignore-not-exist') {|v| options[:ignore_not_exist] = true }
46
+ opt.on('' , '--no-color') { options[:color] = false }
47
+ opt.on('' , '--debug') { options[:debug] = true }
47
48
  opt.on('' , '--auto-identify OUTPUT') {|v| options[:identifier] = Gratan::Identifier::Auto.new(v, options) }
48
49
  opt.on('' , '--csv-identify CSV') {|v| options[:identifier] = Gratan::Identifier::CSV.new(v, options) }
49
50
 
@@ -1,6 +1,8 @@
1
1
  class Gratan::Driver
2
2
  include Gratan::Logger::Helper
3
3
 
4
+ ER_NO_SUCH_TABLE = 1146
5
+
4
6
  def initialize(client, options = {})
5
7
  @client = client
6
8
  @options = options
@@ -84,7 +86,15 @@ class Gratan::Driver
84
86
  sql << " REQUIRE #{required}" if required
85
87
  sql << " WITH #{with_option}" if with_option
86
88
 
87
- update(sql)
89
+ begin
90
+ update(sql)
91
+ rescue Mysql2::Error => e
92
+ if @options[:ignore_not_exist] and e.error_number == ER_NO_SUCH_TABLE
93
+ log(:warn, e.message, :color => :yellow)
94
+ else
95
+ raise e
96
+ end
97
+ end
88
98
  end
89
99
 
90
100
  def identify(user, host, identifier)
@@ -1,3 +1,3 @@
1
1
  module Gratan
2
- VERSION = '0.2.3'
2
+ VERSION = '0.2.4'
3
3
  end
@@ -0,0 +1,96 @@
1
+ describe 'Gratan::Client#apply' do
2
+ context 'when grant privs (ignore_not_exist: true)' do
3
+ let(:logger) do
4
+ logger = Logger.new('/dev/null')
5
+ expect(logger).to receive(:warn).with("[WARN] Table 'yamada.taro' doesn't exist")
6
+ logger
7
+ end
8
+
9
+ subject do
10
+ client(
11
+ ignore_not_exist: true,
12
+ logger: logger
13
+ )
14
+ end
15
+
16
+ before do
17
+ apply {
18
+ <<-RUBY
19
+ user 'scott', 'localhost', identified: 'tiger', required: 'SSL' do
20
+ on '*.*' do
21
+ grant 'SELECT'
22
+ grant 'INSERT'
23
+ end
24
+ end
25
+ RUBY
26
+ }
27
+ end
28
+
29
+ it do
30
+ apply(subject) {
31
+ <<-RUBY
32
+ user 'scott', 'localhost', required: 'SSL' do
33
+ on '*.*' do
34
+ grant 'SELECT'
35
+ grant 'INSERT'
36
+ grant 'UPDATE'
37
+ grant 'DELETE'
38
+ end
39
+
40
+ on 'yamada.taro' do
41
+ grant 'SELECT'
42
+ grant 'INSERT'
43
+ grant 'UPDATE'
44
+ grant 'DELETE'
45
+ end
46
+ end
47
+ RUBY
48
+ }
49
+
50
+ expect(show_grants).to match_array [
51
+ "GRANT SELECT, INSERT, UPDATE, DELETE ON *.* TO 'scott'@'localhost' IDENTIFIED BY PASSWORD '*F2F68D0BB27A773C1D944270E5FAFED515A3FA40' REQUIRE SSL",
52
+ ]
53
+ end
54
+ end
55
+
56
+ context 'when grant privs (ignore_not_exist: false)' do
57
+ subject { client(ignore_not_exist: false) }
58
+
59
+ before do
60
+ apply {
61
+ <<-RUBY
62
+ user 'scott', 'localhost', identified: 'tiger', required: 'SSL' do
63
+ on '*.*' do
64
+ grant 'SELECT'
65
+ grant 'INSERT'
66
+ end
67
+ end
68
+ RUBY
69
+ }
70
+ end
71
+
72
+ it do
73
+ dsl = <<-RUBY
74
+ user 'scott', 'localhost', required: 'SSL' do
75
+ on '*.*' do
76
+ grant 'SELECT'
77
+ grant 'INSERT'
78
+ grant 'UPDATE'
79
+ grant 'DELETE'
80
+ end
81
+
82
+ on 'yamada.taro' do
83
+ grant 'SELECT'
84
+ grant 'INSERT'
85
+ grant 'UPDATE'
86
+ grant 'DELETE'
87
+ end
88
+ end
89
+ RUBY
90
+
91
+ expect {
92
+ apply(subject) { dsl }
93
+ }.to raise_error("Table 'yamada.taro' doesn't exist")
94
+ end
95
+ end
96
+ 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.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Genki Sugawara
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-08 00:00:00.000000000 Z
11
+ date: 2014-10-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mysql2
@@ -147,6 +147,7 @@ files:
147
147
  - spec/change/change_grants_3_spec.rb
148
148
  - spec/change/change_grants_4_spec.rb
149
149
  - spec/change/change_grants_expired_spec.rb
150
+ - spec/change/change_grants_ignore_not_exist_spec.rb
150
151
  - spec/change/change_grants_multi_hosts_spec.rb
151
152
  - spec/change/change_grants_regexp_spec.rb
152
153
  - spec/change/change_grants_spec.rb
@@ -184,7 +185,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
184
185
  version: '0'
185
186
  requirements: []
186
187
  rubyforge_project:
187
- rubygems_version: 2.0.14
188
+ rubygems_version: 2.4.1
188
189
  signing_key:
189
190
  specification_version: 4
190
191
  summary: Gratan is a tool to manage MySQL permissions using Ruby DSL.
@@ -193,6 +194,7 @@ test_files:
193
194
  - spec/change/change_grants_3_spec.rb
194
195
  - spec/change/change_grants_4_spec.rb
195
196
  - spec/change/change_grants_expired_spec.rb
197
+ - spec/change/change_grants_ignore_not_exist_spec.rb
196
198
  - spec/change/change_grants_multi_hosts_spec.rb
197
199
  - spec/change/change_grants_regexp_spec.rb
198
200
  - spec/change/change_grants_spec.rb