mikras_utils 0.15.0 → 0.16.1
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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ccdc04a2de611e4b1fe6b0e611fe9cc3c3751081045f0073044ff53e8dc53371
|
4
|
+
data.tar.gz: bbc7c517c0a35beba4978ae97d3a6b0f7c1958c41143b28b98ce579997fdc983
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5e9e973fde3d6aeb5ab774a26068d1505383e3d36e37c55680ca7ad2ae340228dc55cd2f186e330385b0dfa220b9d04b94e6cbd7c5089dc49221bdfabbb60a92
|
7
|
+
data.tar.gz: 2c860738ae8dba73d4844a18bee439bd541f0329fbbdccf3235e8a4d90223bb309489de539443b2613241afeba2ef47be03ff817e33d79b810717a33bb5ff179
|
@@ -86,6 +86,19 @@ module MkAcl
|
|
86
86
|
# Resolve domains
|
87
87
|
spec.tables.select(&:acl).each { |t| resolve_domain(t) }
|
88
88
|
|
89
|
+
# Function defaults
|
90
|
+
rules = spec.tables.map { |table| table.actions.values.map { |action| action.rules } }.flatten
|
91
|
+
rules.each { |rule|
|
92
|
+
if rule.mutation && !%w(attach detach).include?(rule.action)
|
93
|
+
if !rule.function
|
94
|
+
rule.function = DEFAULT_FUNCTION
|
95
|
+
end
|
96
|
+
else # rule.mutation.nil?
|
97
|
+
# do nothing
|
98
|
+
end
|
99
|
+
}
|
100
|
+
|
101
|
+
|
89
102
|
spec
|
90
103
|
end
|
91
104
|
|
@@ -63,11 +63,11 @@ module MkAcl
|
|
63
63
|
puts
|
64
64
|
|
65
65
|
action.rules.each { |rule|
|
66
|
-
fields = %w(roles filter assert mutation fields tables ordinal)
|
66
|
+
fields = %w(roles filter assert mutation function fields tables ordinal)
|
67
67
|
values = fields.map { |field| conn.quote_value(rule.send(field.to_sym), elem_type: :text) }
|
68
68
|
puts %(
|
69
69
|
insert into acl_portal.acl_rules (
|
70
|
-
acl_action_id, roles, filter, assert, function_name, fields, tables, ordinal)
|
70
|
+
acl_action_id, roles, filter, assert, mutation_name, function_name, fields, tables, ordinal)
|
71
71
|
values (:action_id, #{values.join(', ')})
|
72
72
|
returning id as "rule_id"
|
73
73
|
\\gset
|
@@ -88,6 +88,7 @@ module MkAcl
|
|
88
88
|
when :filter; rule.filter = norm_value(value)
|
89
89
|
when :assert; rule.assert = norm_value(value)
|
90
90
|
when :mutation; rule.mutation = value.nil? ? nil : norm_value(value)
|
91
|
+
when :function; rule.function = value.nil? ? nil : norm_value(value)
|
91
92
|
when :fields; rule.fields = value.nil? ? nil : norm_array(value)
|
92
93
|
when :tables; rule.tables = norm_array(value)
|
93
94
|
else
|
@@ -1,6 +1,6 @@
|
|
1
1
|
|
2
2
|
module MkAcl
|
3
|
-
|
3
|
+
DEFAULT_FUNCTION = "app_portal.mutate"
|
4
4
|
ACTIONS = %w(insert select update delete attach detach)
|
5
5
|
|
6
6
|
class Spec
|
@@ -191,12 +191,29 @@ module MkAcl
|
|
191
191
|
|
192
192
|
attr_reader :action
|
193
193
|
forward_to :action, :table, :name
|
194
|
-
|
195
|
-
|
196
|
-
attr_accessor :
|
197
|
-
|
198
|
-
|
199
|
-
attr_accessor :
|
194
|
+
|
195
|
+
# Roles that this rule applies to
|
196
|
+
attr_accessor :roles
|
197
|
+
|
198
|
+
# Goes into the postgres policy, may be nil
|
199
|
+
attr_accessor :filter
|
200
|
+
|
201
|
+
# Goes into the postgres trigger, may be nil
|
202
|
+
attr_accessor :assert
|
203
|
+
|
204
|
+
# Mutation function, may be nil. Default create/update/delete_RECORD except
|
205
|
+
# select/attach/detach
|
206
|
+
attr_accessor :mutation
|
207
|
+
|
208
|
+
# Implementation function, may be nil. Default 'app_portal.mutate()' except attach/detach
|
209
|
+
attr_accessor :function
|
210
|
+
|
211
|
+
# Only used for insert and update, nil otherwise
|
212
|
+
attr_accessor :fields
|
213
|
+
|
214
|
+
# Only used for attach and detach, nil otherwise
|
215
|
+
attr_accessor :tables
|
216
|
+
|
200
217
|
attr_accessor :stamps
|
201
218
|
attr_accessor :stamp_exprs
|
202
219
|
attr_reader :ordinal
|
@@ -213,7 +230,9 @@ module MkAcl
|
|
213
230
|
@roles = []
|
214
231
|
@filter = nil
|
215
232
|
@assert = nil
|
216
|
-
|
233
|
+
# @mutation = (action.name == "select" ? nil : "#{action}_#{table.record_name}")
|
234
|
+
@mutation = default_mutation
|
235
|
+
@function = nil #(action.name == "select" ? nil : DEFAULT_MUTATION)
|
217
236
|
@fields = %w(insert update).include?(action.name) ? [] : nil
|
218
237
|
@tables = %w(attach detach).include?(action.name) ? [] : nil
|
219
238
|
@stamps = []
|
@@ -224,11 +243,17 @@ module MkAcl
|
|
224
243
|
|
225
244
|
def dump
|
226
245
|
puts "roles: #{roles.join(' ')}"
|
246
|
+
puts "tables: #{tables.join(' ')}" if tables && !tables.empty?
|
227
247
|
puts "filter: #{filter}" if filter
|
228
248
|
puts "assert: #{assert}" if assert
|
229
|
-
|
249
|
+
if %w(insert update delete).include?(action.name)
|
250
|
+
puts "mutation: #{mutation || 'nil'}" \
|
251
|
+
if name != 'select' && (mutation.nil? || mutation != default_mutation)
|
252
|
+
puts "function: #{function || 'nil'}" if name != 'select' && function != DEFAULT_FUNCTION
|
253
|
+
else
|
254
|
+
puts "function: #{function}" if function
|
255
|
+
end
|
230
256
|
puts "fields: #{fields.join(' ')}" if fields && !fields.empty?
|
231
|
-
puts "tables: #{tables.join(' ')}" if tables && !tables.empty?
|
232
257
|
|
233
258
|
if stamp_exprs.size == 1
|
234
259
|
stamp_exprs.first.dump
|
@@ -246,6 +271,15 @@ module MkAcl
|
|
246
271
|
end
|
247
272
|
|
248
273
|
private
|
274
|
+
def default_mutation
|
275
|
+
case action.name
|
276
|
+
when "insert"; "create_#{table.record_name}"
|
277
|
+
when "update", "delete"; "#{action.name}_#{table.record_name}"
|
278
|
+
else
|
279
|
+
nil
|
280
|
+
end
|
281
|
+
end
|
282
|
+
|
249
283
|
def attach_stamp(stamp)
|
250
284
|
@stamps << stamp
|
251
285
|
end
|
data/lib/mikras_utils/version.rb
CHANGED