eco-helpers 2.4.9 → 2.5.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +30 -1
  3. data/eco-helpers.gemspec +1 -1
  4. data/lib/eco/api/common/loaders/case_base.rb +2 -3
  5. data/lib/eco/api/common/loaders/parser.rb +0 -1
  6. data/lib/eco/api/common/people/default_parsers/csv_parser.rb +97 -47
  7. data/lib/eco/api/common/people/default_parsers/select_parser.rb +2 -2
  8. data/lib/eco/api/common/people/default_parsers/xls_parser.rb +0 -1
  9. data/lib/eco/api/common/people/entry_factory.rb +13 -8
  10. data/lib/eco/api/common/people/person_entry_attribute_mapper.rb +2 -2
  11. data/lib/eco/api/common/session/base_session.rb +1 -2
  12. data/lib/eco/api/common/session/environment.rb +6 -10
  13. data/lib/eco/api/common/session/helpers/prompt_user.rb +18 -18
  14. data/lib/eco/api/common/session/mailer.rb +1 -3
  15. data/lib/eco/api/common/session/s3_uploader.rb +1 -3
  16. data/lib/eco/api/common/session/sftp.rb +6 -4
  17. data/lib/eco/api/common/version_patches/ecoportal_api/external_person.rb +5 -4
  18. data/lib/eco/api/session/config/api.rb +4 -2
  19. data/lib/eco/api/session/config/workflow.rb +9 -2
  20. data/lib/eco/api/usecases/base_case.rb +0 -2
  21. data/lib/eco/api/usecases/base_io.rb +0 -3
  22. data/lib/eco/api/usecases/default_cases/samples/sftp_case.rb +1 -1
  23. data/lib/eco/api/usecases/ooze_samples/ooze_from_doc_case.rb +1 -2
  24. data/lib/eco/api/usecases/ooze_samples/ooze_run_base_case.rb +0 -1
  25. data/lib/eco/api/usecases/ooze_samples/ooze_update_case.rb +0 -1
  26. data/lib/eco/api/usecases/ooze_samples/register_export_case.rb +1 -1
  27. data/lib/eco/api/usecases/ooze_samples/register_update_case.rb +0 -2
  28. data/lib/eco/api/usecases/ooze_samples/target_oozes_update_case.rb +0 -1
  29. data/lib/eco/api/usecases/ooze_samples.rb +0 -1
  30. data/lib/eco/api/usecases/use_case.rb +4 -1
  31. data/lib/eco/api/usecases/use_case_chain.rb +1 -4
  32. data/lib/eco/api/usecases/use_case_io.rb +0 -2
  33. data/lib/eco/api.rb +0 -2
  34. data/lib/eco/cli/config/default/options.rb +11 -1
  35. data/lib/eco/cli/config/default/workflow.rb +1 -1
  36. data/lib/eco/csv.rb +4 -7
  37. data/lib/eco/data/files/directory.rb +0 -3
  38. data/lib/eco/data/files/encoding.rb +75 -0
  39. data/lib/eco/data/files/helpers.rb +15 -37
  40. data/lib/eco/data/files.rb +1 -0
  41. data/lib/eco/data/fuzzy_match.rb +8 -4
  42. data/lib/eco/data.rb +0 -1
  43. data/lib/eco/version.rb +1 -1
  44. data/lib/eco-helpers.rb +1 -1
  45. metadata +5 -6
  46. data/lib/eco/data/crypto/encryption.rb +0 -321
  47. data/lib/eco/data/crypto.rb +0 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5f4b841b95f31b7f25c9b5fd33c949bedbc46f2850c0c68b863818f3c75105b1
4
- data.tar.gz: 4ec1d5c2859303fa6943974d19d07c7a4391f4d76fe2a01682510a26e9f92016
3
+ metadata.gz: 140086432682ed765773ca3f1fabcdd46606c04507d6652d94f3df68233cc7ec
4
+ data.tar.gz: fb68c2d6ab307711c45660cf169303b3e79f7555eb5199a6ed33455030def28a
5
5
  SHA512:
