eco-helpers 3.0.37 → 3.1.2

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.
Files changed (136) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -0
  3. data/CHANGELOG.md +132 -1
  4. data/lib/eco/api/common/loaders/base.rb +2 -2
  5. data/lib/eco/api/common/loaders/case_base.rb +2 -0
  6. data/lib/eco/api/common/loaders/config/block.rb +78 -0
  7. data/lib/eco/api/common/loaders/config/workflow/mailer.rb +49 -6
  8. data/lib/eco/api/common/loaders/config.rb +3 -26
  9. data/lib/eco/api/common/loaders/error_handler.rb +2 -0
  10. data/lib/eco/api/common/loaders/parser.rb +1 -4
  11. data/lib/eco/api/common/people/entries.rb +23 -6
  12. data/lib/eco/api/common/people/entry_factory.rb +1 -1
  13. data/lib/eco/api/common/people/person_entry.rb +104 -27
  14. data/lib/eco/api/common/people/person_parser.rb +50 -16
  15. data/lib/eco/api/common/people/supervisor_helpers.rb +12 -6
  16. data/lib/eco/api/common/session/base_session.rb +75 -81
  17. data/lib/eco/api/common/session/environment.rb +70 -70
  18. data/lib/eco/api/common/session/file_manager.rb +132 -135
  19. data/lib/eco/api/common/session/helpers/prompt_user.rb +23 -30
  20. data/lib/eco/api/common/session/helpers.rb +10 -15
  21. data/lib/eco/api/common/session/logger/cache.rb +94 -96
  22. data/lib/eco/api/common/session/logger/channels.rb +24 -32
  23. data/lib/eco/api/common/session/logger/log.rb +38 -46
  24. data/lib/eco/api/common/session/logger.rb +50 -54
  25. data/lib/eco/api/common/session/mailer/aws_provider.rb +64 -71
  26. data/lib/eco/api/common/session/mailer/provider_base.rb +43 -48
  27. data/lib/eco/api/common/session/mailer/sendgrid_provider.rb +101 -109
  28. data/lib/eco/api/common/session/mailer.rb +78 -83
  29. data/lib/eco/api/common/session/s3_uploader.rb +132 -138
  30. data/lib/eco/api/common/session/sftp.rb +202 -208
  31. data/lib/eco/api/common.rb +0 -3
  32. data/lib/eco/api/custom/mailer.rb +4 -2
  33. data/lib/eco/api/error/handlers.rb +1 -1
  34. data/lib/eco/api/microcases/people/apply_changes/set_core/core_excluded.rb +8 -2
  35. data/lib/eco/api/microcases/people/manage/search.rb +2 -2
  36. data/lib/eco/api/organization/people/similarity.rb +3 -3
  37. data/lib/eco/api/organization/people.rb +2 -2
  38. data/lib/eco/api/session/batch/base_policy.rb +42 -27
  39. data/lib/eco/api/session/batch/launcher/mode_size.rb +6 -1
  40. data/lib/eco/api/session/batch/launcher.rb +16 -3
  41. data/lib/eco/api/session/config/api.rb +4 -3
  42. data/lib/eco/api/session/config/apis/one_off.rb +1 -1
  43. data/lib/eco/api/session/config/files.rb +13 -12
  44. data/lib/eco/api/session/config/workflow.rb +1 -373
  45. data/lib/eco/api/session/config.rb +45 -10
  46. data/lib/eco/api/session.rb +7 -9
  47. data/lib/eco/api/usecases/base_case/model.rb +6 -6
  48. data/lib/eco/api/usecases/base_case.rb +1 -1
  49. data/lib/eco/api/usecases/cli.rb +1 -1
  50. data/lib/eco/api/usecases/default/locations/tagtree_extract_case.rb +22 -13
  51. data/lib/eco/api/usecases/default_cases/to_csv_case.rb +4 -1
  52. data/lib/eco/api/usecases/graphql/helpers/location/tags_remap.rb +6 -3
  53. data/lib/eco/api/usecases/graphql/samples/location/command/dsl.rb +2 -2
  54. data/lib/eco/api/usecases/lib/base/env.rb +21 -23
  55. data/lib/eco/api/usecases/lib/files/file_pattern.rb +41 -14
  56. data/lib/eco/api/usecases/lib/files/input_file.rb +110 -0
  57. data/lib/eco/api/usecases/lib/files/sftp.rb +5 -2
  58. data/lib/eco/api/usecases/lib/files.rb +1 -0
  59. data/lib/eco/api/usecases/lib/locations/base.rb +23 -0
  60. data/lib/eco/api/usecases/lib/locations/mapping.rb +94 -0
  61. data/lib/eco/api/usecases/lib/locations.rb +7 -0
  62. data/lib/eco/api/usecases/lib/people/base.rb +20 -0
  63. data/lib/eco/api/usecases/lib/people.rb +6 -0
  64. data/lib/eco/api/usecases/lib.rb +2 -0
  65. data/lib/eco/api/usecases/ooze_cases.rb +1 -1
  66. data/lib/eco/api/usecases/ooze_samples/ooze_base_case.rb +1 -1
  67. data/lib/eco/api/usecases/ooze_samples/ooze_from_doc_case.rb +3 -3
  68. data/lib/eco/api/usecases/ooze_samples/ooze_run_base_case.rb +4 -1
  69. data/lib/eco/api/usecases/ooze_samples/ooze_update_case.rb +1 -1
  70. data/lib/eco/api/usecases/ooze_samples/register_export_case.rb +6 -2
  71. data/lib/eco/api/usecases/ooze_samples/register_migration_case.rb +7 -6
  72. data/lib/eco/api/usecases/ooze_samples/register_update_case.rb +14 -4
  73. data/lib/eco/api/usecases/ooze_samples/target_oozes_update_case.rb +11 -8
  74. data/lib/eco/api/usecases/samples/drivers/sftp_sample.rb +2 -0
  75. data/lib/eco/api/usecases/samples/drivers/url_pull_sample.rb +8 -2
  76. data/lib/eco/api/usecases/service/sftp/with_target_config.rb +0 -33
  77. data/lib/eco/api/usecases/service/sftp.rb +7 -1
  78. data/lib/eco/api/usecases/use_case.rb +3 -2
  79. data/lib/eco/api/usecases/workflow.rb +5 -0
  80. data/lib/eco/api/usecases.rb +12 -5
  81. data/lib/eco/cli/scripting/args_helpers.rb +1 -9
  82. data/lib/eco/cli_default/options.rb +98 -68
  83. data/lib/eco/cli_default/workflow/end.rb +22 -0
  84. data/lib/eco/cli_default/workflow/launch_jobs.rb +14 -0
  85. data/lib/eco/cli_default/workflow/load/data.rb +27 -0
  86. data/lib/eco/cli_default/workflow/load/input.rb +28 -0
  87. data/lib/eco/cli_default/workflow/load.rb +13 -0
  88. data/lib/eco/cli_default/workflow/options.rb +18 -0
  89. data/lib/eco/cli_default/workflow/post_launch.rb +65 -0
  90. data/lib/eco/cli_default/workflow/report.rb +17 -0
  91. data/lib/eco/cli_default/workflow/rescued_exception.rb +21 -0
  92. data/lib/eco/cli_default/workflow/usecases.rb +23 -0
  93. data/lib/eco/cli_default/workflow.rb +24 -180
  94. data/lib/eco/data/count_trace.rb +51 -0
  95. data/lib/eco/data/files/content.rb +39 -0
  96. data/lib/eco/data/files/directory.rb +78 -45
  97. data/lib/eco/data/files/encoding.rb +12 -21
  98. data/lib/eco/data/files/file_pattern.rb +15 -8
  99. data/lib/eco/data/files/folder.rb +196 -0
  100. data/lib/eco/data/files/relative_path.rb +54 -0
  101. data/lib/eco/data/files/timestamp.rb +18 -0
  102. data/lib/eco/data/files.rb +46 -5
  103. data/lib/eco/data/fuzzy_match.rb +1 -1
  104. data/lib/eco/data/hashes/array_diff.rb +11 -5
  105. data/lib/eco/data/hashes/diff_result/meta.rb +12 -4
  106. data/lib/eco/data/locations/node_diff/accessors.rb +1 -1
  107. data/lib/eco/data/mapper.rb +8 -1
  108. data/lib/eco/data.rb +1 -0
  109. data/lib/eco/language/auxiliar_logger.rb +6 -11
  110. data/lib/eco/language/delegation/delegating_missing.rb +1 -1
  111. data/lib/eco/language/delegation/delegating_missing_const.rb +1 -1
  112. data/lib/eco/language/delegation/delegating_missing_on_class.rb +1 -1
  113. data/lib/eco/language/delegation/for_delegator/delegated_class.rb +1 -1
  114. data/lib/eco/language/klass/auto_loader.rb +129 -0
  115. data/lib/eco/language/klass/builder.rb +6 -6
  116. data/lib/eco/language/klass/const.rb +19 -0
  117. data/lib/eco/language/klass/helpers_built.rb +3 -1
  118. data/lib/eco/language/klass/hierarchy.rb +5 -1
  119. data/lib/eco/language/klass/naming.rb +5 -2
  120. data/lib/eco/language/klass/resolver.rb +21 -6
  121. data/lib/eco/language/klass/uid.rb +12 -0
  122. data/lib/eco/language/klass/when_inherited.rb +30 -6
  123. data/lib/eco/language/klass.rb +5 -2
  124. data/lib/eco/language/methods/access_modifier.rb +23 -0
  125. data/lib/eco/language/methods/instance_method_helpers.rb +6 -1
  126. data/lib/eco/language/methods.rb +1 -0
  127. data/lib/eco/language/models/hierarchy.rb +41 -0
  128. data/lib/eco/language/models/workflow.rb +385 -0
  129. data/lib/eco/language/models.rb +2 -1
  130. data/lib/eco/version.rb +1 -1
  131. metadata +31 -7
  132. data/lib/eco/api/common/class_auto_loader.rb +0 -114
  133. data/lib/eco/api/common/class_helpers.rb +0 -9
  134. data/lib/eco/api/common/class_hierarchy.rb +0 -45
  135. data/lib/eco/data/files/helpers.rb +0 -152
  136. data/lib/eco/language/models/class_helpers.rb +0 -136
