gratan 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/lib/gratan/dsl/context.rb +19 -16
- data/lib/gratan/version.rb +1 -1
- data/spec/change/change_grants_multi_hosts_spec.rb +145 -0
- data/spec/create/create_user_multi_hosts_spec.rb +36 -0
- metadata +5 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 594f050aa91a09ebe859fee36bee875f22461540
|
4
|
+
data.tar.gz: 9fd38fa478da13932a4d5d07621e870d8a51f559
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0e924bbca853d1ba2d5c49523aa508f2cd02ba476e6484734eb1fee5f05b5b91db6442c91046b133f3d9aa80ac25a7045c2a118e46a869e639e877c87f41bbae
|
7
|
+
data.tar.gz: 0a490b3b1941baa49d2592e6d0acfb54f4a95dbb952f2922c922b123d0a1559855784ef678460533081ab3bf349deec757c6092249d7a72a6d2618f0e8cd8dcd
|
data/README.md
CHANGED
@@ -80,7 +80,7 @@ user "scott", "%" do
|
|
80
80
|
end
|
81
81
|
end
|
82
82
|
|
83
|
-
user "scott", "localhost", expired: '2014/10/10' do
|
83
|
+
user "scott", ["localhost", "192.168.%"], expired: '2014/10/10' do
|
84
84
|
on "*.*", with: 'GRANT OPTION' do
|
85
85
|
grant "ALL PRIVILEGES"
|
86
86
|
end
|
@@ -89,4 +89,4 @@ end
|
|
89
89
|
|
90
90
|
## What does "Gratan" mean?
|
91
91
|
|
92
|
-
[![](http://i.gyazo.com/c37d934ba0a61f760603ce4c56401e60.png)](https://www.google.
|
92
|
+
[![](http://i.gyazo.com/c37d934ba0a61f760603ce4c56401e60.png)](https://www.google.com/search?q=gratin&tbm=isch)
|
data/lib/gratan/dsl/context.rb
CHANGED
@@ -31,27 +31,30 @@ class Gratan::DSL::Context
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
def user(name,
|
34
|
+
def user(name, host_or_array, options = {}, &block)
|
35
35
|
name = name.to_s
|
36
|
-
|
37
|
-
options ||= {}
|
36
|
+
hosts = [host_or_array].flatten.map {|i| i.to_s }
|
38
37
|
|
39
|
-
|
40
|
-
|
41
|
-
|
38
|
+
hosts.each do |host|
|
39
|
+
options ||= {}
|
40
|
+
|
41
|
+
__validate("User `#{name}@#{host}` is already defined") do
|
42
|
+
not @result.has_key?([name, host])
|
43
|
+
end
|
42
44
|
|
43
|
-
|
44
|
-
|
45
|
+
if @options[:enable_expired] and (expired = options.delete(:expired))
|
46
|
+
expired = Time.parse(expired)
|
45
47
|
|
46
|
-
|
47
|
-
|
48
|
-
|
48
|
+
if Time.new >= expired
|
49
|
+
log(:warn, "User `#{name}@#{host}` has expired", :color => :yellow)
|
50
|
+
return
|
51
|
+
end
|
49
52
|
end
|
50
|
-
end
|
51
53
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
54
|
+
@result[[name, host]] = {
|
55
|
+
:objects => Gratan::DSL::Context::User.new(name, host, &block).result,
|
56
|
+
:options => options,
|
57
|
+
}
|
58
|
+
end
|
56
59
|
end
|
57
60
|
end
|
data/lib/gratan/version.rb
CHANGED
@@ -0,0 +1,145 @@
|
|
1
|
+
describe 'Gratan::Client#apply' do
|
2
|
+
context 'when change privs (multi hosts)' do
|
3
|
+
before(:each) do
|
4
|
+
apply {
|
5
|
+
<<-RUBY
|
6
|
+
user 'scott', 'localhost', identified: 'tiger', required: 'SSL' do
|
7
|
+
on '*.*' do
|
8
|
+
grant 'SELECT'
|
9
|
+
grant 'INSERT'
|
10
|
+
end
|
11
|
+
|
12
|
+
on 'test.*' do
|
13
|
+
grant 'UPDATE'
|
14
|
+
grant 'DELETE'
|
15
|
+
end
|
16
|
+
|
17
|
+
on 'mysql.user' do
|
18
|
+
grant 'SELECT (user)'
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
user 'scott', '%', identified: 'tiger', required: 'SSL' do
|
23
|
+
on '*.*' do
|
24
|
+
grant 'SELECT'
|
25
|
+
grant 'INSERT'
|
26
|
+
end
|
27
|
+
|
28
|
+
on 'test.*' do
|
29
|
+
grant 'UPDATE'
|
30
|
+
grant 'DELETE'
|
31
|
+
end
|
32
|
+
|
33
|
+
on 'mysql.user' do
|
34
|
+
grant 'SELECT (user)'
|
35
|
+
end
|
36
|
+
end
|
37
|
+
RUBY
|
38
|
+
}
|
39
|
+
end
|
40
|
+
|
41
|
+
subject { client }
|
42
|
+
|
43
|
+
it do
|
44
|
+
apply(subject) {
|
45
|
+
<<-RUBY
|
46
|
+
user 'scott', ['localhost', '%', '127.0.0.1'], required: 'SSL' do
|
47
|
+
on '*.*' do
|
48
|
+
grant 'SELECT'
|
49
|
+
grant 'DELETE'
|
50
|
+
end
|
51
|
+
|
52
|
+
on 'test.*' do
|
53
|
+
grant 'UPDATE'
|
54
|
+
grant 'INSERT'
|
55
|
+
end
|
56
|
+
end
|
57
|
+
RUBY
|
58
|
+
}
|
59
|
+
|
60
|
+
expect(show_grants).to match_array [
|
61
|
+
"GRANT INSERT, UPDATE ON `test`.* TO 'scott'@'%'",
|
62
|
+
"GRANT INSERT, UPDATE ON `test`.* TO 'scott'@'127.0.0.1'",
|
63
|
+
"GRANT INSERT, UPDATE ON `test`.* TO 'scott'@'localhost'",
|
64
|
+
"GRANT SELECT, DELETE ON *.* TO 'scott'@'%' IDENTIFIED BY PASSWORD '*F2F68D0BB27A773C1D944270E5FAFED515A3FA40' REQUIRE SSL",
|
65
|
+
"GRANT SELECT, DELETE ON *.* TO 'scott'@'127.0.0.1' REQUIRE SSL",
|
66
|
+
"GRANT SELECT, DELETE ON *.* TO 'scott'@'localhost' IDENTIFIED BY PASSWORD '*F2F68D0BB27A773C1D944270E5FAFED515A3FA40' REQUIRE SSL",
|
67
|
+
]
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
context 'when no change privs (multi hosts)' do
|
72
|
+
before(:each) do
|
73
|
+
apply {
|
74
|
+
<<-RUBY
|
75
|
+
user 'scott', 'localhost', identified: 'tiger', required: 'SSL' do
|
76
|
+
on '*.*' do
|
77
|
+
grant 'SELECT'
|
78
|
+
grant 'INSERT'
|
79
|
+
end
|
80
|
+
|
81
|
+
on 'test.*' do
|
82
|
+
grant 'UPDATE'
|
83
|
+
grant 'DELETE'
|
84
|
+
end
|
85
|
+
|
86
|
+
on 'mysql.user' do
|
87
|
+
grant 'SELECT (user)'
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
user 'scott', '%', identified: 'tiger', required: 'SSL' do
|
92
|
+
on '*.*' do
|
93
|
+
grant 'SELECT'
|
94
|
+
grant 'INSERT'
|
95
|
+
end
|
96
|
+
|
97
|
+
on 'test.*' do
|
98
|
+
grant 'UPDATE'
|
99
|
+
grant 'DELETE'
|
100
|
+
end
|
101
|
+
|
102
|
+
on 'mysql.user' do
|
103
|
+
grant 'SELECT (user)'
|
104
|
+
end
|
105
|
+
end
|
106
|
+
RUBY
|
107
|
+
}
|
108
|
+
end
|
109
|
+
|
110
|
+
subject { client }
|
111
|
+
|
112
|
+
it do
|
113
|
+
result = apply(subject) {
|
114
|
+
<<-RUBY
|
115
|
+
user 'scott', ['localhost', '%'], required: 'SSL' do
|
116
|
+
on '*.*' do
|
117
|
+
grant 'SELECT'
|
118
|
+
grant 'INSERT'
|
119
|
+
end
|
120
|
+
|
121
|
+
on 'test.*' do
|
122
|
+
grant 'UPDATE'
|
123
|
+
grant 'DELETE'
|
124
|
+
end
|
125
|
+
|
126
|
+
on 'mysql.user' do
|
127
|
+
grant 'SELECT (user)'
|
128
|
+
end
|
129
|
+
end
|
130
|
+
RUBY
|
131
|
+
}
|
132
|
+
|
133
|
+
expect(result).to be_falsey
|
134
|
+
|
135
|
+
expect(show_grants).to match_array [
|
136
|
+
"GRANT SELECT (user) ON `mysql`.`user` TO 'scott'@'%'",
|
137
|
+
"GRANT SELECT (user) ON `mysql`.`user` TO 'scott'@'localhost'",
|
138
|
+
"GRANT SELECT, INSERT ON *.* TO 'scott'@'%' IDENTIFIED BY PASSWORD '*F2F68D0BB27A773C1D944270E5FAFED515A3FA40' REQUIRE SSL",
|
139
|
+
"GRANT SELECT, INSERT ON *.* TO 'scott'@'localhost' IDENTIFIED BY PASSWORD '*F2F68D0BB27A773C1D944270E5FAFED515A3FA40' REQUIRE SSL",
|
140
|
+
"GRANT UPDATE, DELETE ON `test`.* TO 'scott'@'%'",
|
141
|
+
"GRANT UPDATE, DELETE ON `test`.* TO 'scott'@'localhost'",
|
142
|
+
]
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
describe 'Gratan::Client#apply' do
|
2
|
+
context 'when create user (multi hosts)' do
|
3
|
+
subject { client }
|
4
|
+
|
5
|
+
it do
|
6
|
+
apply(subject) {
|
7
|
+
<<-RUBY
|
8
|
+
user 'scott', ['localhost', '127.0.0.1', '192.168.%'], identified: 'tiger' do
|
9
|
+
on '*.*' do
|
10
|
+
grant 'SELECT'
|
11
|
+
grant 'INSERT'
|
12
|
+
grant 'UPDATE'
|
13
|
+
grant 'DELETE'
|
14
|
+
end
|
15
|
+
|
16
|
+
on 'test.*' do
|
17
|
+
grant 'SELECT'
|
18
|
+
grant 'INSERT'
|
19
|
+
grant 'UPDATE'
|
20
|
+
grant 'DELETE'
|
21
|
+
end
|
22
|
+
end
|
23
|
+
RUBY
|
24
|
+
}
|
25
|
+
|
26
|
+
expect(show_grants).to match_array [
|
27
|
+
"GRANT SELECT, INSERT, UPDATE, DELETE ON *.* TO 'scott'@'localhost' IDENTIFIED BY PASSWORD '*F2F68D0BB27A773C1D944270E5FAFED515A3FA40'",
|
28
|
+
"GRANT SELECT, INSERT, UPDATE, DELETE ON `test`.* TO 'scott'@'localhost'",
|
29
|
+
"GRANT SELECT, INSERT, UPDATE, DELETE ON *.* TO 'scott'@'127.0.0.1' IDENTIFIED BY PASSWORD '*F2F68D0BB27A773C1D944270E5FAFED515A3FA40'",
|
30
|
+
"GRANT SELECT, INSERT, UPDATE, DELETE ON `test`.* TO 'scott'@'127.0.0.1'",
|
31
|
+
"GRANT SELECT, INSERT, UPDATE, DELETE ON *.* TO 'scott'@'192.168.%' IDENTIFIED BY PASSWORD '*F2F68D0BB27A773C1D944270E5FAFED515A3FA40'",
|
32
|
+
"GRANT SELECT, INSERT, UPDATE, DELETE ON `test`.* TO 'scott'@'192.168.%'",
|
33
|
+
]
|
34
|
+
end
|
35
|
+
end
|
36
|
+
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.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Genki Sugawara
|
@@ -146,10 +146,12 @@ 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_multi_hosts_spec.rb
|
149
150
|
- spec/change/change_grants_regexp_spec.rb
|
150
151
|
- spec/change/change_grants_spec.rb
|
151
152
|
- spec/create/create_user_2_spec.rb
|
152
153
|
- spec/create/create_user_3_spec.rb
|
154
|
+
- spec/create/create_user_multi_hosts_spec.rb
|
153
155
|
- spec/create/create_user_regexp_spec.rb
|
154
156
|
- spec/create/create_user_spec.rb
|
155
157
|
- spec/drop/drop_user_2_spec.rb
|
@@ -187,10 +189,12 @@ test_files:
|
|
187
189
|
- spec/change/change_grants_2_spec.rb
|
188
190
|
- spec/change/change_grants_3_spec.rb
|
189
191
|
- spec/change/change_grants_4_spec.rb
|
192
|
+
- spec/change/change_grants_multi_hosts_spec.rb
|
190
193
|
- spec/change/change_grants_regexp_spec.rb
|
191
194
|
- spec/change/change_grants_spec.rb
|
192
195
|
- spec/create/create_user_2_spec.rb
|
193
196
|
- spec/create/create_user_3_spec.rb
|
197
|
+
- spec/create/create_user_multi_hosts_spec.rb
|
194
198
|
- spec/create/create_user_regexp_spec.rb
|
195
199
|
- spec/create/create_user_spec.rb
|
196
200
|
- spec/drop/drop_user_2_spec.rb
|