6
- metadata.gz: 84a0e4e6191ec10cf37088afce2fff53f9450b4d14f5d8c6206b152d4a0b4758127e5b8df0e3807c99c7dc99263de434fa92787baa778de9322ef56704ea9acd
7
- data.tar.gz: 26b7d8b4e627c8638dd2b392063a25f4f7a633ea13ee3fe6f71bfccff81a3160cee957abc905d1f07e9f6c9e029a507e85b2f256120729fe5096fb2ea83c5018
6
+ metadata.gz: 96ab04ce3bdb34c994becd6a6223cbae38a95aa8bd2309906c047a39a0476b689cf76d7538556c650a826eae5f31cd807c351f0fd6f765cb5efb39857022981f
7
+ data.tar.gz: 0365d9f8777250747eef5580df8531bc07a77dfa7d46c7aaefd29898e44f2450f62fcad8c64f97976d1ae1f7526bfa5e8dcf34eeaa1c4d36777e3e0beff43dff
data/CHANGELOG.md CHANGED
@@ -1,11 +1,40 @@
1
1
  # Change Log
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
- ## [2.4.10] - 2023-04-xx
4
+ ## [2.5.2] - 2023-06-xx
5
5
 
6
6
  ### Added
7
+ - `Eco::API::Session::Config::Workflow#exit_handle`
8
+ - Allows to define a callback on `SystemExit` (`exit` call).
9
+
7
10
  ### Changed
8
11
  ### Fixed
12
+ - `Eco::API::Session::Config::Workflow` on `SystemExit` preserve original exit `status` value (i.e. `0`, `1`)
13
+ - It was changing an `exit 1` to be an `exit 0`
14
+ - Default Workflow. `exit 0` when no operation specified (rather than `exit 1`).
15
+
16
+ ## [2.5.1] - 2023-06-06
17
+
18
+ ### Added
19
+ - `Eco::API::Common::Session:SFTP#host` method
20
+ - New options to control csv headers check (`Eco::API::Common::People::DefaultParsers::CSVParser`)
21
+ - `Eco::API::Common::Loaders::CaseBase` add to the setter the `@usecase`
22
+ - Implemented via `Eco::API::UseCases::UseCase`
23
+
24
+ ### Changed
25
+ - Dry out dependency loading.
26
+ - `ecoportal-api` **gem** remains as eager loading.
27
+ - Patch `Ecoportal::API::V1::Person` with `include`
28
+ - Upgraded `ecoportal-api-graphql` **gem**
29
+ - `Eco::API::Common::People::PersonEntryAttributeMapper`
30
+ - Switched reversed attr defs warning to `info` logging level.
31
+ - `Eco::API::Common::DefaultParsers::SelectParser`
32
+ - When there is dependency with the hash of options, it should return nil when the option is unknown.
33
+
34
+ ### Fixed
35
+ - Tidied up file encoding when getting content.
36
+ - This fixes `Eco::CSV::read`
37
+ - `Eco::API::Common::People::DefaultParsers::CSVParser` made some refactor.
9
38
 
10
39
  ## [2.4.9] - 2023-04-17
11
40
 
data/eco-helpers.gemspec CHANGED
@@ -32,7 +32,7 @@ Gem::Specification.new do |spec|
32
32
 
33
33
  spec.add_dependency 'ecoportal-api', '>= 0.9.4', '< 0.10'
34
34
  spec.add_dependency 'ecoportal-api-v2', '>= 1.1.2', '< 1.2'
35
- spec.add_dependency 'ecoportal-api-graphql', '>= 0.3.6', '< 0.4'
35
+ spec.add_dependency 'ecoportal-api-graphql', '>= 0.3.7', '< 0.4'
36
36
  spec.add_dependency 'aws-sdk-s3', '>= 1.83.0', '< 2'
37
37
  spec.add_dependency 'aws-sdk-ses', '>= 1.36.0', '< 2'