@@ -19,7 +19,9 @@ module Eco
19
19
  # @attr_reader max [Integer] `max` **allowed** number of occurrences of the property
20
20
  # @attr_reader min [Integer] `min` **required** number of occurrences of the property
21
21
  class BasePolicy
22
- extend Eco::API::Common::ClassHierarchy
22
+ extend Eco::Language::Klass::HelpersBuilt
23
+ extend Eco::Language::Models::Hierarchy
24
+
23
25
  # adds evaluate method to enable block calls as DSL
24
26
  include Eco::Language::Methods::DslAble
25
27
 
@@ -31,9 +33,12 @@ module Eco
31
33
  key = key.to_sym.freeze
32
34
  class_name = to_constant(key)
33
35
 
34
- new_class(class_name, inherits: Eco::API::Session::Batch::BasePolicy) do |klass|
36
+ new_class(
37
+ class_name,
38
+ inherits: Eco::API::Session::Batch::BasePolicy
39
+ ) do |klass|
35
40
  klass.model = model[key]
36
- klass.policy_attrs *klass.model_attrs
41
+ klass.policy_attrs(*klass.model_attrs)
37
42
  end
38
43
  end
39
44
 
@@ -47,7 +52,7 @@ module Eco
47
52
  var = "@#{method}".freeze
