lorj 1.0.16 → 1.0.17

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: df0501318f36deb3f6d31fdce4d63f148d91a818
4
- data.tar.gz: 6800e36135d9decb469b1d9dc87e1f3be7385980
3
+ metadata.gz: fd2e3ef16b60623e7d392719983d1c656b90cb73
4
+ data.tar.gz: 5342df87489d1d9feacf527edce9a1ca321358d0
5
5
  SHA512:
6
- metadata.gz: b14d5a49cfe34e91495e412e1c64041ecad1c38927dda2c555e4b57d2589182863a1bbe6e49492639638d6ecdc8121895f667878d77f91ca5ef32a944b20f87b
7
- data.tar.gz: 61d2970cecf4ba70bb01135ecfcc6813bf43ff89c708aa0e29c716975881562cca13b611d533414f263a9d289ddaada7bea8a6fdb83ea43d1abd0ea4b60b6592
6
+ metadata.gz: 0dcd158c91dfeb3d058e0f7374a167ba7efaf9974c14b0b734875d020e3ed9bd4333432adec1a2680d07cb2999ea4c7d31865013b7e6e918319675b7e0814236
7
+ data.tar.gz: eac85b8e31ca9c05cb7002f1064e4f121fd1254d3673c9baae4c1f12c337a512c9c3008018f626edbe5f0d113ae961fdbd2570319a29c07b2fcea05bbbd57458
@@ -48,14 +48,20 @@ class Test < Lorj::BaseDefinition
48
48
 
49
49
  private
50
50
 
51
+ # Test if the encryted data (if encrypted) is readable
51
52
  def account_key_test
52
- entr = _get_encrypt_key
53
- data = @core.config['credentials#account_key']
54
-
55
- res = Lorj::SSLCrypt.get_encrypted_value(data, entr,
56
- 'credentials#account_key')
57
-
58
- test_state(!res.nil?, 'Account key', data)
53
+ key = 'credentials#account_key'
54
+ opts = Lorj.data.auto_section_data(key)
55
+ data = @core.config[key]
56
+ if opts[:encrypted].is_a?(TrueClass)
57
+ entr = _get_encrypt_key
58
+
59
+ res = Lorj::SSLCrypt.get_encrypted_value(data, entr, key)
60
+ status = !res.nil?
61
+ else
62
+ status = true
63
+ end
64
+ test_state(status, key, data)
59
65
  end
60
66
 
61
67
  def test_state(res, test, value)
data/lib/core/core.rb CHANGED
@@ -347,9 +347,11 @@ module Lorj
347
347
  # - env_hash: String. Base64 encrypted Hash.
348
348
  # OR
349
349
  # - nil if issues.
350
- def account_export(map = nil, with_name = true)
350
+ def account_export(map = nil, with_name = true, account_only = false,
351
+ processes_options = {})
351
352
  return nil if @core_object.nil?
352
- @core_object.account_export(map, with_name)
353
+ @core_object.account_export(map, with_name, account_only,
354
+ processes_options)
353
355
  end
354
356
 
355
357
  # Core parameters are:
@@ -139,13 +139,16 @@ module Lorj
139
139
  # True by default.
140
140
  # - +account_only+ : True data extracted must come exclusively from the
141
141
  # config 'account' layer.
142
+ # - +processes_options+ : Hash. Export options for processes
143
+ # - :exclude: Array. name of process to exclude.
142
144
  #
143
145
  # * *returns* :
144
146
  # - key: String. Key used to encrypt.
145
147
  # - env_hash: String. Base64 encrypted Hash.
146
148
  # OR
147
149
  # - nil if issues.
148
- def account_export(map = nil, with_name = true, account_only = true)
150
+ def account_export(map = nil, with_name = true, account_only = true,
151
+ processes_options = {})
149
152
  map = _account_map if map.nil?
150
153
 
151
154
  map.merge!('account#name' => {}, 'account#provider' => {}) if with_name
