mikras_utils 0.14.1 → 0.15.0
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/mikras_utils/mkacl/generators/seeds.rb +35 -2
- data/lib/mikras_utils/mkacl/parser.rb +8 -27
- data/lib/mikras_utils/mkacl/spec.rb +46 -15
- data/lib/mikras_utils/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4b53fcf02009d498760ed46a4e2e01fb5418ed6a8ee19b37a66504d5c524b209
|
4
|
+
data.tar.gz: b4361d6d864f9582fe93462b9d8b2fac2d846e96ac04d5a18777dce4d16bddfb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 414f6394b7c34992986a859875d69c14931ac913af2739a80759157effb38e20a55ee2addc815d024210908c15cddbf41669ab87ba474c527eada2aa92695458
|
7
|
+
data.tar.gz: 8ef782e64378a14de544d0099534d952963a223573bfb833e710acf673b6d3058d4928cd6c2f3c00805371bf163c85a3fbe3c41a5ce83e589170dc9e14f2e8d1
|
@@ -54,6 +54,7 @@ module MkAcl
|
|
54
54
|
|
55
55
|
table.actions.values.each { |action|
|
56
56
|
puts %(
|
57
|
+
-- #{action.name.upcase}
|
57
58
|
insert into acl_portal.acl_actions (acl_table_id, kind)
|
58
59
|
values (:table_id, '#{action.name.upcase}')
|
59
60
|
returning id as "action_id"
|
@@ -75,11 +76,12 @@ module MkAcl
|
|
75
76
|
|
76
77
|
rule.stamps.each { |stamp|
|
77
78
|
puts %(
|
78
|
-
insert into acl_portal.acl_stamps (acl_rule_id, watch, stamp)
|
79
|
+
insert into acl_portal.acl_stamps (acl_rule_id, watch, stamp, value)
|
79
80
|
values (
|
80
81
|
:rule_id,
|
81
82
|
#{conn.quote_value(stamp.watch)},
|
82
|
-
#{conn.quote_value(stamp.stamp)}
|
83
|
+
#{conn.quote_value(stamp.stamp)},
|
84
|
+
#{conn.quote_value(stamp.value)}
|
83
85
|
);
|
84
86
|
).align
|
85
87
|
}
|
@@ -87,7 +89,11 @@ module MkAcl
|
|
87
89
|
}
|
88
90
|
end
|
89
91
|
|
92
|
+
# Patch-up acl_tables
|
90
93
|
puts %(
|
94
|
+
--
|
95
|
+
-- ASSIGN TABLE PARENT ID
|
96
|
+
--
|
91
97
|
update acl_portal.acl_tables sub
|
92
98
|
set parent_id = (
|
93
99
|
select id
|
@@ -97,6 +103,33 @@ module MkAcl
|
|
97
103
|
);
|
98
104
|
).align
|
99
105
|
puts
|
106
|
+
|
107
|
+
# Patch-up acl_stamps
|
108
|
+
puts %(
|
109
|
+
--
|
110
|
+
-- ASSIGN STAMP TYPE AND VALUE
|
111
|
+
--
|
112
|
+
update acl_portal.acl_stamps s
|
113
|
+
set type = c.column_type,
|
114
|
+
value = coalesce(
|
115
|
+
s.value,
|
116
|
+
case c.column_type
|
117
|
+
when 'int' then 'public.current_role_id()'
|
118
|
+
when 'time' then 'now()'
|
119
|
+
end
|
120
|
+
)
|
121
|
+
from
|
122
|
+
acl_portal.acl_rules r
|
123
|
+
join acl_portal.acl_actions a on a.id = r.acl_action_id
|
124
|
+
join acl_portal.acl_tables t on t.id = a.acl_table_id
|
125
|
+
join meta.columns c
|
126
|
+
on c.schema_name = t.schema_name
|
127
|
+
and c.table_name = t.table_name
|
128
|
+
where
|
129
|
+
r.id = s.acl_rule_id
|
130
|
+
and c.column_name = s.stamp
|
131
|
+
;
|
132
|
+
).align
|
100
133
|
end
|
101
134
|
end
|
102
135
|
end
|
@@ -103,12 +103,9 @@ module MkAcl
|
|
103
103
|
def parse_stamps(rule, stamps)
|
104
104
|
constrain rule, Rule
|
105
105
|
constrain stamps, String, Hash, Array
|
106
|
-
# constrain stamps, String, Hash[watch: NilClass | String | [String], stamp: String | [String]]
|
107
106
|
|
108
107
|
# Normalize stamps
|
109
|
-
stamps = Array(stamps)
|
110
|
-
|
111
|
-
stamps.map! { |stamp|
|
108
|
+
stamps = Array(stamps).map! { |stamp|
|
112
109
|
case stamp
|
113
110
|
when Hash; stamp
|
114
111
|
when String; { stamp: stamp }
|
@@ -120,32 +117,16 @@ module MkAcl
|
|
120
117
|
# Check fields and create stamp
|
121
118
|
stamps.each { |stamp|
|
122
119
|
# Check fields
|
123
|
-
diff = stamp.keys - [:watch, :stamp]
|
120
|
+
diff = stamp.keys - [:watch, :stamp, :value]
|
124
121
|
diff.empty? or raise "Illegal field '#{diff.first}' in #{rule.name} rule in table #{rule.table.name}"
|
125
|
-
|
122
|
+
(stamp[:watch]&.split || [nil]).map { |watch_field|
|
123
|
+
stamp[:stamp].split.map { |stamp_field|
|
124
|
+
Stamp.new(rule, watch_field, stamp_field, stamp[:value])
|
125
|
+
}
|
126
|
+
}
|
127
|
+
StampExpr.new(rule, stamp[:watch]&.split, stamp[:stamp].split, stamp[:value])
|
126
128
|
}
|
127
129
|
end
|
128
130
|
end
|
129
131
|
end
|
130
132
|
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
@@ -175,13 +175,9 @@ module MkAcl
|
|
175
175
|
end
|
176
176
|
end
|
177
177
|
|
178
|
-
def dump(header =
|
179
|
-
|
180
|
-
|
181
|
-
indent { dump_body }
|
182
|
-
else
|
183
|
-
dump_body
|
184
|
-
end
|
178
|
+
def dump(header = name)
|
179
|
+
puts "#{header || name}:"
|
180
|
+
indent { dump_body }
|
185
181
|
end
|
186
182
|
|
187
183
|
private
|
@@ -202,6 +198,7 @@ module MkAcl
|
|
202
198
|
attr_accessor :fields # Only used for insert and update, nil otherwise
|
203
199
|
attr_accessor :tables # Only used for attach and detach, nil otherwise
|
204
200
|
attr_accessor :stamps
|
201
|
+
attr_accessor :stamp_exprs
|
205
202
|
attr_reader :ordinal
|
206
203
|
|
207
204
|
# admin, internal, etc.
|
@@ -220,6 +217,7 @@ module MkAcl
|
|
220
217
|
@fields = %w(insert update).include?(action.name) ? [] : nil
|
221
218
|
@tables = %w(attach detach).include?(action.name) ? [] : nil
|
222
219
|
@stamps = []
|
220
|
+
@stamp_exprs = []
|
223
221
|
|
224
222
|
action.send :attach_rule, self
|
225
223
|
end
|
@@ -232,47 +230,80 @@ module MkAcl
|
|
232
230
|
puts "fields: #{fields.join(' ')}" if fields && !fields.empty?
|
233
231
|
puts "tables: #{tables.join(' ')}" if tables && !tables.empty?
|
234
232
|
|
235
|
-
if
|
236
|
-
|
237
|
-
elsif
|
233
|
+
if stamp_exprs.size == 1
|
234
|
+
stamp_exprs.first.dump
|
235
|
+
elsif stamp_exprs.size > 1
|
238
236
|
puts "stamps:"
|
239
237
|
indent {
|
240
|
-
for
|
238
|
+
for stamp_expr in stamp_exprs
|
241
239
|
print "- "
|
242
|
-
indent(bol: false) {
|
240
|
+
indent(bol: false) { stamp_expr.dump }
|
243
241
|
end
|
244
242
|
}
|
245
243
|
end
|
246
244
|
|
247
245
|
puts "ordinal: #{ordinal}"
|
248
246
|
end
|
247
|
+
|
249
248
|
private
|
250
249
|
def attach_stamp(stamp)
|
251
250
|
@stamps << stamp
|
252
251
|
end
|
252
|
+
|
253
|
+
def attach_stamp_expr(stamp_expr)
|
254
|
+
@stamp_exprs << stamp_expr
|
255
|
+
end
|
253
256
|
end
|
254
257
|
|
255
258
|
class Stamp
|
256
259
|
attr_reader :rule
|
260
|
+
|
257
261
|
forward_to :rule, :table, :name
|
258
262
|
|
259
263
|
attr_accessor :watch
|
260
264
|
attr_accessor :stamp
|
265
|
+
attr_accessor :value
|
261
266
|
|
262
|
-
def initialize(rule, watch
|
267
|
+
def initialize(rule, watch, stamp, value)
|
263
268
|
constrain rule, Rule
|
269
|
+
constrain watch, String, nil
|
270
|
+
constrain stamp, String
|
264
271
|
@rule = rule
|
265
|
-
@watch, @stamp = watch, stamp
|
272
|
+
@watch, @stamp, @value = watch, stamp, value
|
266
273
|
rule.send :attach_stamp, self
|
267
274
|
end
|
268
275
|
|
276
|
+
def to_s() = watch ? "#{watch}->#{stamp}" : stamp
|
277
|
+
|
278
|
+
def dump
|
279
|
+
puts "watch: #{watch}" if watch
|
280
|
+
puts "stamp: #{stamp}" if stamp
|
281
|
+
puts "value: #{value}" if value
|
282
|
+
end
|
283
|
+
end
|
284
|
+
|
285
|
+
class StampExpr # For debug. Express the structure of stamp syntax
|
286
|
+
attr_reader :rule
|
287
|
+
forward_to :rule, :table, :name
|
288
|
+
|
289
|
+
attr_accessor :watch # [String]
|
290
|
+
attr_accessor :stamp # [String]
|
291
|
+
attr_accessor :value
|
292
|
+
|
293
|
+
def initialize(rule, watch, stamp, value)
|
294
|
+
constrain rule, Rule
|
295
|
+
@rule = rule
|
296
|
+
@watch, @stamp, @value = watch, stamp, value
|
297
|
+
rule.send :attach_stamp_expr, self
|
298
|
+
end
|
299
|
+
|
269
300
|
def to_s() = watch
|
270
301
|
|
271
302
|
def dump
|
272
303
|
puts "watch: #{watch.join(" ")}" if watch
|
273
304
|
puts "stamp: #{stamp.join(" ")}" if stamp
|
305
|
+
puts "value: #{value}" if value
|
274
306
|
end
|
275
307
|
end
|
276
|
-
|
277
308
|
end
|
278
309
|
|
data/lib/mikras_utils/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mikras_utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.15.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Claus Rasmussen
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-03-
|
11
|
+
date: 2025-03-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pg_conn
|