48
53
 
49
54
  define_method(method) do |&block|
50
- unless policy = self[attr]
55
+ unless (policy = self[attr])
51
56
  klass = self.class.policy_class(attr)
52
57
  policy = self[attr] = klass.new(attr, _parent: self)
53
58
  end
@@ -65,10 +70,9 @@ module Eco
65
70
 
66
71
  include Enumerable
67
72
 
68
- attr_reader :attr
69
- attr_accessor :max, :min
73
+ attr_writer :max, :min, :count
70
74
 
71
- def initialize(attr = nil, _parent: self)
75
+ def initialize(attr = nil, _parent: self) # rubocop:disable Lint/UnderscorePrefixedVariableName
72
76
  @_parent = _parent
73
77
  @attr = attr.to_sym
74
78
  @policies = {}
@@ -76,16 +80,19 @@ module Eco
76
80
 
77
81
  def max(value = :unused)
78
82
  return @max if value == :unused
83
+
79
84
  self.max = value
80
85
  end
81
86
 
82
87
  def min(value = :unused)
83
88
  return @min if value == :unused
89
+
84
90
  self.min = value
85
91
  end
86
92
 
87
93
  def attr(as_namespace: false)
88
94
  return @attr if !as_namespace || root?
95
+
89
96
  "#{@_parent.attr(as_namespace: true)}:#{@attr}"