@@ -172,21 +175,26 @@ module Lorj
172
175
  entr = Lorj::SSLCrypt.new_encrypt_key
173
176
  export_data = { :enc_data => Lorj::SSLCrypt.encrypt_value(rhash.to_yaml,
174
177
  entr) }
175
- export_data[:processes] = _export_processes
178
+ export_data[:processes] = _export_processes(processes_options)
176
179
  [entr, export_data.to_yaml]
177
180
  end
178
181
 
179
182
  private
180
183
 
181
- def _export_processes
184
+ def _export_processes(processes_options)
182
185
  export_data = []
183
186
  PrcLib.processes.each do |p|
184
187
  next unless p.key?(:process_name) && p.key?(:lib_name)
185
188
 
189
+ next if processes_options[:exclude].is_a?(Array) &&
190
+ processes_options[:exclude].include?(p[:process_name])
191
+
186
192
  process = {}
187
193
  process[:process_module] = p[:process_name]
188
194
  process[:lib_name] = p[:lib_name]
189
- process[:controller] = p[:controller_name] if p.key?(:controller_name)
195
+ if p.key?(:controller_name)
196
+ process[:controller_name] = p[:controller_name]
197
+ end
190
198
  export_data << process if process.length > 0
191
199
  end
192
200
  export_data
@@ -480,7 +480,7 @@ module Lorj
480
480
  # Internal function
481
481
  def self._query_mapping(key, map)
482
482
  return nil unless [String, Symbol].include?(key.class)
483
- return nil unless [NilClass, Symbol, String].include?(map.class)
483
+ return nil unless [NilClass, Symbol, String, Array].include?(map.class)
484
484
 
485
485
  object_type = PrcLib.model.object_context
486
486
  key_path = KeyPath.new(key)
@@ -104,7 +104,10 @@ module Lorj
104
104
  end
105
105
  controller_error '%s is not set.', key
106
106
  end
107
+ end
107
108
 
109
+ # Defining private internal controller functions
110
+ class BaseController
108
111
  private
109
112
 
110
113
  # controller helper function:
@@ -115,19 +118,40 @@ module Lorj
115
118
  # - +objects+ : Collection of object which respond to each
116
119
  # - +query+ : Hash. Containing a list of attributes to test
117
120
  # See #ctrl_do_query_match for details
118
- # - +&block+ : block to extract the object data from a key.
119
- def ctrl_query_each(objects, query) # :doc:
121
+ # - +triggers+: Hash. Optional. Procs to interact at several places:
122
+ # - :before : &code(object) - To execute some code on the object
123
+ # before extract.
124
+ # *return* true to go on, or false to ignore the object.
125
+ # - :after : &code(object, query, selected) - To execute some code on
126
+ # the object after extract.
127
+ # This after trigger is the last change to select or not the object
128
+ # for the query. Note that query structure defined by lorj by default.
129
+ # *return* true if the object is selected. false otherwise.
130
+ # - :extract : &code(object, key) - To execute the data extraction
131
+ # This block is required only if call of [] or :<key> is not supported
132
+ # *return* the value extracted.
133
+ #
134
+ def ctrl_query_each(objects, query, triggers = {}) # :doc:
120
135
  results = []
121
136
  Lorj.debug(4, "Filtering with '%s'", query)
122
137
  unless objects.class.method_defined?(:each)
123
138
  controller_error "'%s' do not have 'each' function.", objects.class
124
139
  end
125
140
  objects.each do |o|
126
- if block_given?
127
- selected = ctrl_do_query_match(o, query) { |d, k| yield d, k }
141
+ if [Proc, Method].include?(triggers[:before].class)
142
+ code = triggers[:before]
143
+ next unless code.call o
144
+ end
145
+ if [Proc, Method].include?(triggers[:extract].class)
146
+ code = triggers[:extract]
147
+ selected = ctrl_do_query_match(o, query) { |d, k| code.call d, k }
128
148
  else
129
149
  selected = ctrl_do_query_match(o, query)
130
150
  end
