mikras_utils 0.15.0 → 0.16.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4b53fcf02009d498760ed46a4e2e01fb5418ed6a8ee19b37a66504d5c524b209
4
- data.tar.gz: b4361d6d864f9582fe93462b9d8b2fac2d846e96ac04d5a18777dce4d16bddfb
3
+ metadata.gz: 4fe12ca731ca5946497ff1c82d4d31f00b383dc467588581a8af123347e961d9
4
+ data.tar.gz: f703327b44103dcd3d0cb0e5b87f5ac87322d48a9756a23ed1ca14fd19cac580
5
5
  SHA512:
6
- metadata.gz: 414f6394b7c34992986a859875d69c14931ac913af2739a80759157effb38e20a55ee2addc815d024210908c15cddbf41669ab87ba474c527eada2aa92695458
7
- data.tar.gz: 8ef782e64378a14de544d0099534d952963a223573bfb833e710acf673b6d3058d4928cd6c2f3c00805371bf163c85a3fbe3c41a5ce83e589170dc9e14f2e8d1
6
+ metadata.gz: 5bd1d52942bf6493256aecf50776fe0c77d86e47566fd049d858d8439d027ec2f99dfffeb0973cb14f70747c6862cdb52f73b2c610037a63b7d413478f445c30
7
+ data.tar.gz: df3cac1ea3ce8b620db3417304798e53e5ac5efe6773d8cf88f3d9e765669293aff97277f4f77ef6f314e41d4f113a22a53c322422d67bef7693302ac64fd394
@@ -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
- DEFAULT_MUTATION = "app_portal.mutate"
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
- attr_accessor :roles # Roles that this rule applies to
195
- attr_accessor :filter # Goes into the postgres policy, may be nil
196
- attr_accessor :assert # Goes into the postgres trigger, may be nil
197
- attr_accessor :mutation # Mutation function to use, may be nil. Default app_portal.mutate() except attach/detach
198
- attr_accessor :fields # Only used for insert and update, nil otherwise
199
- attr_accessor :tables # Only used for attach and detach, nil otherwise
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
- @mutation = (action.name == "select" ? nil : DEFAULT_MUTATION)
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
- puts "mutation: #{mutation || 'nil'}" if !mutation.nil? && mutation != DEFAULT_MUTATION
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,10 @@ module MkAcl
246
271
  end
247
272
 
248
273
  private
274
+ def default_mutation
275
+ %w(insert update delete).include?(action.name) ? "#{action.name}_#{table.record_name}" : nil
276
+ end
277
+
249
278
  def attach_stamp(stamp)
250
279
  @stamps << stamp
251
280
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MikrasUtils
4
- VERSION = "0.15.0"
4
+ VERSION = "0.16.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mikras_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.15.0
4
+ version: 0.16.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Claus Rasmussen