90
97
  end
91
98
 
@@ -110,7 +117,7 @@ module Eco
110
117
 
111
118
  # @return [Boolean] `true` if there are no active subpolicies, `false` otherwise
112
119
  def empty?
113
- count == 0
120
+ count.zero?
114
121
  end
115
122
 
116
123
  # @return [Boolean] `true` if there are active subpolicies, `false` otherwise
@@ -120,6 +127,7 @@ module Eco
120
127
 
121
128
  def each(&block)
122
129
  return to_enum(:each) unless block
130
+
123
131
  items.each(&block)
124
132
  end
125
133
 
@@ -141,9 +149,12 @@ module Eco
141
149
  end
142
150
 
143
151
  # @param attr [Symbol, String] name of the policy
144
- # @param value [Expected object of Eco::API::Session::Batch::BasePolicy] a subpolicy to assign to a name `attr`
152
+ # @param value [Expected object of Eco::API::Session::Batch::BasePolicy] a subpolicy
153
+ # to assign to a name `attr`
145
154
  def []=(attr, value)
146
- raise "Expected object of Eco::API::Session::Batch::BasePolicy. Given #{value.class}" unless value.is_a?(Eco::API::Session::Batch::BasePolicy)
155
+ msg = "Expected object of Eco::API::Session::Batch::BasePolicy. Given #{value.class}"
156
+ raise ArgumentError, msg unless value.is_a?(Eco::API::Session::Batch::BasePolicy)
157
+
147
158
  @policies[attr.to_sym] = value
148
159
  end
149
160
 
@@ -151,9 +162,10 @@ module Eco
151
162
  # @param recurse [Boolean] to determine if we only check the current policy or also all active subpolicies
152
163
  # @return [Boolean] `true` if `model` is compliant with the current policy
153
164
  def compliant?(model, recurse: true)
154
- unless hash = model_to_hash(model)
155
- raise "Expected 'model' to be a Hash (or hashable) object. Given: #{model}"
165
+ unless (hash = model_to_hash(model))
166
+ raise ArgumentError, "Expected 'model' to be a Hash (or hashable) object. Given: #{model}"
156
167
  end
168
+
157
169
  value = model_attr(hash)
158
170
  good = !model_attr?(hash) || (min?(value) && max?(value))
159
171
  #pp "batch_policy: '#{attr}' - #{value}: 'min' #{min?(value)}; 'max' #{max?(value)}"
@@ -162,10 +174,10 @@ module Eco
162
174
  end
163
175
 
164
176
  def validate!(model)
165
- unless compliant?(model)
166
- msg = self.uncompliance(model)
167
- raise "Uncompliance Exception\n#{msg}"
168
- end
177
+ return if compliant?(model)
178
+
179
+ msg = uncompliance(model)
180
+ raise "Uncompliance Exception\n#{msg}"
169
181
  end
170
182
 
171
183
  # @param model [Hash] plain hash (or hashable object) with the stats to check policy compliance against
@@ -182,25 +194,27 @@ module Eco
182
194
  # @param recurse [Boolean] to determine if we only check the current policy or also all active subpolicies