38
38
  spec.add_dependency 'dotenv', '>= 2.7.6', '< 3'
@@ -3,7 +3,6 @@ module Eco
3
3
  module Common
4
4
  module Loaders
5
5
  class CaseBase < Loaders::Base
6
-
7
6
  class << self
8
7
  attr_writer :name, :type
9
8
 
@@ -19,13 +18,13 @@ module Eco
19
18
  def name_only_once!
20
19
  raise "You have already declared #{self} or you are trying to give it a name twice" if @name
21
20
  end
22
-
23
21
  end
24
22
 
23
+ attr_reader :usecase
24
+
25
25
  def name
26
26
  self.class.name
27
27
  end
28
-
29
28
  end
30
29
  end
31
30
  end
@@ -149,7 +149,6 @@ module Eco
149
149
  def _define_serializer(attr_parser)
150
150
  attr_parser.def_serializer(self.class.serializing_phase, &self.method(:serializer))
151
151
  end
152
-
153
152
  end
154
153
  end
155
154
  end
@@ -3,7 +3,8 @@ class Eco::API::Common::People::DefaultParsers::CSVParser < Eco::API::Common::Lo
3
3
 
4
4
  def parser(data, deps)
5
5
  Eco::CSV.parse(data, headers: true, skip_blanks: true).tap do |table|
6
- check_headers(table) if deps[:check_headers] && !options.dig(:input, :skip_header_check)
6
+ require_headers!(table)
7
+ check_headers(table) if deps[:check_headers] && check_headers?
7
8
  end.each_with_object([]) do |row, arr_hash|
8
9
  row_hash = row.headers.uniq.each_with_object({}) do |attr, hash|
9
10
  next if attr.to_s.strip.empty?
@@ -26,6 +27,26 @@ class Eco::API::Common::People::DefaultParsers::CSVParser < Eco::API::Common::Lo
26
27
 
27
28
  private
28
29
 
30
+ def abort(message)
31
+ logger.error(message)
32
+ exit(1)
33
+ end
34
+
35
+ def require_headers!(table)
36
+ headers = table.headers
37
+ abort("Missing headers in CSV") unless headers && !headers.empty?
38
+ empty = []
39
+ with_value = headers.each_with_index do |header, idx|
40
+ empty << idx if header.to_s.strip.empty?
41
+ end
42
+ abort("Empty headers in column(s): #{empty.join(', ')}") unless empty.empty?
43
+ true
44
+ end
45
+
46
+ def check_headers?
47
+ !options.dig(:input, :header_check, :skip)
48
+ end
49
+
29
50
  def options
30
51
  ASSETS.cli.options
31
52
  end
@@ -43,29 +64,54 @@ class Eco::API::Common::People::DefaultParsers::CSVParser < Eco::API::Common::Lo
43
64
  end
44
65
 
45
66
  def check_headers(table)
46
- headers = table.headers
47
- missing = missing_headers(headers)
48
- unknown = unknown_headers(headers)
49
- unless missing.empty? && unknown.empty?
50
- msg = "Detected possible HEADER ISSUES !!!\n"
51
- msg << "There might be Missing or Wrong HEADER names in the CSV file:\n"
52
- msg << " * UNKNOWN (or not used?): #{unknown}\n" unless unknown.empty?
53
- msg << " * MISSING DIRECT: #{missing[:direct]}\n" unless (missing[:direct] || []).empty?
54
- unless (data = missing[:indirect] || []).empty?
55
- msg << " * MISSING INDIRECT:\n"
56
- data.each do |ext, info|
57
- msg << " - '#{ext}' => "
58
- msg << (info[:attrs] || {}).map do |status, attrs|
59
- if status == :inactive
60
- "makes inactive: #{attrs}"
61
- elsif status == :active
62
- "there could be missing info in: #{attrs}"
63
- end
64
- end.compact.join("; ") + "\n"
65
- end
67
+ headers = table.headers
68
+ unmatch = []
69
+ unmatch = unmatched_headers(headers) if options.dig(:input, :header_check, :order)
70
+ missing = missing_headers(headers)
71
+ unknown = unknown_headers(headers)
72
+ criteria = [unknown, missing[:direct], missing[:indirect], unmatch]
73
+ return if criteria.all?(&:empty?)
74
+
75
+ msg = "Detected possible HEADER ISSUES !!!\n"
76
+
77
+ # requires exact match
78
+ unless unmatch.empty?
79
+ msg << "CSV headers do NOT exactly match the expected:\n"
80
+ msg << " * Expected: #{known_headers}\n"
81
+ expected, given = unmatch.first
82
+ msg << " * First unmatch => Given: '#{given}' where expected '#{expected}'\n"
83
+ missed = known_headers - headers
84
+ unless missed.empty?
85
+ msg << " * Missing headers:\n"
86
+ msg << " - #{missed.join("\n - ")}\n"
66
87
  end
