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
@@ -1,101 +1,99 @@
1
- module Eco
2
- module API
3
- module Common
4
- module Session
5
- class Logger
6
- class Cache
7
- LEVELS = %w[UNKNOWN FATAL ERROR WARN INFO DEBUG].freeze
8
- CHANNELS = Logger::CHANNELS.map(&:to_s).map(&:upcase).freeze
9
-
10
- def initialize
11
- reset
12
- end
13
-
14
- def level(level)
15
- cache[to_level(level)] ||= []
16
- end
17
-
18
- def add(level, datetime, message, formatted)
19
- Logger::Log.new(level, datetime, message, formatted).tap do |log|
20
- self.level(level).push(log)
21
- end
22
- end
23
-
24
- def cache
25
- @cache ||= {}
26
- end
27
-
28
- def reset(level: nil, start_time: nil, end_time: nil)
29
- where(start_time, end_time) do |cond|
30
- to_levels(level).map do |lev|
31
- self.level(lev).reject(&cond)
32
- end
33
- end
34
- self
35
- end
36
-
37
- def logs(level: nil, start_time: nil, end_time: nil)
38
- where(start_time, end_time) do |cond|
39
- to_levels(level).map do |lev|
40
- self.level(lev).select(&cond)
41
- end.flatten
42
- end.sort
43
- end
44
-
45
- private
46
-
47
- def where(start_time, end_time)
48
- tstart = to_datetime(start_time)
49
- tend = to_datetime(end_time)
50
- condition = proc do |log|
51
- next true unless tstart || tend
52
-
53
- log.after?(tstart) && log.before?(tend)
54
- end
55
-
56
- yield(condition)
57
- end
58
-
59
- def to_datetime(value)
60
- return unless value
61
-
62
- Time.parse(value)
63
- end
64
-
65
- def to_levels(value)
66
- levels = [value].flatten.map {|v| to_level(v)}.compact
67
- return levels unless levels.empty?
68
-
69
- valid_levels
70
- end
71
-
72
- def to_level(value)
73
- nil_or_upcase(value).tap do |out|
74
- valid_level!(out)
75
- end
76
- end
77
-
78
- def valid_level!(str)
79
- return true unless str
80
- return true if valid_levels.any? {|lev| str == lev}
81
-
82
- msg = "Unknown level #{str}. Should be one of #{LEVELS}"
83
- raise ArgumentError, msg
84
- end
85
-
86
- def nil_or_upcase(value)
87
- value = value.to_s.upcase if value
88
- return yield(value) if block_given?
89
-
90
- value
91
- end
92
-
93
- def valid_levels
94
- @valid_levels ||= self.class::LEVELS | self.class::CHANNELS
95
- end
96
- end
1
+ class Eco::API::Common::Session::Logger
2
+ class Cache
3
+ LEVELS = %w[UNKNOWN FATAL ERROR WARN INFO DEBUG].freeze
4
+ CHANNELS = Eco::API::Common::Session::Logger::CHANNELS.
5
+ map(&:to_s).map(&:upcase).freeze
6
+
7
+ def initialize
8
+ reset
9
+ end
10
+
11
+ def level(level)
12
+ cache[to_level(level)] ||= []
13
+ end
14
+
15
+ def add(level, datetime, message, formatted)
16
+ Eco::API::Common::Session::Logger::Log.new(
17
+ level,
18
+ datetime,
19
+ message,
20
+ formatted
21
+ ).tap do |log|
22
+ self.level(level).push(log)
23
+ end
24
+ end
25
+
26
+ def cache
27
+ @cache ||= {}
28
+ end
29
+
30
+ def reset(level: nil, start_time: nil, end_time: nil)
31
+ where(start_time, end_time) do |cond|
32
+ to_levels(level).map do |lev|
33
+ self.level(lev).reject(&cond)
97
34
  end
98
35
  end