151
+ if [Proc, Method].include?(triggers[:after].class)
152
+ code = triggers[:after]
153
+ selected = code.call o, query, selected
154
+ end
131
155
  results.push o if selected
132
156
  end
133
157
  Lorj.debug(4, '%d records selected', results.length)
@@ -155,7 +179,7 @@ module Lorj
155
179
  # - No exception
156
180
  #
157
181
  # by default, this function will extract data from the object
158
- # with followinf functions: If one fails, it will try the next one.
182
+ # with following functions: If one fails, it will try the next one.
159
183
  # :[], or :key or &block.
160
184
  # The optional &block is a third way defined by the controller to extract
161
185
  # data.
@@ -171,15 +195,18 @@ module Lorj
171
195
  def ctrl_do_query_match(object, query)
172
196
  selected = true
173
197
  query.each do |key, match_value|
198
+ key_path = KeyPath.new(key)
174
199
  if block_given?
175
- found, v = _get_from(object, key) { |d, k| yield d, k }
200
+ found, v = _get_from(object, key_path.tree) { |d, k| yield d, k }
176
201
  else
177
- found, v = _get_from(object, key)
202
+ found, v = _get_from(object, key_path.tree)
178
203
  end
179
204
 
180
205
  Lorj.debug(4, "'%s.%s' = '%s'", object.class, key, v) if found
181
206
 
182
- selected = lorj_filter_regexp(v, match_value)
207
+ selected = lorj_filter_regexp(v, match_value)
208
+ selected |= lorj_filter_hash(v, match_value)
209
+ selected |= lorj_filter_array(v, match_value)
183
210
  selected |= lorj_filter_default(v, match_value)
184
211
  break unless selected
185
212
  end
@@ -192,12 +219,20 @@ module Lorj
192
219
  query.select { |_k, v| limit.include?(v.class) }
193
220
  end
194
221
 
195
- def _get_from(data, key)
222
+ def _get_from(data, *key)
196
223
  ret = nil
197
224
  found = nil
225
+ key.flatten!
226
+
227
+ if data.is_a?(Hash)
228
+ found = data.rh_exist?(*key)
229
+ ret = data.rh_get(*key)
230
+ return [found, ret]
231
+ end
198
232
 
199
- [:[], key].each do |f|
200
- found, ret = _get_from_func(data, key, f)
233
+ [:[], key[0]].each do |f|
234
+ found, ret = _get_from_func(data, key[0], f)
235
+ return _get_from(ret, key[1..-1]) if found && key.length > 1
201
236
  break if found
202
237
  end
203
238
  return [found, ret] if found || !block_given?
@@ -213,7 +248,7 @@ module Lorj
213
248
  end
214
249
 
215
250
  def _get_from_func(data, key, func = nil)
216
- func = key if func.nil?
251
+ func = key[0] if func.nil?
217
252
  v = nil
218
253
  if data.class.method_defined?(func)
219
254
  begin
@@ -248,6 +283,42 @@ module Lorj
248
283
  false
249
284
  end
250
285
 
286
+ # Function to check if a value is found in an Array
287
+ #
288
+ # * *returns*:
289
+ # - true if found
290
+ # OR
291
+ # - false otherwise
292
+ #
293
+ def lorj_filter_array(value, match_value)
294
+ return false unless value.is_a?(Array) || match_value.is_a?(Array)
295
+
296
+ if value.is_a?(Array) && match_value.is_a?(Array)
297
+ return (value.sort == match_value.sort)
298
+ end
299
+
300
+ value.include?(match_value)
301
+ end
302
+
303
+ # Function to check if a value match a filter value.
304
+ #
305
+ # * *returns*:
306
+ # - true if match
307
+ # OR
308
+ # - false otherwise
309
+ #
310
+ def lorj_filter_hash(value, structure)
311
+ return false unless value.is_a?(Hash)
312
+
313
+ key_path = KeyPath.new(structure)
314
+ tree = key_path.tree[0..-2]
315
+ return false unless value.rh_exist?(tree)
316
+ match_value = key_path.key
317
+ res = value.rh_get(tree)
318
+ return lorj_filter_array(res.flatten, match_value) if res.is_a?(Array)
319
+ lorj_filter_default(res, match_value)
320
+ end
321
+
251
322
  # Function to check if a value match a filter value.
