posgra 0.1.5 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/posgra/driver.rb +33 -21
- data/lib/posgra/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 45874f5aa54ff585d53004c99222773b4964f885
|
4
|
+
data.tar.gz: 654038906c2981a3f03b6a250221381a1ba6949d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0356ed811f29833fbf7dc36daf5e0496f78473b557ed8c519a4495396291d77d9f7c8f45775cd72dfa1a2ea63b6ec702fdb725575e79c3f568badc2fdb1d6672
|
7
|
+
data.tar.gz: 1ed24ddf548cf6a852089ee8571ea03890154710453f114e257ba8a7fff4cc3509d57cf4615381398754a09ec0fe5f42b06a3645c5612036127a675b3d46d866
|
data/lib/posgra/driver.rb
CHANGED
@@ -42,7 +42,7 @@ class Posgra::Driver
|
|
42
42
|
log(:info, sql, :color => :cyan)
|
43
43
|
|
44
44
|
unless @options[:dry_run]
|
45
|
-
|
45
|
+
exec(sql)
|
46
46
|
updated = true
|
47
47
|
end
|
48
48
|
|
@@ -56,7 +56,7 @@ class Posgra::Driver
|
|
56
56
|
log(:info, sql, :color => :red)
|
57
57
|
|
58
58
|
unless @options[:dry_run]
|
59
|
-
|
59
|
+
exec(sql)
|
60
60
|
updated = true
|
61
61
|
end
|
62
62
|
|
@@ -70,7 +70,7 @@ class Posgra::Driver
|
|
70
70
|
log(:info, sql, :color => :cyan)
|
71
71
|
|
72
72
|
unless @options[:dry_run]
|
73
|
-
|
73
|
+
exec(sql)
|
74
74
|
updated = true
|
75
75
|
end
|
76
76
|
|
@@ -84,7 +84,7 @@ class Posgra::Driver
|
|
84
84
|
log(:info, sql, :color => :green)
|
85
85
|
|
86
86
|
unless @options[:dry_run]
|
87
|
-
|
87
|
+
exec(sql)
|
88
88
|
updated = true
|
89
89
|
end
|
90
90
|
|
@@ -98,7 +98,7 @@ class Posgra::Driver
|
|
98
98
|
log(:info, sql, :color => :cyan)
|
99
99
|
|
100
100
|
unless @options[:dry_run]
|
101
|
-
|
101
|
+
exec(sql)
|
102
102
|
updated = true
|
103
103
|
end
|
104
104
|
|
@@ -112,7 +112,7 @@ class Posgra::Driver
|
|
112
112
|
log(:info, sql, :color => :red)
|
113
113
|
|
114
114
|
unless @options[:dry_run]
|
115
|
-
|
115
|
+
exec(sql)
|
116
116
|
updated = true
|
117
117
|
end
|
118
118
|
|
@@ -122,12 +122,8 @@ class Posgra::Driver
|
|
122
122
|
def revoke_all_on_schema(role, schema)
|
123
123
|
updated = false
|
124
124
|
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
unless @options[:dry_run]
|
129
|
-
@client.query(sql)
|
130
|
-
updated = true
|
125
|
+
describe_objects(schema).each do |object|
|
126
|
+
updated = revoke_all_on_object(role, schema, object) || updated
|
131
127
|
end
|
132
128
|
|
133
129
|
updated
|
@@ -140,7 +136,7 @@ class Posgra::Driver
|
|
140
136
|
log(:info, sql, :color => :green)
|
141
137
|
|
142
138
|
unless @options[:dry_run]
|
143
|
-
|
139
|
+
exec(sql)
|
144
140
|
updated = true
|
145
141
|
end
|
146
142
|
|
@@ -159,7 +155,7 @@ class Posgra::Driver
|
|
159
155
|
log(:info, sql, :color => :green)
|
160
156
|
|
161
157
|
unless @options[:dry_run]
|
162
|
-
|
158
|
+
exec(sql)
|
163
159
|
updated = true
|
164
160
|
end
|
165
161
|
|
@@ -185,7 +181,7 @@ class Posgra::Driver
|
|
185
181
|
log(:info, sql, :color => :green)
|
186
182
|
|
187
183
|
unless @options[:dry_run]
|
188
|
-
|
184
|
+
exec(sql)
|
189
185
|
updated = true
|
190
186
|
end
|
191
187
|
|
@@ -199,7 +195,7 @@ class Posgra::Driver
|
|
199
195
|
log(:info, sql, :color => :green)
|
200
196
|
|
201
197
|
unless @options[:dry_run]
|
202
|
-
|
198
|
+
exec(sql)
|
203
199
|
updated = true
|
204
200
|
end
|
205
201
|
|
@@ -213,7 +209,7 @@ class Posgra::Driver
|
|
213
209
|
log(:info, sql, :color => :green)
|
214
210
|
|
215
211
|
unless @options[:dry_run]
|
216
|
-
|
212
|
+
exec(sql)
|
217
213
|
updated = true
|
218
214
|
end
|
219
215
|
|
@@ -221,7 +217,7 @@ class Posgra::Driver
|
|
221
217
|
end
|
222
218
|
|
223
219
|
def describe_objects(schema)
|
224
|
-
rs =
|
220
|
+
rs = exec <<-SQL
|
225
221
|
SELECT
|
226
222
|
pg_class.relname,
|
227
223
|
pg_namespace.nspname
|
@@ -245,7 +241,7 @@ class Posgra::Driver
|
|
245
241
|
end
|
246
242
|
|
247
243
|
def describe_users
|
248
|
-
rs =
|
244
|
+
rs = exec('SELECT * FROM pg_user')
|
249
245
|
|
250
246
|
options_by_user = {}
|
251
247
|
|
@@ -259,7 +255,7 @@ class Posgra::Driver
|
|
259
255
|
end
|
260
256
|
|
261
257
|
def describe_groups
|
262
|
-
rs =
|
258
|
+
rs = exec <<-SQL
|
263
259
|
SELECT
|
264
260
|
pg_group.groname,
|
265
261
|
pg_user.usename
|
@@ -282,7 +278,7 @@ class Posgra::Driver
|
|
282
278
|
end
|
283
279
|
|
284
280
|
def describe_grants
|
285
|
-
rs =
|
281
|
+
rs = exec <<-SQL
|
286
282
|
SELECT
|
287
283
|
pg_class.relname,
|
288
284
|
pg_namespace.nspname,
|
@@ -329,8 +325,11 @@ class Posgra::Driver
|
|
329
325
|
aclitems = aclitems[1..-2].split(',')
|
330
326
|
|
331
327
|
aclitems.map do |aclitem|
|
328
|
+
aclitem = unquote_aclitem(aclitem)
|
332
329
|
grantee, privileges_grantor = aclitem.split('=', 2)
|
333
330
|
privileges, grantor = privileges_grantor.split('/', 2)
|
331
|
+
grantee = unescape_aclname(grantee)
|
332
|
+
grantor = unescape_aclname(grantor)
|
334
333
|
|
335
334
|
{
|
336
335
|
'grantee' => grantee,
|
@@ -358,4 +357,17 @@ class Posgra::Driver
|
|
358
357
|
|
359
358
|
options_by_privilege
|
360
359
|
end
|
360
|
+
|
361
|
+
def exec(sql)
|
362
|
+
log(:debug, sql)
|
363
|
+
@client.exec(sql)
|
364
|
+
end
|
365
|
+
|
366
|
+
def unquote_aclitem(str)
|
367
|
+
str.sub(/\A"/, '').sub(/"\z/, '').gsub('\\', '')
|
368
|
+
end
|
369
|
+
|
370
|
+
def unescape_aclname(str)
|
371
|
+
str.sub(/\A"/, '').sub(/"\z/, '').gsub('""', '"')
|
372
|
+
end
|
361
373
|
end
|
data/lib/posgra/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: posgra
|
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
|
- winebarrel
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-02-
|
11
|
+
date: 2016-02-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pg
|