36
+ self
37
+ end
38
+
39
+ def logs(level: nil, start_time: nil, end_time: nil)
40
+ where(start_time, end_time) do |cond|
41
+ to_levels(level).map do |lev|
42
+ self.level(lev).select(&cond)
43
+ end.flatten
44
+ end.sort
45
+ end
46
+
47
+ private
48
+
49
+ def where(start_time, end_time)
50
+ tstart = to_datetime(start_time)
51
+ tend = to_datetime(end_time)
52
+ condition = proc do |log|
53
+ next true unless tstart || tend
54
+
55
+ log.after?(tstart) && log.before?(tend)
56
+ end
57
+
58
+ yield(condition)
59
+ end
60
+
61
+ def to_datetime(value)
62
+ return unless value
63
+
64
+ Time.parse(value)
65
+ end
66
+
67
+ def to_levels(value)
68
+ levels = [value].flatten.map {|v| to_level(v)}.compact
69
+ return levels unless levels.empty?
70
+
71
+ valid_levels
72
+ end
73
+
74
+ def to_level(value)
75
+ nil_or_upcase(value).tap do |out|
76
+ valid_level!(out)
77
+ end
78
+ end
79
+
80
+ def valid_level!(str)
81
+ return true unless str
82
+ return true if valid_levels.any? {|lev| str == lev}
83
+
84
+ msg = "Unknown level #{str}. Should be one of #{LEVELS}"
85
+ raise ArgumentError, msg
86
+ end
87
+
88
+ def nil_or_upcase(value)
89
+ value = value.to_s.upcase if value
90
+ return yield(value) if block_given?
91
+
92
+ value
93
+ end
94
+
95
+ def valid_levels
96
+ @valid_levels ||= self.class::LEVELS | self.class::CHANNELS
99
97
  end
100
98
  end
101
99
  end
@@ -1,43 +1,35 @@
1
- module Eco
2
- module API
3
- module Common
4
- module Session
5
- class Logger
6
- module Channels
7
- CHANNELS = %i[general].freeze
1
+ class Eco::API::Common::Session::Logger
2
+ module Channels
3
+ CHANNELS = %i[general].freeze
8
4
 
9
- class << self
10
- def included(base)
11
- super
5
+ class << self
6
+ def included(base)
7
+ super
12
8
 
13
- base.extend ClassMethods
14
- end
15
- end
16
-
17
- module ClassMethods
18
- def channels!(&def_block)
19
- str = 'Block with channel implementation expected. None given.'
20
- raise ArgumentError, str unless block_given?
21
-
22
- channels.each do |channel|
23
- meth = channel.to_s.downcase.to_sym
9
+ base.extend ClassMethods
10
+ end
11
+ end
24
12
 
25
- define_method(meth) do |msg = nil, &block|
26
- # `block` instead of `&block`
27
- instance_exec(meth, msg, block, &def_block)
28
- end
29
- end
30
- end
13
+ module ClassMethods
14
+ def channels!(&def_block)
15
+ str = 'Block with channel implementation expected. None given.'
16
+ raise ArgumentError, str unless block_given?
31
17
 
32
- private
18
+ channels.each do |channel|
19
+ meth = channel.to_s.downcase.to_sym
33
20
 
34
- def channels
35
- self::CHANNELS
36
- end
37
- end
21
+ define_method(meth) do |msg = nil, &block|
22
+ # `block` instead of `&block`
23
+ instance_exec(meth, msg, block, &def_block)
38
24
  end
39
25
  end
40
26
  end
27
+
28
+ private
29
+
30
+ def channels
31
+ self::CHANNELS
32
+ end
41
33
  end
42
34
  end
43
35
  end