67
- logger.warn(msg)
68
- sleep(2)
88
+ end
89
+ msg << "Missing or Wrong HEADER names in the CSV file:\n"
90
+ msg << " * UNKNOWN (or not used?): #{unknown}\n" unless unknown.empty?
91
+ msg << " * MISSING HEADER: #{missing[:direct]}\n" unless missing[:direct].empty?
92
+ unless (data = missing[:indirect]).empty?
93
+ msg << " * MISSING INDIRECTLY:\n"
94
+ data.each do |ext, info|
95
+ msg << " - '#{ext}' => "
96
+ msg << (info[:attrs] || {}).map do |status, attrs|
97
+ if status == :inactive
98
+ "makes inactive: #{attrs}"
99
+ elsif status == :active
100
+ "there could be missing info in: #{attrs}"
101
+ end
102
+ end.compact.join("; ") + "\n"
103
+ end
104
+ end
105
+ logger.warn(msg)
106
+ if options.dig(:input, :header_check, :must_be_valid)
107
+ abort("There were issues identified on the CSV header names. Aborting...")
108
+ end
109
+ sleep(2)
110
+ end
111
+
112
+ def unmatched_headers(headers)
113
+ known_headers.zip(headers).reject do |(expected, given)|
114
+ expected == given
69
115
  end
70
116
  end
71
117
 
@@ -82,27 +128,28 @@ class Eco::API::Common::People::DefaultParsers::CSVParser < Eco::API::Common::Lo
82
128
  ext_present = known_headers_present(int_head) | ext
83
129
  ext_miss = known_headers - ext_present
84
130
 
85
- ext_miss.each_with_object({}) do |ext, missing|
86
- next unless int = fields_mapper.to_internal(ext)
87
- if all_internal_attrs.include?(int)
88
- missing[:direct] ||= []
89
- missing[:direct] << ext
90
- end
91
- related_attrs_requirements = required_attrs.values.select do |req|
92
- dep = req.dependant?(int)
93
- affects = dep && !int_head.include?(int)
94
- in_header = int_head.include?(req.attr)
95
- affects || (dep && !in_header)
96
- end
97
- next if related_attrs_requirements.empty?
98
- missing[:indirect] ||= {}
99
- data = missing[:indirect][ext] = {}
100
- data[:int] = int
101
- data[:attrs] = {}
102
- related_attrs_requirements.each_with_object(data[:attrs]) do |req, attrs|
103
- status = req.active?(*int_head) ? :active : :inactive
104
- attrs[status] ||= []
105
- attrs[status] << req.attr
131
+ {
132
+ direct: [],
133
+ indirect: {}
134
+ }.tap do |missing|
135
+ ext_miss.each do |ext|
136
+ next unless int = fields_mapper.to_internal(ext)
137
+ missing[:direct] << ext if all_internal_attrs.include?(int)
138
+ related_attrs_requirements = required_attrs.values.select do |req|
139
+ dep = req.dependant?(int)
140
+ affects = dep && !int_head.include?(int)
141
+ in_header = int_head.include?(req.attr)
142
+ affects || (dep && !in_header)
143
+ end
144
+ next if related_attrs_requirements.empty?
145
+ data = missing[:indirect][ext] = {}
146
+ data[:int] = int
147
+ data[:attrs] = {}
148
+ related_attrs_requirements.each_with_object(data[:attrs]) do |req, attrs|
149
+ status = req.active?(*int_head) ? :active : :inactive
150
+ attrs[status] ||= []
151
+ attrs[status] << req.attr
152
+ end
106
153
  end
107
154
  end
108
155
  end
@@ -114,8 +161,11 @@ class Eco::API::Common::People::DefaultParsers::CSVParser < Eco::API::Common::Lo
114
161
  end
115
162
  end
116
163
 
164
+ # Scopes what internal attrs appear in headers as they are
117
165
  def internal_present_or_active(headers, inactive_requirements = {})
118
- hint = headers & all_internal_attrs
166
+ # internal attrs that are not being mapped
167
+ int_all = all_internal_attrs.reject {|i| fields_mapper.external?(i)}
168
+ hint = headers & int_all
119
169
  hext = headers - hint
120
170
  int_present = hint + hext.map {|e| fields_mapper.to_internal(e)}.compact
121
171
 
@@ -142,8 +192,9 @@ class Eco::API::Common::People::DefaultParsers::CSVParser < Eco::API::Common::Lo
142
192
  int_present
143
193
  end
144
194
 
195
+ # The csv header names as expected
145
196
  def known_headers
146
- @known_headers ||= fields_mapper.list(:external).compact
197
+ @known_headers ||= fields_mapper.list(:external).compact.uniq
147
198
  end
148
199
 
149
200
  def fields_mapper
@@ -167,5 +218,4 @@ class Eco::API::Common::People::DefaultParsers::CSVParser < Eco::API::Common::Lo
167
218
  def person_parser
168
219
  session.entry_factory.person_parser
169
220
  end
170
-
171
221
  end
@@ -11,9 +11,9 @@ module Eco
11
11
  options_hash = deps[:select_hashes][deps["attr"]]
12
12
  next value if !options_hash
13
13
  if value.is_a?(Array)
14
- value.map { |v| options_hash[v&.downcase.strip] || v }
14
+ value.map { |v| options_hash[v&.downcase.strip] }.compact
15
15
  elsif value
16
- options_hash[value&.downcase.strip] || value
16
+ options_hash[value&.downcase.strip]
17
17
  end
18
18
  end.def_serializer do |value|
19
19
  value
@@ -64,5 +64,4 @@ class Eco::API::Common::People::DefaultParsers::XLSParser < Eco::API::Common::Lo
64
64
  require 'roo-xls'
65
65
  already_required = true
66
66
  end
67
-
68
67
  end
@@ -86,10 +86,10 @@ module Eco
86
86
  # @option options [Boolean] :check_headers signals if the `csv` file headers should be expected.
87
87
  # @return [Eco::API::Common::People::Entries] collection of `Eco::API::Common::People::PersonEntry`.
88
88
  def entries(data: (no_data = true; nil), file: (no_file = true; nil), format: (no_format = true; nil), **options)
89
- fatal("You should at least use data: or file:, but not both") if no_data == no_file
89
+ fatal("You should at least use data: or file:, but not both") if no_data == no_file
90
90
  fatal("You must specify a valid format: (symbol) when you use file.") if file && no_format
91
- fatal("Format should be a Symbol. Given '#{format}'") if format && !format.is_a?(Symbol)
92
- fatal("There is no parser/serializer for format ':#{format.to_s}'") unless no_format || @person_parser.defined?(format)
91
+ fatal("Format should be a Symbol. Given '#{format}'") if format && !format.is_a?(Symbol)
92
+ fatal("There is no parser/serializer for format ':#{format.to_s}'") unless no_format || @person_parser.defined?(format)
93
93
 
94
94
  options.merge!(content: data) unless no_data
95
95
  options.merge!(file: file) unless no_file
@@ -113,9 +113,8 @@ module Eco
113
113
  # Get content only when it's not :xls
114
114
  # note: even if content was provided, file takes precedence
115
115
  if (format != :xls) && file
116
- content = get_file_content(file, encoding)
116
+ content = get_file_content(file, encoding: encoding)
117
117
  end
118
- #content = get_file_content(file, format, encoding) if (format != :xls) && file
119
118
 
120
119
  case content
121
120
  when Hash
@@ -129,15 +128,16 @@ module Eco
129
128
  case sample
130
129
  when Hash, Array, ::CSV::Row
131
130
  Eco::CSV::Table.new(content).to_array_of_hashes
131
+ when NilClass
132
+ abort("There is NO input data")
132
133
  else
133
- logger.error("Input content 'Array' of '#{sample.class}' is not supported.")
134
+ abort("Input content 'Array' of '#{sample.class}' is not supported.")
134
135
  end
135
136
  else
136
137
  if file && format == :xls
137
138
  person_parser.parse(format, file)
138
139
  else
139
- logger.error("Could not obtain any data out of these: #{kargs}. Given content: '#{content.class}'")
140
- exit(1)
140
+ abort("Could not obtain any data out of these: #{kargs}. Given content: '#{content.class}'")
141
141
  end
142
142
  end.tap do |out_array|
143
143
  start_from_two = (format == :csv) || format == :xls
@@ -189,6 +189,11 @@ module Eco
189
189
 
190
190
  private
191
191
 
192
+ def abort(message)
193
+ logger.error(message)
194
+ exit(1)
195
+ end
196
+
192
197
  def fatal(msg)
193
198
  logger.fatal(msg)
194
199
  raise msg
@@ -133,7 +133,7 @@ module Eco
133
133
  attr = @attr_map.to_internal(value.strip)
134
134
  when @attr_map.internal?(value) || @attr_map.internal?(value.strip) || @attr_map.internal?(value.strip.downcase)
135
135
  unless cached_warning("external", "reversed", value)
136
- logger.warn("The mapper [external, internal] attribute names may be declared reversedly for EXTERNAL attribute: '#{value}'")
136
+ logger.info("The mapper [external, internal] attribute names may be declared reversedly for EXTERNAL attribute: '#{value}'")
137
137
  end
138
138
  end
139
139
  end
@@ -172,7 +172,7 @@ module Eco
172
172
  attr = @attr_map.to_external(value.strip)
173
173
  when @attr_map.external?(value) || @attr_map.external?(value.strip) || @attr_map.external?(value.strip.downcase)
174
174
  unless cached_warning("internal", "reversed", value)
175
- logger.warn("The mapper [external, internal] attribute names may be declared reversedly for INTERNAL attribute: '#{value}'")
175
+ logger.info("The mapper [external, internal] attribute names may be declared reversedly for INTERNAL attribute: '#{value}'")
176
176
  end
177
177
  end
178
178
  end
@@ -12,7 +12,7 @@ module Eco
12
12
  alias_method :fm, :file_manager
13
13
 
14
14
  include Session::Helpers
15
-
15
+
16
16
  def initialize(e)
17
17
  raise "Expected object Eco::API::Common::Session::Environment. Given: #{e.class}" unless e.is_a?(Environment)
18
18
  self.environment = e
@@ -72,7 +72,6 @@ module Eco
72
72
  logger.fatal(msg)
73
73
  raise msg
74
74
  end
75
-
76
75
  end
77
76
  end
78
77
  end
@@ -24,9 +24,8 @@ module Eco
24
24
  end
25
25
 
26
26
  def mailer
27
- if mailer?
28
- @mailer ||= Eco::API::Common::Session::Mailer.new(enviro: self)
29
- end
27
+ return nil unless mailer?
28
+ @mailer ||= Eco::API::Common::Session::Mailer.new(enviro: self)
30
29
  end
31
30
 
32
31
  def mailer?