183
195
  # @return [String] message with what failed to meet compliance
184
196
  def uncompliance(model, recurse: true)
185
- unless hash = model_to_hash(model)
186
- raise "Expected 'model' to be a Hash (or hashable) object. Given: #{model}"
197
+ unless (hash = model_to_hash(model))
198
+ raise ArgumentError, "Expected 'model' to be a Hash (or hashable) object. Given: #{model}"
187
199
  end
188
- msg = ""
200
+
201
+ msg = ''
189
202
  unless compliant?(hash, recurse: false)
190
203
  value = model_attr(hash)
191
- msg += "'#{attr(as_namespace: true)}' fails to meet: "
192
- msg += " [ min(#{min}) >= #{value}] " unless min?(value)
193
- msg += " [ max(#{max}) <= #{value}] " unless max?(value)
194
- msg += "\n"
204
+ msg << "'#{attr(as_namespace: true)}' fails to meet: "
205
+ msg << " [ min(#{min}) >= #{value}] " unless min?(value)
206
+ msg << " [ max(#{max}) <= #{value}] " unless max?(value)
207
+ msg << "\n"
195
208
  end
196
209
 
197
210
  if recurse
198
211
  map do |active|
199
212
  active.uncompliance(hash, recurse: true)
200
213
  end.compact.tap do |msgs|
201
- msg += "\n" + msgs.join("\n") unless msgs.empty?
214
+ msg << "\n#{msgs.join("\n")}" unless msgs.empty?
202
215
  end
203
216
  end
217
+
204
218
  msg
205
219
  end
206
220
 
@@ -217,18 +231,19 @@ module Eco
217
231
  end
218
232
 
219
233
  def model_attr?(hash)
220
- hash.key?(self.attr) || hash.key?(self.attr.to_s)
234
+ hash.key?(self.attr) || hash.key?(self.attr.to_s) # rubocop:disable Style/RedundantSelf
221
235
  end
222
236
 
223
237
  def model_attr(hash)
224
- return hash[self.attr] if hash.key?(self.attr)
225
- hash[self.attr.to_s] if model_attr?(hash)
238
+ return hash[self.attr] if hash.key?(self.attr) # rubocop:disable Style/RedundantSelf
239
+ hash[self.attr.to_s] if model_attr?(hash) # rubocop:disable Style/RedundantSelf
226
240
  end
227
241
 
228
242
  private
229
243
 
230
244
  def model_to_hash(model)
231
245
  return model if model.is_a?(Hash)
246
+
232
247
  model.to_h if model.respond_to?(:to_h)
233
248
  end
234
249
  end
@@ -8,6 +8,7 @@ module Eco
8
8
 
9
9
  DEFAULT_BATCH_SIZE = 50
10
10
  DEFAULT_JOB_SIZE = 100
11
+ MIN_JOB_SIZE = 15
11
12
 
12
13
  def batch_size(opts = options)
13
14
  return job_mode_size if job_mode?(opts)
@@ -18,7 +19,11 @@ module Eco
18
19
  private
19
20
 
20
21
  # Swaps to batch endpoint on specific errors
21
- def batch_mode_on(*error_types, options: self.options, allow_job_mode: true)
22
+ def batch_mode_on(
23
+ *error_types,
24
+ options: self.options,
25
+ allow_job_mode: true
26
+ )
22
27
  msg = 'Expecting block. Non given'
23
28
  raise ArgumentError, msg unless block_given?
24
29
 
@@ -58,7 +58,7 @@ module Eco
58
58
  )
59
59
  end
60
60
 
