gratan 0.1.7 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/gratan/dsl/context.rb +1 -1
- data/lib/gratan/dsl/context/on.rb +6 -2
- data/lib/gratan/dsl/context/user.rb +14 -3
- data/lib/gratan/dsl/validator.rb +2 -2
- data/lib/gratan/logger.rb +1 -0
- data/lib/gratan/version.rb +1 -1
- data/spec/change/change_grants_expired_spec.rb +138 -0
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3652b6032331534d479d99c2b543327ddc15f645
|
4
|
+
data.tar.gz: eb14f74f6d20959b8c1a74b65a8d63df3b13c891
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8564bed70a26a922920c115dd4db0dbffeea38c0e54a73b9ebf3931fee3521e95195f5cc93ab92d2c0e0347ae49d5281e6637380f2524f7fb8b9bfa9d1a00769
|
7
|
+
data.tar.gz: f6c014b19e44f3bfd11a0c93bbaa2bb70822d23042a4beaa86e3641b32d6680bcb5501d9f00e60c27622644ddf57fb4eb1f5ef13b1650e1d5eb21690b4b85fc9
|
data/README.md
CHANGED
data/lib/gratan/dsl/context.rb
CHANGED
@@ -3,8 +3,12 @@ class Gratan::DSL::Context::On
|
|
3
3
|
|
4
4
|
attr_reader :result
|
5
5
|
|
6
|
-
def initialize(user, host, object, &block)
|
7
|
-
@
|
6
|
+
def initialize(user, host, object, options, &block)
|
7
|
+
@object_identifier = "User `#{user}@#{host}` on `#{object}`"
|
8
|
+
@user = user
|
9
|
+
@host = host
|
10
|
+
@object = object
|
11
|
+
@options = options
|
8
12
|
@result = []
|
9
13
|
instance_eval(&block)
|
10
14
|
end
|
@@ -1,12 +1,14 @@
|
|
1
1
|
class Gratan::DSL::Context::User
|
2
2
|
include Gratan::DSL::Validator
|
3
|
+
include Gratan::Logger::Helper
|
3
4
|
|
4
5
|
attr_reader :result
|
5
6
|
|
6
|
-
def initialize(user, host, &block)
|
7
|
-
@
|
7
|
+
def initialize(user, host, options, &block)
|
8
|
+
@object_identifier = "User `#{user}@#{host}`"
|
8
9
|
@user = user
|
9
10
|
@host = host
|
11
|
+
@options = options
|
10
12
|
@result = {}
|
11
13
|
instance_eval(&block)
|
12
14
|
end
|
@@ -18,7 +20,16 @@ class Gratan::DSL::Context::User
|
|
18
20
|
not @result.has_key?(name)
|
19
21
|
end
|
20
22
|
|
21
|
-
|
23
|
+
if @options[:enable_expired] and (expired = options.delete(:expired))
|
24
|
+
expired = Time.parse(expired)
|
25
|
+
|
26
|
+
if Time.new >= expired
|
27
|
+
log(:warn, "Object `#{name}` has expired", :color => :yellow)
|
28
|
+
return
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
grant = {:privs => Gratan::DSL::Context::On.new(@user, @host, name, @options, &block).result}
|
22
33
|
grant[:with] = options[:with] if options[:with]
|
23
34
|
@result[name] = grant
|
24
35
|
end
|
data/lib/gratan/dsl/validator.rb
CHANGED
data/lib/gratan/logger.rb
CHANGED
@@ -18,6 +18,7 @@ class Gratan::Logger < ::Logger
|
|
18
18
|
module Helper
|
19
19
|
def log(level, message, options = {})
|
20
20
|
global_options = @options || {}
|
21
|
+
message = "#{@object_identifier}: #{message}" if @object_identifier
|
21
22
|
message = "[#{level.to_s.upcase}] #{message}" unless level == :info
|
22
23
|
|
23
24
|
if global_options[:dry_run] and options[:dry_run] != false
|
data/lib/gratan/version.rb
CHANGED
@@ -0,0 +1,138 @@
|
|
1
|
+
describe 'Gratan::Client#apply' do
|
2
|
+
before(:each) do
|
3
|
+
apply {
|
4
|
+
<<-RUBY
|
5
|
+
user 'scott', 'localhost', identified: 'tiger', required: 'SSL' do
|
6
|
+
on '*.*' do
|
7
|
+
grant 'SELECT'
|
8
|
+
grant 'INSERT'
|
9
|
+
end
|
10
|
+
|
11
|
+
on 'test.*' do
|
12
|
+
grant 'UPDATE'
|
13
|
+
grant 'DELETE'
|
14
|
+
end
|
15
|
+
|
16
|
+
on 'mysql.user' do
|
17
|
+
grant 'SELECT (user)'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
RUBY
|
21
|
+
}
|
22
|
+
end
|
23
|
+
|
24
|
+
context 'when object has expired' do
|
25
|
+
let(:logger) do
|
26
|
+
logger = Logger.new('/dev/null')
|
27
|
+
expect(logger).to receive(:warn).with('[WARN] User `scott@localhost`: Object `test.*` has expired')
|
28
|
+
logger
|
29
|
+
end
|
30
|
+
|
31
|
+
subject do
|
32
|
+
client(
|
33
|
+
enable_expired: true,
|
34
|
+
logger: logger
|
35
|
+
)
|
36
|
+
end
|
37
|
+
|
38
|
+
it do
|
39
|
+
dsl = <<-RUBY
|
40
|
+
user 'scott', 'localhost', required: 'SSL' do
|
41
|
+
on '*.*' do
|
42
|
+
grant 'SELECT'
|
43
|
+
grant 'INSERT'
|
44
|
+
end
|
45
|
+
|
46
|
+
on 'test.*', expired: '2014/10/06' do
|
47
|
+
grant 'UPDATE'
|
48
|
+
grant 'DELETE'
|
49
|
+
end
|
50
|
+
|
51
|
+
on 'mysql.user' do
|
52
|
+
grant 'SELECT (user)'
|
53
|
+
end
|
54
|
+
end
|
55
|
+
RUBY
|
56
|
+
|
57
|
+
Timecop.freeze(Time.parse('2014/10/06')) do
|
58
|
+
apply(subject) { dsl }
|
59
|
+
end
|
60
|
+
|
61
|
+
expect(show_grants).to match_array [
|
62
|
+
"GRANT SELECT (user) ON `mysql`.`user` TO 'scott'@'localhost'",
|
63
|
+
"GRANT SELECT, INSERT ON *.* TO 'scott'@'localhost' IDENTIFIED BY PASSWORD '*F2F68D0BB27A773C1D944270E5FAFED515A3FA40' REQUIRE SSL",
|
64
|
+
]
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
context 'when object has not expired' do
|
69
|
+
subject { client(enable_expired: true) }
|
70
|
+
|
71
|
+
it do
|
72
|
+
dsl = <<-RUBY
|
73
|
+
user 'scott', 'localhost', required: 'SSL' do
|
74
|
+
on '*.*' do
|
75
|
+
grant 'SELECT'
|
76
|
+
grant 'INSERT'
|
77
|
+
end
|
78
|
+
|
79
|
+
on 'test.*', expired: '2014/10/06' do
|
80
|
+
grant 'UPDATE'
|
81
|
+
grant 'DELETE'
|
82
|
+
end
|
83
|
+
|
84
|
+
on 'mysql.user' do
|
85
|
+
grant 'SELECT (user)'
|
86
|
+
end
|
87
|
+
end
|
88
|
+
RUBY
|
89
|
+
|
90
|
+
Timecop.freeze(Time.parse('2014/10/05 23:59:59')) do
|
91
|
+
result = apply(subject) { dsl }
|
92
|
+
expect(result).to be_falsey
|
93
|
+
end
|
94
|
+
|
95
|
+
expect(show_grants).to match_array [
|
96
|
+
"GRANT SELECT (user) ON `mysql`.`user` TO 'scott'@'localhost'",
|
97
|
+
"GRANT SELECT, INSERT ON *.* TO 'scott'@'localhost' IDENTIFIED BY PASSWORD '*F2F68D0BB27A773C1D944270E5FAFED515A3FA40' REQUIRE SSL",
|
98
|
+
"GRANT UPDATE, DELETE ON `test`.* TO 'scott'@'localhost'",
|
99
|
+
]
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
context 'when enable_expired is false' do
|
104
|
+
subject { client(enable_expired: false) }
|
105
|
+
|
106
|
+
it do
|
107
|
+
dsl = <<-RUBY
|
108
|
+
user 'scott', 'localhost', required: 'SSL' do
|
109
|
+
on '*.*' do
|
110
|
+
grant 'SELECT'
|
111
|
+
grant 'INSERT'
|
112
|
+
end
|
113
|
+
|
114
|
+
on 'test.*', expired: '2014/10/06' do
|
115
|
+
grant 'UPDATE'
|
116
|
+
grant 'DELETE'
|
117
|
+
end
|
118
|
+
|
119
|
+
on 'mysql.user' do
|
120
|
+
grant 'SELECT (user)'
|
121
|
+
end
|
122
|
+
end
|
123
|
+
RUBY
|
124
|
+
|
125
|
+
|
126
|
+
Timecop.freeze(Time.parse('2014/10/10')) do
|
127
|
+
result = apply(subject) { dsl }
|
128
|
+
expect(result).to be_falsey
|
129
|
+
end
|
130
|
+
|
131
|
+
expect(show_grants).to match_array [
|
132
|
+
"GRANT SELECT (user) ON `mysql`.`user` TO 'scott'@'localhost'",
|
133
|
+
"GRANT SELECT, INSERT ON *.* TO 'scott'@'localhost' IDENTIFIED BY PASSWORD '*F2F68D0BB27A773C1D944270E5FAFED515A3FA40' REQUIRE SSL",
|
134
|
+
"GRANT UPDATE, DELETE ON `test`.* TO 'scott'@'localhost'",
|
135
|
+
]
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gratan
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Genki Sugawara
|
@@ -146,6 +146,7 @@ files:
|
|
146
146
|
- spec/change/change_grants_2_spec.rb
|
147
147
|
- spec/change/change_grants_3_spec.rb
|
148
148
|
- spec/change/change_grants_4_spec.rb
|
149
|
+
- spec/change/change_grants_expired_spec.rb
|
149
150
|
- spec/change/change_grants_multi_hosts_spec.rb
|
150
151
|
- spec/change/change_grants_regexp_spec.rb
|
151
152
|
- spec/change/change_grants_spec.rb
|
@@ -189,6 +190,7 @@ test_files:
|
|
189
190
|
- spec/change/change_grants_2_spec.rb
|
190
191
|
- spec/change/change_grants_3_spec.rb
|
191
192
|
- spec/change/change_grants_4_spec.rb
|
193
|
+
- spec/change/change_grants_expired_spec.rb
|
192
194
|
- spec/change/change_grants_multi_hosts_spec.rb
|
193
195
|
- spec/change/change_grants_regexp_spec.rb
|
194
196
|
- spec/change/change_grants_spec.rb
|