@@ -34,9 +33,8 @@ module Eco
34
33
  end
35
34
 
36
35
  def sftp
37
- if sftp?
38
- @sftp ||= Eco::API::Common::Session::SFTP.new(enviro: self)
39
- end
36
+ return nil unless sftp?
37
+ @sftp ||= Eco::API::Common::Session::SFTP.new(enviro: self)
40
38
  end
41
39
 
42
40
  def sftp?
@@ -44,9 +42,8 @@ module Eco
44
42
  end
45
43
 
46
44
  def s3uploader
47
- if s3uploader?
48
- @s3uploader ||= Eco::API::Common::Session::S3Uploader.new(enviro: self)
49
- end
45
+ return nil unless s3uploader?
46
+ @s3uploader ||= Eco::API::Common::Session::S3Uploader.new(enviro: self)
50
47
  end
51
48
 
52
49
  def s3uploader?
@@ -56,7 +53,6 @@ module Eco
56
53
  def api(version: nil)
57
54
  config.api(logger, version: version)
58
55
  end
59
-
60
56
  end
61
57
  end
62
58
  end
@@ -1,31 +1,31 @@
1
- require 'timeout'
2
1
  module Eco
3
2
  module API
4
3
  module Common
5
4
  module Session
6
5
  module Helpers
7
6
  module PromptUser
8
-
7
+ # Prompts user for input with option for default on timeout.
9
8
  def prompt_user(question, default:, explanation: "", timeout: nil)
10
- response = if config.run_mode_remote?
11
- default
12
- else
13
- puts explanation
14
- print "#{question} "
15
- if timeout
16
- begin
17
- Timeout::timeout(timeout) { STDIN.gets.chop }
18
- rescue Timeout::Error
19
- default
20
- end
21
- else
22
- STDIN.gets.chop
23
- end
24
- end
9
+ require 'timeout'
10
+ response = \
11
+ if config.run_mode_remote?
12
+ default
13
+ else
14
+ puts explanation
15
+ print "#{question} "
16
+ if timeout
17
+ begin
18
+ Timeout::timeout(timeout) { STDIN.gets.chop }
19
+ rescue Timeout::Error
20
+ default
21
+ end
22
+ else
23
+ STDIN.gets.chop
24
+ end
25
+ end
25
26
  return response unless block_given?
26
27
  yield(response)
27
28
  end
28
-
29
29
  end
30
30
  end
31
31
  end
@@ -1,5 +1,3 @@
1
- require 'aws-sdk-ses'
2
-
3
1
  module Eco
4
2
  module API
5
3
  module Common
@@ -42,6 +40,7 @@ module Eco
42
40
  private
43
41
 
44
42
  def ses
43
+ require 'aws-sdk-ses'
45
44
  begin
46
45
  @ses ||= Aws::SES::Client.new(
47
46
  access_key_id: fetch_access_key_id,
@@ -98,7 +97,6 @@ module Eco
98
97
  def fetch_message_id_domain
99
98
  config.mailer.message_id_domain
100
99
  end
101
-
102
100
  end
103
101
  end
104
102
  end
@@ -1,5 +1,3 @@
1
- require 'aws-sdk-s3'
2
-
3
1
  module Eco
4
2
  module API
5
3
  module Common
@@ -75,6 +73,7 @@ module Eco
75
73
  end
76
74
 
77
75
  def bucket
76
+ require 'aws-sdk-s3'
78
77
  begin
79
78
  @bucket ||= Aws::S3::Resource.new(
80
79
  access_key_id: fetch_access_key_id,
@@ -128,7 +127,6 @@ module Eco
128
127
  def fetch_region
129
128
  config.s3storage.region || ENV['AWS_REGION']
130
129
  end
131
-
132
130
  end
133
131
  end
134
132
  end
@@ -1,20 +1,23 @@
1
- require "net/sftp"
2
1
  module Eco
3
2
  module API
4
3
  module Common
5
4
  module Session
6
5
  class SFTP
7
-
8
6
  def initialize (enviro:)
9
7
  raise "Required Environment object (enviro:). Given: #{enviro}" if enviro && !enviro.is_a?(Eco::API::Common::Session::Environment)
10
8
  @enviro = enviro
11
9
  end
12
10
 
11
+ def host
12
+ @host ||= fetch_host
13
+ end
14
+
13
15
  # @see Net::SFTP::Session
14
16
  def sftp_session
17
+ require "net/sftp"
15
18
  begin
16
19
  @sftp_session ||= Net::SFTP.start(
17
- fetch_host,
20
+ host,
18
21
  fetch_user,
19
22
  **session_options
20
23
  )
@@ -135,7 +138,6 @@ module Eco
135
138
  def fetch_base_path
136
139
  config.sftp.base_path || ENV['SFTP_BASE_PATH']
137
140
  end
138
-
139
141
  end
140
142
  end
141
143
  end
@@ -1,8 +1,8 @@
1
- module Ecoportal
1
+ module Eco
2
2
  module API
3
- class V1
4
- # @attr entry [Eco::API::Common::People::PersonEntry, Hash] the input entry plain hash data used to update/create this person.
5
- class Person
3
+ module Common
4
+ module PersonPatch
5
+ # @attr entry [Eco::API::Common::People::PersonEntry, Hash] the input entry plain hash data used to update/create this person.
6
6
  attr_accessor :entry
7
7
 
8
8
  def identify(section = :person)
@@ -14,6 +14,7 @@ module Ecoportal
14
14
  end
15
15
  end
16
16
  end
17
+ Ecoportal::API::V1::Person.include PersonPatch
17
18
  end
18
19
  end
19
20
  end
@@ -24,8 +24,10 @@ module Eco
24
24
  when :v1
25
25
  Ecoportal::API::V1
26
26
  when :v2
27
+ require 'ecoportal/api-v2'
27
28
  Ecoportal::API::V2
28
29
  when :graphql
30
+ require 'ecoportal/api-graphql'
29
31
  Ecoportal::API::GraphQL
30
32
  else
31
33
  end
@@ -45,8 +47,8 @@ module Eco
45
47
  self["mode"] = mode
46
48
  self["user_key"] = user_key
47
49
  self["external_key"] = external_key
48
- self["email"] = email
49
- self["pass"] = pass
50
+ self["email"] = email || ENV['USER_EMAIL']
51
+ self["pass"] = pass || ENV['USER_PASS']
50
52
  self["org_id"] = org_id
51
53
  end
52
54
 
@@ -129,6 +129,12 @@ module Eco
129
129
  self
130
130
  end
131
131
 
132
+ def exit_handle(&block)
133
+ return @exit_handle unless block
134
+ @exit_handle = block
135
+ self
136
+ end
137
+
132
138
  # Used in **configuration** time **add previous** `callbacks` **before** the `on` _callback_ of the (sub)stage `key` is actually `run`
133
139
  # @note
134
140
  # - it will **not** `yield` it immediately, but when the _workflow_ reaches the target stage
@@ -239,8 +245,9 @@ module Eco
239
245
  end
240
246
  end
241
247
  end
242
- rescue SystemExit
243
- exit
248
+ rescue SystemExit => e
249
+ self.exit_handle.call(e, io) if self.exit_handle
250
+ exit e.status
244
251
  rescue Interrupt => i
245
252
  raise
246
253
  rescue Exception => e
@@ -3,7 +3,6 @@ module Eco
3
3
  class UseCases
4
4
  # Core class of UseCases. It basically defines and manages allowed `types`
5
5
  class BaseCase
6
-
7
6
  class InvalidType < StandardError
8
7
  def initialize(msg = nil, type:, types:)
9
8
  msg ||= "Invalid type."
@@ -27,7 +26,6 @@ module Eco
27
26
  raise InvalidType.new(type: type, types: types) unless valid_type?(type)
28
27
  end
29
28
  end
30
-
31
29
  end
32
30
  end
33
31
  end