@@ -1,49 +1,41 @@
1
- module Eco
2
- module API
3
- module Common
4
- module Session
5
- class Logger
6
- class Log
7
- attr_accessor :level, :datetime, :message, :formatted
8
-
9
- def initialize(level, datetime, message, formatted)
10
- @level = level
11
- @datetime = datetime
12
- @message = message
13
- @formatted = formatted
14
- end
15
-
16
- def to_s
17
- formatted
18
- end
19
-
20
- def <=>(other)
21
- datetime <=> other.datetime
22
- end
23
-
24
- def before?(value)
25
- return true unless value
26
-
27
- datetime <= to_datetime(value)
28
- end
29
-
30
- def after?(value)
31
- return true unless value
32
-
33
- datetime >= to_datetime(value)
34
- end
35
-
36
- private
37
-
38
- def to_datetime(value)
39
- return value if value.is_a?(Time)
40
- return unless value
41
-
42
- Time.parse(value)
43
- end
44
- end
45
- end
46
- end
1
+ class Eco::API::Common::Session::Logger
2
+ class Log
3
+ attr_accessor :level, :datetime, :message, :formatted
4
+
5
+ def initialize(level, datetime, message, formatted)
6
+ @level = level
7
+ @datetime = datetime
8
+ @message = message
9
+ @formatted = formatted
10
+ end
11
+
12
+ def to_s
13
+ formatted
14
+ end
15
+
16
+ def <=>(other)
17
+ datetime <=> other.datetime
18
+ end
19
+
20
+ def before?(value)
21
+ return true unless value
22
+
23
+ datetime <= to_datetime(value)
24
+ end
25
+
26
+ def after?(value)
27
+ return true unless value
28
+
29
+ datetime >= to_datetime(value)
30
+ end
31
+
32
+ private
33
+
34
+ def to_datetime(value)
35
+ return value if value.is_a?(Time)
36
+ return unless value
37
+
38
+ Time.parse(value)
47
39
  end
48
40
  end
49
41
  end
@@ -1,74 +1,70 @@
1
- module Eco
2
- module API
3
- module Common
4
- module Session
5
- class Logger < Eco::Language::BasicLogger
6
- TIMESTAMP_PATTERN = '%Y-%m-%dT%H:%M:%S'.freeze
7
-
8
- require_relative 'logger/channels'
9
- include Channels
10
-
11
- channels! do |channel, message = nil, block|
12
- format_proc(console: true) do |severity, datetime, msg, formatted_msg|
13
- cache.add(severity, datetime, msg, formatted_msg)
14
- end.call(channel, Time.now, 'prog_name', message || block.call)
15
- end
1
+ module Eco::API::Common::Session
2
+ class Logger < Eco::Language::BasicLogger
3
+ TIMESTAMP_PATTERN = '%Y-%m-%dT%H:%M:%S'.freeze
16
4
 
17
- attr_reader :cache
5
+ require_relative 'logger/channels'
6
+ include Channels
18
7
 
19
- def initialize(file_level: ::Logger::DEBUG, log_file: nil, enviro: nil, **kargs)
20
- super(**kargs)
8
+ channels! do |channel, message = nil, block|
9
+ format_proc(console: true) do |severity, datetime, msg, formatted_msg|
10
+ cache.add(severity, datetime, msg, formatted_msg)
11
+ end.call(channel, Time.now, 'prog_name', message || block.call)
12
+ end
21
13
 
22
- msg = "Required Environment object (enviro:). Given: #{enviro.class}"
23
- raise ArgumentError, msg if enviro && !enviro.is_a?(Eco::API::Common::Session::Environment)
14
+ attr_reader :cache
24
15
 
25
- @enviro = enviro
26
- @cache = Logger::Cache.new
16
+ def initialize(file_level: ::Logger::DEBUG, log_file: nil, enviro: nil, **kargs)
17
+ super(**kargs)
27
18
 
28
- if (log_file = fetch_log_file(log_file))
29
- loggers[:file] = ::Logger.new(log_file).tap do |logger|
30
- logger.formatter = format_proc(console: false) do |severity, datetime, msg, formatted_msg|
31
- cache.add(severity, datetime, msg, formatted_msg)
32
- end
19
+ msg = "Required Environment object (enviro:). Given: #{enviro.class}"
20
+ raise ArgumentError, msg if enviro && !enviro.is_a?(Eco::API::Common::Session::Environment)
33
21
 