252
323
  #
253
324
  # * *returns*:
@@ -137,9 +137,9 @@ module Lorj
137
137
  object_type, key_path_obj.key,
138
138
  value unless value_mapping.rh_exist?(value)
139
139
 
140
- result.rh_set(value_mapping[value], map_path.tree)
140
+ result.rh_set(value_mapping[value], map_path.to_s)
141
141
  else
142
- result.rh_set(value, map_path.tree)
142
+ result.rh_set(value, map_path.to_s)
143
143
  end
144
144
  nil
145
145
  end
@@ -111,9 +111,11 @@ module Lorj
111
111
  class BaseProcess
112
112
  private
113
113
 
114
- def account_export(map = nil, with_name = true, account_only = false) #:doc:
114
+ def account_export(map = nil, with_name = true, account_only = false,
115
+ processes_options = {}) #:doc:
115
116
  fail Lorj::PrcError.new, 'No Base object loaded.' unless @base_object
116
- @base_object.account_export(map, with_name, account_only)
117
+ @base_object.account_export(map, with_name, account_only,
118
+ processes_options)
117
119
  end
118
120
 
119
121
  def account_import(key, enc_hash, name = nil, controller = nil) #:doc:
@@ -34,8 +34,8 @@ module Lorj
34
34
  # oKey = KeyPath(:test)
35
35
  # puts oKey.to_s # => 'test'
36
36
  # puts oKey.key # => :test
37
- # puts oKey.key[0] # => :test
38
- # puts oKey.key[1] # => nil
37
+ # puts oKey.key(0) # => :test
38
+ # puts oKey.key(1) # => nil
39
39
  # puts oKey.fpath # => ':test'
40
40
  # puts oKey.tree # => [:test]
41
41
  # puts oKey.key_tree # => :test
@@ -43,8 +43,8 @@ module Lorj
43
43
  # oKey = KeyPath([:test,:test2,:test3])
44
44
  # puts oKey.to_s # => 'test/test2/test3'
45
45
  # puts oKey.key # => :test3
46
- # puts oKey.key[0] # => :test
47
- # puts oKey.key[1] # => :test2
46
+ # puts oKey.key(0) # => :test
47
+ # puts oKey.key(1) # => :test2
48
48
  # puts oKey.fpath # => ':test/:test2/:test3'
49
49
  # puts oKey.tree # => [:test,:test2,:test3]
50
50
  # puts oKey.key_tree # => ':test/:test2/:test3'
@@ -52,8 +52,8 @@ module Lorj
52
52
  # oKey = KeyPath([:test, '{/.*/}', :test3])
53
53
  # puts oKey.to_s # => 'test/{\/.*\/}/test3'
54
54
  # puts oKey.key # => :test3
55
- # puts oKey.key[0] # => :test
56
- # puts oKey.key[1] # => '{/.*/}'
55
+ # puts oKey.key(0) # => :test
56
+ # puts oKey.key(1) # => '{/.*/}'
57
57
  # puts oKey.fpath # => ':test/{\/.*\/}/:test3'
58
58
  # puts oKey.tree # => [:test, '{/.*/}',:test3]
59
59
  # puts oKey.key_tree # => ':test/{\/.*\/}/:test3'
data/lib/lorj/version.rb CHANGED
@@ -16,6 +16,6 @@
16
16
 
17
17
  # Lorj version
18
18
  module Lorj
19
- VERSION = '1.0.16'
20
- DATE = '2015-06-25'
19
+ VERSION = '1.0.17'
20
+ DATE = '2015-06-26'
21
21
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lorj
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.16
4
+ version: 1.0.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - forj team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-25 00:00:00.000000000 Z
11
+ date: 2015-06-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler