Skip to content
This repository has been archived by the owner on May 31, 2024. It is now read-only.

Commit

Permalink
Merge pull request #10 from winebarrel/v0.2.7
Browse files Browse the repository at this point in the history
v0.2.7
  • Loading branch information
I left from github. probably... committed Nov 5, 2014
2 parents 9ad8ee4 + 2675615 commit 16f3a3a
Show file tree
Hide file tree
Showing 10 changed files with 333 additions and 10 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ Usage: gratan [options]
-o, --output FILE
--ignore-user REGEXP
--target-user REGEXP
--ignore-object REGEXP
--enable-expired
--ignore-not-exist
--no-color
Expand Down
1 change: 1 addition & 0 deletions bin/gratan
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ ARGV.options do |opt|
opt.on('-o', '--output FILE') {|v| output_file = v }
opt.on('' , '--ignore-user REGEXP') {|v| options[:ignore_user] = Regexp.new(v) }
opt.on('' , '--target-user REGEXP') {|v| options[:target_user] = Regexp.new(v) }
opt.on('' , '--ignore-object REGEXP') {|v| options[:ignore_object] = Regexp.new(v) }
opt.on('' , '--enable-expired') { options[:enable_expired] = true }
opt.on('' , '--ignore-not-exist') {|v| options[:ignore_not_exist] = true }
opt.on('' , '--no-color') { options[:color] = false }
Expand Down
8 changes: 6 additions & 2 deletions lib/gratan/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,13 @@ def show_all_tables

def expand_object(object_or_regexp)
if object_or_regexp.kind_of?(Regexp)
show_all_tables.select {|i| i =~ object_or_regexp }
objects = show_all_tables.select {|i| i =~ object_or_regexp }
else
[object_or_regexp]
objects = [object_or_regexp]
end

objects.select do |object|
object !~ @options[:ignore_object]
end
end

Expand Down
4 changes: 2 additions & 2 deletions lib/gratan/dsl/converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def output_user_options(options)
end

def output_objects(objects)
objects.map {|object, grant|
objects.sort_by {|k, v| k }.map {|object, grant|
options = output_object_options(grant)

<<-EOS
Expand All @@ -61,7 +61,7 @@ def output_object_options(grant)
end

def output_grant(grant)
grant[:privs].map {|priv|
grant[:privs].sort.map {|priv|
<<-EOS
grant #{priv.inspect}
EOS
Expand Down
1 change: 1 addition & 0 deletions lib/gratan/exporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def pack(grants)
host = grant.delete(:host)
user_host = [user, host]
object = grant.delete(:object)
next if object =~ @options[:ignore_object]
identified = grant.delete(:identified)
required = grant.delete(:require)

Expand Down
2 changes: 1 addition & 1 deletion lib/gratan/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Gratan
VERSION = '0.2.6'
VERSION = '0.2.7'
end
131 changes: 131 additions & 0 deletions spec/change/change_grants_with_ignore_object_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
describe 'Gratan::Client#apply' do
before(:each) do
apply {
<<-RUBY
user 'scott', 'localhost', identified: 'tiger', required: 'SSL' do
on '*.*' do
grant 'SELECT'
grant 'INSERT'
end
on 'test.*' do
grant 'UPDATE'
grant 'DELETE'
end
on 'mysql.user' do
grant 'SELECT (user)'
end
end
user 'bob', 'localhost' do
on '*.*' do
grant 'USAGE'
end
on 'test.*' do
grant 'ALL PRIVILEGES'
end
end
RUBY
}
end

context 'when grant privs with ignore_object' do
subject { client(ignore_object: /user/) }

it do
apply(subject) {
<<-RUBY
user 'scott', 'localhost', identified: 'tiger', required: 'SSL' do
on '*.*' do
grant 'SELECT'
grant 'INSERT'
grant 'UPDATE'
grant 'DELETE'
end
on 'test.*' do
grant 'SELECT'
grant 'INSERT'
grant 'UPDATE'
grant 'DELETE'
end
on 'mysql.user' do
grant 'SELECT (user)'
grant 'UPDATE (host)' # ignore
end
end
user 'bob', 'localhost' do
on '*.*' do
grant 'USAGE'
end
on 'test.*' do
grant 'ALL PRIVILEGES'
end
end
RUBY
}

expect(show_grants).to match_array [
"GRANT ALL PRIVILEGES ON `test`.* TO 'bob'@'localhost'",
"GRANT SELECT (user) ON `mysql`.`user` TO 'scott'@'localhost'",
"GRANT SELECT, INSERT, UPDATE, DELETE ON *.* TO 'scott'@'localhost' IDENTIFIED BY PASSWORD '*F2F68D0BB27A773C1D944270E5FAFED515A3FA40' REQUIRE SSL",
"GRANT SELECT, INSERT, UPDATE, DELETE ON `test`.* TO 'scott'@'localhost'",
"GRANT USAGE ON *.* TO 'bob'@'localhost'",
]
end
end

context 'when grant privs with ignore_object (2)' do
subject { client(ignore_object: /user2/) }

it do
apply(subject) {
<<-RUBY
user 'scott', 'localhost', identified: 'tiger', required: 'SSL' do
on '*.*' do
grant 'SELECT'
grant 'INSERT'
grant 'UPDATE'
grant 'DELETE'
end
on 'test.*' do
grant 'SELECT'
grant 'INSERT'
grant 'UPDATE'
grant 'DELETE'
end
on 'mysql.user' do
grant 'SELECT (user)'
grant 'UPDATE (host)'
end
end
user 'bob', 'localhost' do
on '*.*' do
grant 'USAGE'
end
on 'test.*' do
grant 'ALL PRIVILEGES'
end
end
RUBY
}

expect(show_grants).to match_array [
"GRANT ALL PRIVILEGES ON `test`.* TO 'bob'@'localhost'",
"GRANT SELECT (user), UPDATE (host) ON `mysql`.`user` TO 'scott'@'localhost'",
"GRANT SELECT, INSERT, UPDATE, DELETE ON *.* TO 'scott'@'localhost' IDENTIFIED BY PASSWORD '*F2F68D0BB27A773C1D944270E5FAFED515A3FA40' REQUIRE SSL",
"GRANT SELECT, INSERT, UPDATE, DELETE ON `test`.* TO 'scott'@'localhost'",
"GRANT USAGE ON *.* TO 'bob'@'localhost'",
]
end
end
end
76 changes: 76 additions & 0 deletions spec/create/create_user_with_ignore_object_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
describe 'Gratan::Client#apply' do
context 'when user does not exist' do
subject { client }

it do
result = apply(subject) { '' }
expect(result).to be_falsey
expect(show_grants).to match_array []
end
end

context 'when create user with ignore_object' do
subject { client(ignore_object: /test/) }

it do
result = apply(subject) {
<<-RUBY
user 'scott', 'localhost', identified: 'tiger' do
on '*.*' do
grant 'SELECT'
grant 'INSERT'
grant 'UPDATE'
grant 'DELETE'
end
on 'test.*' do
grant 'SELECT'
grant 'INSERT'
grant 'UPDATE'
grant 'DELETE'
end
end
RUBY
}

expect(result).to be_truthy

expect(show_grants).to match_array [
"GRANT SELECT, INSERT, UPDATE, DELETE ON *.* TO 'scott'@'localhost' IDENTIFIED BY PASSWORD '*F2F68D0BB27A773C1D944270E5FAFED515A3FA40'",
]
end
end

context 'when create user with ignore_object (2)' do
subject { client(ignore_object: /test2/) }

it do
result = apply(subject) {
<<-RUBY
user 'scott', 'localhost', identified: 'tiger' do
on '*.*' do
grant 'SELECT'
grant 'INSERT'
grant 'UPDATE'
grant 'DELETE'
end
on 'test.*' do
grant 'SELECT'
grant 'INSERT'
grant 'UPDATE'
grant 'DELETE'
end
end
RUBY
}

expect(result).to be_truthy

expect(show_grants).to match_array [
"GRANT SELECT, INSERT, UPDATE, DELETE ON *.* TO 'scott'@'localhost' IDENTIFIED BY PASSWORD '*F2F68D0BB27A773C1D944270E5FAFED515A3FA40'",
"GRANT SELECT, INSERT, UPDATE, DELETE ON `test`.* TO 'scott'@'localhost'",
]
end
end
end
10 changes: 5 additions & 5 deletions spec/export/export_chunk_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@
grant "SELECT"
end
on "test3.*" do
grant "UPDATE"
grant "DELETE"
end
on "test2.*" do
grant "INSERT"
end
on "test3.*" do
grant "DELETE"
grant "UPDATE"
end
end
RUBY
end
Expand Down

0 comments on commit 16f3a3a

Please sign in to comment.