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.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -0
- data/CHANGELOG.md +132 -1
- data/lib/eco/api/common/loaders/base.rb +2 -2
- data/lib/eco/api/common/loaders/case_base.rb +2 -0
- data/lib/eco/api/common/loaders/config/block.rb +78 -0
- data/lib/eco/api/common/loaders/config/workflow/mailer.rb +49 -6
- data/lib/eco/api/common/loaders/config.rb +3 -26
- data/lib/eco/api/common/loaders/error_handler.rb +2 -0
- data/lib/eco/api/common/loaders/parser.rb +1 -4
- data/lib/eco/api/common/people/entries.rb +23 -6
- data/lib/eco/api/common/people/entry_factory.rb +1 -1
- data/lib/eco/api/common/people/person_entry.rb +104 -27
- data/lib/eco/api/common/people/person_parser.rb +50 -16
- data/lib/eco/api/common/people/supervisor_helpers.rb +12 -6
- data/lib/eco/api/common/session/base_session.rb +75 -81
- data/lib/eco/api/common/session/environment.rb +70 -70
- data/lib/eco/api/common/session/file_manager.rb +132 -135
- data/lib/eco/api/common/session/helpers/prompt_user.rb +23 -30
- data/lib/eco/api/common/session/helpers.rb +10 -15
- data/lib/eco/api/common/session/logger/cache.rb +94 -96
- data/lib/eco/api/common/session/logger/channels.rb +24 -32
- data/lib/eco/api/common/session/logger/log.rb +38 -46
- data/lib/eco/api/common/session/logger.rb +50 -54
- data/lib/eco/api/common/session/mailer/aws_provider.rb +64 -71
- data/lib/eco/api/common/session/mailer/provider_base.rb +43 -48
- data/lib/eco/api/common/session/mailer/sendgrid_provider.rb +101 -109
- data/lib/eco/api/common/session/mailer.rb +78 -83
- data/lib/eco/api/common/session/s3_uploader.rb +132 -138
- data/lib/eco/api/common/session/sftp.rb +202 -208
- data/lib/eco/api/common.rb +0 -3
- data/lib/eco/api/custom/mailer.rb +4 -2
- data/lib/eco/api/error/handlers.rb +1 -1
- data/lib/eco/api/microcases/people/apply_changes/set_core/core_excluded.rb +8 -2
- data/lib/eco/api/microcases/people/manage/search.rb +2 -2
- data/lib/eco/api/organization/people/similarity.rb +3 -3
- data/lib/eco/api/organization/people.rb +2 -2
- data/lib/eco/api/session/batch/base_policy.rb +42 -27
- data/lib/eco/api/session/batch/launcher/mode_size.rb +6 -1
- data/lib/eco/api/session/batch/launcher.rb +16 -3
- data/lib/eco/api/session/config/api.rb +4 -3
- data/lib/eco/api/session/config/apis/one_off.rb +1 -1
- data/lib/eco/api/session/config/files.rb +13 -12
- data/lib/eco/api/session/config/workflow.rb +1 -373
- data/lib/eco/api/session/config.rb +45 -10
- data/lib/eco/api/session.rb +7 -9
- data/lib/eco/api/usecases/base_case/model.rb +6 -6
- data/lib/eco/api/usecases/base_case.rb +1 -1
- data/lib/eco/api/usecases/cli.rb +1 -1
- data/lib/eco/api/usecases/default/locations/tagtree_extract_case.rb +22 -13
- data/lib/eco/api/usecases/default_cases/to_csv_case.rb +4 -1
- data/lib/eco/api/usecases/graphql/helpers/location/tags_remap.rb +6 -3
- data/lib/eco/api/usecases/graphql/samples/location/command/dsl.rb +2 -2
- data/lib/eco/api/usecases/lib/base/env.rb +21 -23
- data/lib/eco/api/usecases/lib/files/file_pattern.rb +41 -14
- data/lib/eco/api/usecases/lib/files/input_file.rb +110 -0
- data/lib/eco/api/usecases/lib/files/sftp.rb +5 -2
- data/lib/eco/api/usecases/lib/files.rb +1 -0
- data/lib/eco/api/usecases/lib/locations/base.rb +23 -0
- data/lib/eco/api/usecases/lib/locations/mapping.rb +94 -0
- data/lib/eco/api/usecases/lib/locations.rb +7 -0
- data/lib/eco/api/usecases/lib/people/base.rb +20 -0
- data/lib/eco/api/usecases/lib/people.rb +6 -0
- data/lib/eco/api/usecases/lib.rb +2 -0
- data/lib/eco/api/usecases/ooze_cases.rb +1 -1
- data/lib/eco/api/usecases/ooze_samples/ooze_base_case.rb +1 -1
- data/lib/eco/api/usecases/ooze_samples/ooze_from_doc_case.rb +3 -3
- data/lib/eco/api/usecases/ooze_samples/ooze_run_base_case.rb +4 -1
- data/lib/eco/api/usecases/ooze_samples/ooze_update_case.rb +1 -1
- data/lib/eco/api/usecases/ooze_samples/register_export_case.rb +6 -2
- data/lib/eco/api/usecases/ooze_samples/register_migration_case.rb +7 -6
- data/lib/eco/api/usecases/ooze_samples/register_update_case.rb +14 -4
- data/lib/eco/api/usecases/ooze_samples/target_oozes_update_case.rb +11 -8
- data/lib/eco/api/usecases/samples/drivers/sftp_sample.rb +2 -0
- data/lib/eco/api/usecases/samples/drivers/url_pull_sample.rb +8 -2
- data/lib/eco/api/usecases/service/sftp/with_target_config.rb +0 -33
- data/lib/eco/api/usecases/service/sftp.rb +7 -1
- data/lib/eco/api/usecases/use_case.rb +3 -2
- data/lib/eco/api/usecases/workflow.rb +5 -0
- data/lib/eco/api/usecases.rb +12 -5
- data/lib/eco/cli/scripting/args_helpers.rb +1 -9
- data/lib/eco/cli_default/options.rb +98 -68
- data/lib/eco/cli_default/workflow/end.rb +22 -0
- data/lib/eco/cli_default/workflow/launch_jobs.rb +14 -0
- data/lib/eco/cli_default/workflow/load/data.rb +27 -0
- data/lib/eco/cli_default/workflow/load/input.rb +28 -0
- data/lib/eco/cli_default/workflow/load.rb +13 -0
- data/lib/eco/cli_default/workflow/options.rb +18 -0
- data/lib/eco/cli_default/workflow/post_launch.rb +65 -0
- data/lib/eco/cli_default/workflow/report.rb +17 -0
- data/lib/eco/cli_default/workflow/rescued_exception.rb +21 -0
- data/lib/eco/cli_default/workflow/usecases.rb +23 -0
- data/lib/eco/cli_default/workflow.rb +24 -180
- data/lib/eco/data/count_trace.rb +51 -0
- data/lib/eco/data/files/content.rb +39 -0
- data/lib/eco/data/files/directory.rb +78 -45
- data/lib/eco/data/files/encoding.rb +12 -21
- data/lib/eco/data/files/file_pattern.rb +15 -8
- data/lib/eco/data/files/folder.rb +196 -0
- data/lib/eco/data/files/relative_path.rb +54 -0
- data/lib/eco/data/files/timestamp.rb +18 -0
- data/lib/eco/data/files.rb +46 -5
- data/lib/eco/data/fuzzy_match.rb +1 -1
- data/lib/eco/data/hashes/array_diff.rb +11 -5
- data/lib/eco/data/hashes/diff_result/meta.rb +12 -4
- data/lib/eco/data/locations/node_diff/accessors.rb +1 -1
- data/lib/eco/data/mapper.rb +8 -1
- data/lib/eco/data.rb +1 -0
- data/lib/eco/language/auxiliar_logger.rb +6 -11
- data/lib/eco/language/delegation/delegating_missing.rb +1 -1
- data/lib/eco/language/delegation/delegating_missing_const.rb +1 -1
- data/lib/eco/language/delegation/delegating_missing_on_class.rb +1 -1
- data/lib/eco/language/delegation/for_delegator/delegated_class.rb +1 -1
- data/lib/eco/language/klass/auto_loader.rb +129 -0
- data/lib/eco/language/klass/builder.rb +6 -6
- data/lib/eco/language/klass/const.rb +19 -0
- data/lib/eco/language/klass/helpers_built.rb +3 -1
- data/lib/eco/language/klass/hierarchy.rb +5 -1
- data/lib/eco/language/klass/naming.rb +5 -2
- data/lib/eco/language/klass/resolver.rb +21 -6
- data/lib/eco/language/klass/uid.rb +12 -0
- data/lib/eco/language/klass/when_inherited.rb +30 -6
- data/lib/eco/language/klass.rb +5 -2
- data/lib/eco/language/methods/access_modifier.rb +23 -0
- data/lib/eco/language/methods/instance_method_helpers.rb +6 -1
- data/lib/eco/language/methods.rb +1 -0
- data/lib/eco/language/models/hierarchy.rb +41 -0
- data/lib/eco/language/models/workflow.rb +385 -0
- data/lib/eco/language/models.rb +2 -1
- data/lib/eco/version.rb +1 -1
- metadata +31 -7
- data/lib/eco/api/common/class_auto_loader.rb +0 -114
- data/lib/eco/api/common/class_helpers.rb +0 -9
- data/lib/eco/api/common/class_hierarchy.rb +0 -45
- data/lib/eco/data/files/helpers.rb +0 -152
- data/lib/eco/language/models/class_helpers.rb +0 -136
@@ -1,101 +1,99 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
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
|
-
|
2
|
-
module
|
3
|
-
|
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
|
-
|
10
|
-
|
11
|
-
|
5
|
+
class << self
|
6
|
+
def included(base)
|
7
|
+
super
|
12
8
|
|
13
|
-
|
14
|
-
|
15
|
-
|
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
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
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
|
-
|
18
|
+
channels.each do |channel|
|
19
|
+
meth = channel.to_s.downcase.to_sym
|
33
20
|
|
34
|
-
|
35
|
-
|
36
|
-
|
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
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
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
|
-
|
3
|
-
|
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
|
-
|
5
|
+
require_relative 'logger/channels'
|
6
|
+
include Channels
|
18
7
|
|
19
|
-
|
20
|
-
|
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
|
-
|
23
|
-
raise ArgumentError, msg if enviro && !enviro.is_a?(Eco::API::Common::Session::Environment)
|
14
|
+
attr_reader :cache
|
24
15
|
|
25
|
-
|
26
|
-
|
16
|
+
def initialize(file_level: ::Logger::DEBUG, log_file: nil, enviro: nil, **kargs)
|
17
|
+
super(**kargs)
|
27
18
|
|
28
|
-
|
29
|
-
|
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
|
-
|
35
|
-
|
36
|
-
end
|
22
|
+
@enviro = enviro
|
23
|
+
@cache = Eco::API::Common::Session::Logger::Cache.new
|
37
24
|
|
38
|
-
|
39
|
-
|
40
|
-
|
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
|
-
|
44
|
-
|
45
|
-
|
33
|
+
logger.level = file_level
|
34
|
+
end
|
35
|
+
end
|
46
36
|
|
47
|
-
|
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
|
-
|
50
|
-
|
42
|
+
def file_level=(value)
|
43
|
+
loggers[:file]&.level = value
|
44
|
+
end
|
51
45
|
|
52
|
-
|
53
|
-
end
|
46
|
+
private
|
54
47
|
|
55
|
-
|
56
|
-
|
48
|
+
def config(attr)
|
49
|
+
return unless (cnf = @enviro&.config&.logger)
|
57
50
|
|
58
|
-
|
59
|
-
|
60
|
-
end
|
51
|
+
cnf.send(attr) if cnf.respond_to?(attr)
|
52
|
+
end
|
61
53
|
|
62
|
-
|
63
|
-
|
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
|
-
|
69
|
-
|
70
|
-
|
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
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
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
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
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
|
-
|
30
|
+
private
|
35
31
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
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
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
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
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
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
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
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
|
-
|
69
|
-
|
70
|
-
|
65
|
+
def fetch_region
|
66
|
+
config.mailer.region || env_credential(:region)
|
67
|
+
end
|
71
68
|
|
72
|
-
|
73
|
-
|
74
|
-
|
69
|
+
def fetch_server
|
70
|
+
config.mailer.server
|
71
|
+
end
|
75
72
|
|
76
|
-
|
77
|
-
|
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
|