61
- def launch_batch( # rubocop:disable Metrics/AbcSize
61
+ def launch_batch( # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
62
62
  data,
63
63
  method:,
64
64
  status: nil,
@@ -67,10 +67,19 @@ module Eco
67
67
  people_api: api&.people,
68
68
  silent: false
69
69
  )
70
- tap_status(status: status, enviro: enviro, queue: data, method: method) do |overall_status|
70
+ tap_status(
71
+ status: status,
72
+ enviro: enviro,
73
+ queue: data,
74
+ method: method
75
+ ) do |overall_status|
71
76
  pending_for_server_error = data.to_a[0..]
72
77
 
73
- batch_mode_on(*RETRY_ON, options: options, allow_job_mode: job_mode) do |as_job_mode, per_page|
78
+ batch_mode_on(
79
+ *RETRY_ON,
80
+ options: options,
81
+ allow_job_mode: job_mode
82
+ ) do |as_job_mode, per_page|
74
83
  iteration = 0
75
84
  done = 0
76
85
  iterations = (data.length.to_f / per_page).ceil
@@ -85,6 +94,9 @@ module Eco
85
94
  msg << (' ' * 20)
86
95
  log(:info) { msg } unless silent
87
96
 
97
+ # Use batch endpoint, rather than job when min not reached
98
+ as_job_mode &&= slice.length >= MIN_JOB_SIZE
99
+
88
100
  start_slice = Time.now
89
101
 
90
102
  offer_retry_on(*RETRY_ON, retries_left: TIMEOUT_RETRIES) do
@@ -136,6 +148,7 @@ module Eco
136
148
  server_error = !res_status || res_status.server_error?
137
149
  other_error = !server_error && (!res_status.code || res_status.code < 100)
138
150
  no_body = !server_error && !other_error && !response.body
151
+
139
152
  server_error || other_error || no_body
140
153
  end
141
154
  end
@@ -96,7 +96,7 @@ module Eco
96
96
  # @param logger [Logger] the logger that will be used with this api instance.
97
97
  # @return [Ecoportal::API::Internal, Ecoportal::API::V2, Ecoportal::API::V1]
98
98
  def api(version: nil, logger: nil)
99
- version = version ? version : self.version
99
+ version ||= self.version
100
100
  switch_logger = (logger != @logger)
101
101
  @logger = logger if logger
102
102
 
@@ -135,9 +135,10 @@ module Eco
135
135
  self.class.description(self)
136
136
  end
137
137
 
138
- # @todo: deletage to `apis.one_off?`
139
138
  def one_off?
140
- name.is_a?(Symbol)
139
+ return false unless @root.respond_to?(:one_off)
140
+
141
+ @root.one_off?
141
142
  end
142
143
 
143
144
  def key
@@ -83,7 +83,7 @@ module Eco
83
83
 
84
84
  true
85
85
  rescue StandardError => err
86
- puts err.to_s
86
+ puts err
87
87
  false
88
88
  end
89
89
  end
@@ -3,25 +3,26 @@ module Eco
3
3
  class Session
4
4
  class Config
5
5
  class Files < BaseConfig
6
-
7
6
  def initialize(config:)
8
- super(config: config)
7
+ super
8
+
9
9
  @validations = {}
10
10
  end
11
11
 
12
12
  def working_directory=(path)
13
- self["dir"] = path
13
+ self['dir'] = path
14
14
  end
15
15
 
16
16
  def working_directory
17
- if config.apis.active_api&.one_off?
18
- one_off_dir = File.join("one_off", config.apis.active_name.to_s)
19
- unless full_path = Eco::Data::Files::Directory.new(one_off_dir).create
20
- raise "Could not create the folder '#{full_path}'"
21
- end
22
- self["dir"] = one_off_dir
23
- end
24
- self["dir"]
17
+ return self['dir'] unless config.apis.active_api&.one_off?
18
+
19
+ one_off_dir = File.join('one_off', config.apis.active_name.to_s)
20
+ dir = Eco::Data::Files::Directory.new(one_off_dir)
21
+
22
+ msg = "Could not create the folder '#{dir.full_path}'"
23
+ raise msg unless dir.create
24
+
25
+ self['dir'] = one_off_dir
25
26
  end
26
27
 
27
28
  attr_key :timestamp_pattern
@@ -32,7 +33,7 @@ module Eco
32
33
  end
33
34
 
34
35
  def validate(format, input)
35
- @validations[format].call(input) if @validations.key?(format)
36
+ @validations[format].call(input) if @validations.key?(format)
36
37
  end
37
38
  end
38
39
  end