34
- logger.level = file_level
35
- end
36
- end
22
+ @enviro = enviro
23
+ @cache = Eco::API::Common::Session::Logger::Cache.new
37
24
 
38
- if_config(:timestamp_console) { |value| self.timestamp = value }
39
- if_config(:console_level) { |value| self.level = value }
40
- if_config(:file_level) { |value| self.file_level = value }
25
+ if (log_file = fetch_log_file(log_file))
26
+ loggers[:file] = ::Logger.new(log_file).tap do |logger|
27
+ logger.formatter = format_proc(
28
+ console: false
29
+ ) do |severity, datetime, msg, formatted_msg|
30
+ cache.add(severity, datetime, msg, formatted_msg)
41
31
  end
42
32
 
43
- def file_level=(value)
44
- loggers[:file]&.level = value
45
- end
33
+ logger.level = file_level
34
+ end
35
+ end
46
36
 
47
- private
37
+ if_config(:timestamp_console) { |value| self.timestamp = value }
38
+ if_config(:console_level) { |value| self.level = value }
39
+ if_config(:file_level) { |value| self.file_level = value }
40
+ end
48
41
 
49
- def config(attr)
50
- return unless (cnf = @enviro&.config&.logger)
42
+ def file_level=(value)
43
+ loggers[:file]&.level = value
44
+ end
51
45
 
52
- cnf.send(attr) if cnf.respond_to?(attr)
53
- end
46
+ private
54
47
 
55
- def if_config(attr)
56
- return if (value = config(attr)).nil?
48
+ def config(attr)
49
+ return unless (cnf = @enviro&.config&.logger)
57
50
 
58
- yield(value) if block_given?
59
- value
60
- end
51
+ cnf.send(attr) if cnf.respond_to?(attr)
52
+ end
61
53
 
62
- def fetch_log_file(log_file)
63
- if log_file ||= config(:file)
64
- log_file = @enviro.file_manager.dir.file(log_file) if @enviro
65
- FileManager.create_directory(log_file, includes_file: true)
66
- end
54
+ def if_config(attr)
55
+ return if (value = config(attr)).nil?
67
56
 
68
- log_file
69
- end
70
- end
57
+ yield(value) if block_given?
58
+ value
59
+ end
60
+
61
+ def fetch_log_file(log_file)
62
+ if log_file ||= config(:file)
63
+ log_file = @enviro.file_manager.dir.file(log_file) if @enviro
64
+ FileUtils.mkdir_p(File.dirname(log_file))
71
65
  end
66
+
67
+ log_file
72
68
  end
73
69
  end
74
70
  end
@@ -1,84 +1,77 @@
1
1
  # rubocop:disable Naming/MethodParameterName
2
- module Eco
3
- module API
4
- module Common
5
- module Session
6
- class Mailer
7
- class AwsProvider < ProviderBase
8
- def send_mail(subject:, body:, to: nil, cc: nil, bcc: nil)
9
- ses.send_email(
10
- destination: fetch_destination(to: to, cc: cc, bcc: bcc),
11
- source: fetch_from,
12
- message: {
13
- subject: {
14
- charset: 'UTF-8',
15
- data: subject
16
- },
17
- body: {
18
- # NOTE: (html) will let you send html instead
19
- # you can use both at once if you like
20
- text: {
21
- charset: 'UTF-8',
22
- data: body
23
- }
24
- }
25
- }
26
- )
27
- end
2
+ class Eco::API::Common::Session::Mailer
3
+ class AwsProvider < ProviderBase
4
+ def send_mail(subject:, body:, to: nil, cc: nil, bcc: nil)
5
+ ses.send_email(
6
+ destination: fetch_destination(to: to, cc: cc, bcc: bcc),
7
+ source: fetch_from,
8
+ message: {
9
+ subject: {
10
+ charset: 'UTF-8',
11
+ data: subject
12
+ },
13
+ body: {
14
+ # NOTE: (html) will let you send html instead
15
+ # you can use both at once if you like
16
+ text: {
17
+ charset: 'UTF-8',
18
+ data: body
19
+ }
20
+ }
21
+ }
22
+ )
23
+ end
28
24
 
