mikras_utils 0.9.0 → 0.10.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 +8 -0
- data/lib/mikras_utils/mkacl/parser.rb +48 -17
- data/lib/mikras_utils/mkacl/spec.rb +53 -3
- data/lib/mikras_utils/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8dd821a71e85300806a80403130c21aa7030b7c81b2b2fb561e6fa973387f484
|
4
|
+
data.tar.gz: 89e10674d60fb851387f1a87466bb34a9e7a489644d8da774686b573d260fe6c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 21108d406598b5ed0d75b6c0b47a2fd131e784545f2abcb2cf3553867ebb95c3b5385496438ad7d499837286b9fe168972a7e787b83e14c34359e045a7841604
|
7
|
+
data.tar.gz: 6216a7c2993315c6022494fd7f238ad6d103311200a5a41277b1462eac0eeda222f5bd3b9d4edb7b4c7c2132b3a2b4fa6b6fc66eda2bc314bba525f19cf8447b
|
@@ -65,6 +65,14 @@ module MkAcl
|
|
65
65
|
).align
|
66
66
|
puts
|
67
67
|
}
|
68
|
+
|
69
|
+
action.timestamps.each { |timestamp|
|
70
|
+
puts %(
|
71
|
+
insert into acl_portal.acl_timestamps (action_id, watch, stamp)
|
72
|
+
values (:action_id, '#{timestamp.watch}', '#{timestamp.stamp}');
|
73
|
+
).align
|
74
|
+
puts
|
75
|
+
}
|
68
76
|
}
|
69
77
|
end
|
70
78
|
|
@@ -43,43 +43,75 @@ module MkAcl
|
|
43
43
|
end
|
44
44
|
|
45
45
|
def parse_tables(spec, tables)
|
46
|
-
for table_name,
|
47
|
-
|
48
|
-
parent =
|
49
|
-
domain =
|
50
|
-
triggers =
|
51
|
-
acl =
|
46
|
+
for table_name, entries in tables
|
47
|
+
entries.is_a?(Hash) or error "Syntax error around '#{entries}'"
|
48
|
+
parent = entries.delete(:parent)
|
49
|
+
domain = entries.delete(:domain)
|
50
|
+
triggers = entries.key?(:triggers) ? entries.delete(:triggers) : true
|
51
|
+
acl = entries.key?(:acl) ? entries.delete(:acl) : true
|
52
52
|
table = Table.new(spec, table_name, domain, parent, triggers, acl)
|
53
|
-
parse_actions(table,
|
53
|
+
parse_actions(table, entries)
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
57
|
def parse_actions(table, actions)
|
58
|
-
for action_name,
|
58
|
+
for action_name, entries in actions
|
59
59
|
constrain?(action_name, :insert, :select, :update, :delete, :attach, :detach) or
|
60
60
|
error "Illegal action '#{action_name}'"
|
61
61
|
|
62
62
|
for real_action_name in (action_name == :attach ? [:attach, :detach] : [action_name])
|
63
|
-
constrain?(
|
64
|
-
error "Illegal value for #{action_name}
|
63
|
+
constrain?(entries, String, Array, Hash) or
|
64
|
+
error "Illegal value for #{action_name} entry '#{entries}'"
|
65
65
|
action = Action.new(table, real_action_name)
|
66
66
|
|
67
|
-
# Normalize
|
68
|
-
case
|
67
|
+
# Normalize entries
|
68
|
+
case entries
|
69
69
|
when Hash
|
70
|
-
|
70
|
+
timestamps = entries.delete(:timestamps) and parse_timestamps(action, timestamps)
|
71
|
+
entries = [entries]
|
71
72
|
when String
|
72
|
-
|
73
|
+
entries = [{ roles: entries }]
|
74
|
+
when Array
|
75
|
+
entries.reject! { |element|
|
76
|
+
timestamps = element.delete(:timestamps) and parse_timestamps(action, timestamps)
|
77
|
+
}
|
73
78
|
end
|
74
|
-
|
75
|
-
parse_rules(action, rules)
|
79
|
+
parse_rules(action, entries)
|
76
80
|
end
|
77
81
|
end
|
78
82
|
end
|
79
83
|
|
84
|
+
def parse_timestamps(table, timestamps)
|
85
|
+
# Normalize timestamps
|
86
|
+
timestamps = [timestamps] if timestamps.is_a?(Hash)
|
87
|
+
|
88
|
+
case timestamps
|
89
|
+
when String
|
90
|
+
timestamps.split.each { |watch_field|
|
91
|
+
Timestamp.new(table, watch_field)
|
92
|
+
}
|
93
|
+
when Array
|
94
|
+
for entry in timestamps
|
95
|
+
timestamp = Timestamp.new(table)
|
96
|
+
for key, value in entry
|
97
|
+
case key
|
98
|
+
when :watch; timestamp.watch = value
|
99
|
+
when :stamp; timestamp.stamp = value
|
100
|
+
else
|
101
|
+
error "Illegal field '#{key}' in #{table} timestamps"
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
else
|
106
|
+
error "Illegal timestamp type: #{timestamps.class}"
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
80
110
|
def parse_rules(action, rules)
|
81
111
|
ordinal = 0
|
112
|
+
|
82
113
|
for entry in rules
|
114
|
+
timestamps = entry.delete(:timestamps) and parse_timestamps(action, timestamps)
|
83
115
|
rule = Rule.new(action, ordinal += 1)
|
84
116
|
for key, value in entry
|
85
117
|
case key
|
@@ -87,7 +119,6 @@ module MkAcl
|
|
87
119
|
when :filter; rule.filter = norm_value(value)
|
88
120
|
when :assert; rule.assert = norm_value(value)
|
89
121
|
when :fields; rule.fields = value.nil? ? nil : norm_array(value)
|
90
|
-
when :fields; rule.fields = norm_array(value)
|
91
122
|
when :tables; rule.tables = norm_array(value)
|
92
123
|
else
|
93
124
|
raise ArgumentError, "Illegal field '#{key}' in #{action.table}.#{action}"
|
@@ -78,7 +78,7 @@ module MkAcl
|
|
78
78
|
# Associated record name. Used in function names and in conversions
|
79
79
|
attr_reader :record_name
|
80
80
|
|
81
|
-
# Action objects
|
81
|
+
# Action and timestamp objects
|
82
82
|
def insert = @actions["insert"]
|
83
83
|
def select = @actions["select"]
|
84
84
|
def update = @actions["update"]
|
@@ -117,6 +117,7 @@ module MkAcl
|
|
117
117
|
for action_name in %w(insert select update delete)
|
118
118
|
actions[action_name]&.dump
|
119
119
|
end
|
120
|
+
|
120
121
|
puts "triggers: #{triggers}"
|
121
122
|
case acl
|
122
123
|
when false; puts "acl: false"
|
@@ -137,26 +138,38 @@ module MkAcl
|
|
137
138
|
attr_reader :table
|
138
139
|
attr_reader :name
|
139
140
|
attr_reader :rules
|
141
|
+
attr_reader :timestamps
|
140
142
|
|
141
143
|
def initialize(table, name)
|
142
144
|
@table = table
|
143
145
|
@name = name.to_s
|
144
146
|
@rules = []
|
147
|
+
@timestamps = []
|
145
148
|
@table.send :attach_action, self
|
146
149
|
end
|
147
150
|
|
148
151
|
def to_s() name end
|
149
152
|
|
150
153
|
def dump
|
151
|
-
if rules.empty?
|
154
|
+
if rules.empty? && timestamps.empty?
|
152
155
|
puts "#{name}: []"
|
153
156
|
else
|
154
|
-
puts name
|
157
|
+
puts "#{name}:"
|
155
158
|
indent {
|
156
159
|
for rule in rules.sort_by(&:ordinal)
|
157
160
|
print "- "
|
158
161
|
indent(bol: false) { rule.dump }
|
159
162
|
end
|
163
|
+
|
164
|
+
if !timestamps.empty?
|
165
|
+
puts "- timestamps:"
|
166
|
+
indent {
|
167
|
+
for timestamp in timestamps
|
168
|
+
print "- "
|
169
|
+
indent(bol: false) { timestamp.dump }
|
170
|
+
end
|
171
|
+
}
|
172
|
+
end
|
160
173
|
}
|
161
174
|
end
|
162
175
|
end
|
@@ -165,6 +178,43 @@ module MkAcl
|
|
165
178
|
def attach_rule(rule)
|
166
179
|
@rules << rule
|
167
180
|
end
|
181
|
+
|
182
|
+
def attach_timestamp(timestamp)
|
183
|
+
@timestamps << timestamp
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
class Timestamp
|
188
|
+
attr_reader :action
|
189
|
+
forward_to :action, :table, :name
|
190
|
+
attr_accessor :watch
|
191
|
+
attr_accessor :stamp
|
192
|
+
|
193
|
+
def created_at?() = watch == "insert"
|
194
|
+
def updated_at?() = watch == "update"
|
195
|
+
def deleted_at?() = watch == "delete"
|
196
|
+
|
197
|
+
def initialize(action, watch = nil, stamp = nil)
|
198
|
+
@action = action
|
199
|
+
|
200
|
+
case watch
|
201
|
+
when /^(.*)(?:_by_id|_to_id)$/
|
202
|
+
@watch, @stamp = watch, stamp || "#{$1}_at"
|
203
|
+
when "created_at", "updated_at", "deleted_at"
|
204
|
+
@watch, @stamp = nil, watch
|
205
|
+
else
|
206
|
+
@watch, @stamp = watch, stamp
|
207
|
+
end
|
208
|
+
|
209
|
+
action.send :attach_timestamp, self
|
210
|
+
end
|
211
|
+
|
212
|
+
def to_s() = watch
|
213
|
+
|
214
|
+
def dump
|
215
|
+
puts "watch: #{watch}"
|
216
|
+
puts "stamp: #{stamp}"
|
217
|
+
end
|
168
218
|
end
|
169
219
|
|
170
220
|
class Rule
|
data/lib/mikras_utils/version.rb
CHANGED