29
- # @return [Boolean] whether or not the mailer is configured for usage.
30
- def configured?
31
- fetch_access_key_id && fetch_secret_access_key && fetch_region
32
- end
25
+ # @return [Boolean] whether or not the mailer is configured for usage.
26
+ def configured?
27
+ fetch_access_key_id && fetch_secret_access_key && fetch_region
28
+ end
33
29
 
34
- private
30
+ private
35
31
 
36
- def credentials
37
- @credentials ||= {
38
- id: 'AWS_ACCESS_KEY_ID',
39
- key: 'AWS_SECRET_ACCESS_KEY'
40
- }
41
- end
32
+ def credentials
33
+ @credentials ||= super.merge({
34
+ id: 'AWS_ACCESS_KEY_ID',
35
+ key: 'AWS_SECRET_ACCESS_KEY',
36
+ region: 'AWS_REGION'
37
+ })
38
+ end
42
39
 
43
- def ses
44
- require 'aws-sdk-ses'
45
- @ses ||= Aws::SES::Client.new(
46
- access_key_id: fetch_access_key_id,
47
- secret_access_key: fetch_secret_access_key,
48
- region: fetch_region
49
- )
50
- rescue StandardError => err
51
- log(:error) {
52
- "Trying to send an email with wrong email configuration: #{err}"
53
- }
54
- end
40
+ def ses
41
+ require 'aws-sdk-ses'
42
+ @ses ||= Aws::SES::Client.new(
43
+ access_key_id: fetch_access_key_id,
44
+ secret_access_key: fetch_secret_access_key,
45
+ region: fetch_region
46
+ )
47
+ rescue StandardError => err
48
+ log(:error) {
49
+ "Trying to send an email with wrong email configuration: #{err}"
50
+ }
51
+ end
55
52
 
56
- def fetch_destination(to: nil, cc: nil, bcc: nil)
57
- {
58
- to_addresses: [fetch_to(to)].flatten.compact.uniq
59
- }.tap do |dest|
60
- cc = [cc].flatten.compact.uniq
61
- bcc = [bcc].flatten.compact.uniq
53
+ def fetch_destination(to: nil, cc: nil, bcc: nil)
54
+ {
55
+ to_addresses: [fetch_to(to)].flatten.compact.uniq
56
+ }.tap do |dest|
57
+ cc = [cc].flatten.compact.uniq
58
+ bcc = [bcc].flatten.compact.uniq
62
59
 
63
- dest.merge!(cc_addresses: cc) unless cc.empty?
64
- dest.merge!(bcc_addresses: bcc) unless bcc.empty?
65
- end
66
- end
60
+ dest.merge!(cc_addresses: cc) unless cc.empty?
61
+ dest.merge!(bcc_addresses: bcc) unless bcc.empty?
62
+ end
63
+ end
67
64
 
68
- def fetch_region
69
- config.mailer.region || ENV['AWS_REGION']
70
- end
65
+ def fetch_region
66
+ config.mailer.region || env_credential(:region)
67
+ end
71
68
 
72
- def fetch_server
73
- config.mailer.server
74
- end
69
+ def fetch_server
70
+ config.mailer.server
71
+ end
75
72
 
76
- def fetch_message_id_domain
77
- config.mailer.message_id_domain
78
- end
79
- end
80
- end
81
- end
73
+ def fetch_message_id_domain
74
+ config.mailer.message_id_domain
82
75
  end
83
76
  end
84
77
  end