eco-helpers 1.5.10 → 1.5.15
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.yardopts +1 -0
- data/CHANGELOG.md +69 -1
- data/eco-helpers.gemspec +2 -2
- data/lib/eco/api/common/class_helpers.rb +45 -1
- data/lib/eco/api/common/loaders/error_handler.rb +2 -0
- data/lib/eco/api/common/loaders/parser.rb +4 -0
- data/lib/eco/api/common/loaders/use_case.rb +2 -0
- data/lib/eco/api/common/people/default_parsers/csv_parser.rb +15 -2
- data/lib/eco/api/common/people/person_entry.rb +15 -3
- data/lib/eco/api/common/session/logger.rb +9 -1
- data/lib/eco/api/common/session/logger/cache.rb +91 -0
- data/lib/eco/api/common/session/logger/log.rb +48 -0
- data/lib/eco/api/common/version_patches/ecoportal_api/external_person.rb +9 -0
- data/lib/eco/api/microcases/people_cache.rb +7 -0
- data/lib/eco/api/microcases/people_load.rb +29 -21
- data/lib/eco/api/microcases/people_refresh.rb +6 -0
- data/lib/eco/api/microcases/people_search.rb +33 -8
- data/lib/eco/api/microcases/set_core_with_supervisor.rb +5 -3
- data/lib/eco/api/organization/tag_tree.rb +7 -0
- data/lib/eco/api/policies.rb +1 -0
- data/lib/eco/api/policies/default_policies.rb +12 -0
- data/lib/eco/api/policies/default_policies/99_user_access_policy.rb +100 -0
- data/lib/eco/api/session.rb +13 -0
- data/lib/eco/api/session/batch/job.rb +17 -7
- data/lib/eco/api/session/config/api.rb +1 -1
- data/lib/eco/api/usecases.rb +1 -0
- data/lib/eco/api/usecases/ooze_samples.rb +11 -0
- data/lib/eco/api/usecases/ooze_samples/ooze_update_case.rb +85 -0
- data/lib/eco/version.rb +1 -1
- metadata +11 -16
- data/lib/eco/api/usecases/backup/append_usergroups_case.rb +0 -36
- data/lib/eco/api/usecases/backup/create_case.rb +0 -104
- data/lib/eco/api/usecases/backup/create_details_case.rb +0 -31
- data/lib/eco/api/usecases/backup/create_details_with_supervisor_case.rb +0 -48
- data/lib/eco/api/usecases/backup/hris_case.rb +0 -124
- data/lib/eco/api/usecases/backup/set_default_tag_case.rb +0 -49
- data/lib/eco/api/usecases/backup/set_supervisor_case.rb +0 -41
- data/lib/eco/api/usecases/backup/transfer_account_case.rb +0 -90
- data/lib/eco/api/usecases/backup/update_case.rb +0 -112
- data/lib/eco/api/usecases/backup/update_details_case.rb +0 -64
- data/lib/eco/api/usecases/backup/upsert_case.rb +0 -114
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 71bf87e88b7a707a7684879b5462db11da003360d353d513005d169e77eaa033
|
4
|
+
data.tar.gz: 53fe5d42e0be580d0903ddd72e02b014ca113daafe8b37d073481a769deceb7f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 36db363c1aef9dac9f5fe0ca874c5d6e8dd39c89fbc7326fc66975ac12b5282288d6ba6c1449aea457c9831aacfbfe0529a53490389fc72f1f0ede956e35b9eb
|
7
|
+
data.tar.gz: 17ca4ae2ce8acde161e94f203eb643d405d33210972eec1bbbc3598f50f7b7015a94f9a81c50d64bafb0a42c9066464d421f6eb491e15a17c531753aa64ff59c
|
data/.yardopts
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,7 +1,75 @@
|
|
1
1
|
# Change Log
|
2
2
|
All notable changes to this project will be documented in this file.
|
3
3
|
|
4
|
-
## [1.5.
|
4
|
+
## [1.5.15] - 2021-02-xx
|
5
|
+
|
6
|
+
### Added
|
7
|
+
- `Eco::API::Common::ClassHelpers` added support for class methods inheritance
|
8
|
+
- this is key to be able to define usecase models to inherit from
|
9
|
+
- `Eco::API::UseCases::OozeSamples::OozeUpdateCase`: added this sample to inherit from (simplifying use cases code)
|
10
|
+
- `Eco::API::Common::ClassHelpers` added inheritable attribute values
|
11
|
+
- added benchmarking to people loaders:
|
12
|
+
- `Eco::API::MicroCases#people_load`
|
13
|
+
- `Eco::API::MicroCases#people_cache`
|
14
|
+
- `Eco::API::MicroCases#people_search`
|
15
|
+
- `Eco::API::MicroCases#refresh`
|
16
|
+
|
17
|
+
### Changed
|
18
|
+
### Fixed
|
19
|
+
- `Eco::API::Policies::DefaultPolicies::UserAccess` typos in default api policy
|
20
|
+
|
21
|
+
## [1.5.14] - 2021-02-05
|
22
|
+
|
23
|
+
### Added
|
24
|
+
- `Eco::API::Policies::DefaultPolicies` policies that are run always (after the custom policies)
|
25
|
+
- `Eco::API::Policies::DefaultPolicies::UserAccess`:
|
26
|
+
- remove account if there's no `email`
|
27
|
+
- provision min user level to those with account (if no usergroup and no abilities)
|
28
|
+
- `Eco::API::Session#policies` which merges the default policies to be added/run after the custom policies
|
29
|
+
- `Eco::API::Common::Session::Logger`: add caching of logs
|
30
|
+
- `Eco::API::Common::Session::Logger::Cache` new class to manage cached logs
|
31
|
+
- `Eco::API::Common::Session::Logger::Log` new class to have a trace on logs
|
32
|
+
- `Eco::API::Session::Batch::Job#summary` added subjobs (error handlers) summary
|
33
|
+
|
34
|
+
### Changed
|
35
|
+
- `Eco::API::Session::Batch::Job#launch` it will also run the default api policies before feedback and query launch
|
36
|
+
- `Eco::API::Common::People::PersonEntry` add error log when wrong email error is detected
|
37
|
+
- previously it would have crashed
|
38
|
+
|
39
|
+
### Fixed
|
40
|
+
|
41
|
+
## [1.5.13] - 2021-02-01
|
42
|
+
|
43
|
+
### Added
|
44
|
+
### Changed
|
45
|
+
- upgraded dependency with `ecoportal-api-oozes`
|
46
|
+
|
47
|
+
### Fixed
|
48
|
+
- `Eco::API::Session::Config::Api` was not including the correct `host`
|
49
|
+
- this could have launched an `api` request to `live.ecoportal.com` when targeting `pre.dev`
|
50
|
+
|
51
|
+
## [1.5.12] - 2021-02-01
|
52
|
+
|
53
|
+
### Added
|
54
|
+
- `Eco::API::Common::People::DefaultParsers::CSVParser` when cell content is `Null`, capture `nil` value.
|
55
|
+
|
56
|
+
### Changed
|
57
|
+
- upgraded `ecoportal-api` dependency
|
58
|
+
|
59
|
+
### Fixed
|
60
|
+
|
61
|
+
|
62
|
+
## [1.5.11] - 2021-01-25
|
63
|
+
|
64
|
+
### Added
|
65
|
+
- `Eco::API::Organization::TagTree#subtag?` to check if the tag is in any subtree.
|
66
|
+
|
67
|
+
### Changed
|
68
|
+
|
69
|
+
### Fixed
|
70
|
+
- `Eco::API::MicroCases#set_supervisor` shouldn't set it if the entry does not have it.
|
71
|
+
|
72
|
+
## [1.5.10] - 2021-01-19
|
5
73
|
|
6
74
|
### Added
|
7
75
|
### Changed
|
data/eco-helpers.gemspec
CHANGED
@@ -29,8 +29,8 @@ Gem::Specification.new do |s|
|
|
29
29
|
s.add_development_dependency "yard", ">= 0.9.18", "< 0.10"
|
30
30
|
s.add_development_dependency "redcarpet", ">= 3.5.0", "< 3.6"
|
31
31
|
|
32
|
-
s.add_dependency 'ecoportal-api', '>= 0.7.
|
33
|
-
s.add_dependency 'ecoportal-api-oozes', '>= 0.7.
|
32
|
+
s.add_dependency 'ecoportal-api', '>= 0.7.4', '< 0.8'
|
33
|
+
s.add_dependency 'ecoportal-api-oozes', '>= 0.7.3', '< 0.8'
|
34
34
|
s.add_dependency 'aws-sdk-s3', '>= 1.64.0', '< 2'
|
35
35
|
s.add_dependency 'aws-sdk-ses', '>= 1.29.0', '< 2'
|
36
36
|
s.add_dependency 'dotenv', '>= 2.7.0', '< 2.8'
|
@@ -3,7 +3,7 @@ module Eco
|
|
3
3
|
module Common
|
4
4
|
module ClassHelpers
|
5
5
|
|
6
|
-
# Creates
|
6
|
+
# Creates a class and instance object methods with name `name` to resolve `klass` name
|
7
7
|
def class_resolver(name, klass)
|
8
8
|
define_singleton_method(name) { resolve_class(klass) }
|
9
9
|
define_method(name) { self.class.resolve_class(klass) }
|
@@ -39,6 +39,15 @@ module Eco
|
|
39
39
|
end.join("")
|
40
40
|
end
|
41
41
|
|
42
|
+
# Helper to create an instance variable `name`
|
43
|
+
# @param [String, Symbol] the name of the variable
|
44
|
+
# @reutrn [String] the name of the created instance variable
|
45
|
+
def instance_variable_name(name)
|
46
|
+
str = name.to_s
|
47
|
+
str = "@#{str}" unless str.start_with?("@")
|
48
|
+
str
|
49
|
+
end
|
50
|
+
|
42
51
|
# If the class for `name` exists, it returns it. Otherwise it generates it.
|
43
52
|
# @param name [String, Symbol] the name of the new class
|
44
53
|
# @param inherits [Class] the parent class to _inherit_ from
|
@@ -92,6 +101,41 @@ module Eco
|
|
92
101
|
descendants(parent_class: parent_class, direct: direct).length > 0
|
93
102
|
end
|
94
103
|
|
104
|
+
# Keeps track on class instance variables that should be inherited by child classes.
|
105
|
+
# @note
|
106
|
+
# - subclasses will inherit the value as is at that moment
|
107
|
+
# - any change afterwards will be only on the specific class (in line with class instance variables)
|
108
|
+
# - adapted from https://stackoverflow.com/a/10729812/4352306
|
109
|
+
# TODO: this separates the logic of the method to the instance var. Think if would be possible to join them somehow.
|
110
|
+
def inheritable_class_vars(*vars)
|
111
|
+
@inheritable_class_vars ||= [:inheritable_class_vars]
|
112
|
+
@inheritable_class_vars += vars
|
113
|
+
end
|
114
|
+
|
115
|
+
# Builds the attr_reader and attr_writer of `attrs` and registers the associated instance variable as inheritable.
|
116
|
+
def inheritable_attrs(*attrs)
|
117
|
+
attrs.each do |attr|
|
118
|
+
class_eval %(
|
119
|
+
class << self; attr_accessor :#{attr} end
|
120
|
+
)
|
121
|
+
end
|
122
|
+
inheritable_class_vars(*attrs)
|
123
|
+
end
|
124
|
+
|
125
|
+
# This callback method is called whenever a subclass of the current class is created.
|
126
|
+
# @note
|
127
|
+
# - values of the instance variables are copied as they are (no dups or clones)
|
128
|
+
# - the above means: avoid methods that change the state of the mutable object on it
|
129
|
+
# - mutating methods would reflect the changes on other classes as well
|
130
|
+
# - therefore, `freeze` will be called on the values that are inherited.
|
131
|
+
def inherited(subclass)
|
132
|
+
inheritable_class_vars.each do |var|
|
133
|
+
instance_var = instance_variable_name(var)
|
134
|
+
value = instance_variable_get(instance_var)
|
135
|
+
subclass.instance_variable_set(instance_var, value.freeze)
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
95
139
|
end
|
96
140
|
end
|
97
141
|
end
|
@@ -60,6 +60,8 @@ module Eco
|
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
63
|
+
private
|
64
|
+
|
63
65
|
# Helper to obtain the current internal named attributes of the data
|
64
66
|
# @param source_data [Array<String>, Hash] if `Array` those are already the `keys`, if `Hash` it gets the `keys`
|
65
67
|
# @return [Array<String>] `keys` of `source_data`
|
@@ -76,6 +78,8 @@ module Eco
|
|
76
78
|
|
77
79
|
end
|
78
80
|
|
81
|
+
inheritable_class_vars :attribute
|
82
|
+
|
79
83
|
def initialize(person_parser)
|
80
84
|
raise "Expected Eco::API::Common::People::PersonParser. Given #{policies.class}" unless person_parser.is_a?(Eco::API::Common::People::PersonParser)
|
81
85
|
person_parser.define_attribute(self.attribute, dependencies: self.class.dependencies) do |attr_parser|
|
@@ -14,6 +14,8 @@ module Eco
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
+
inheritable_class_vars :type
|
18
|
+
|
17
19
|
def initialize(usecases)
|
18
20
|
raise "Expected Eco::API::UseCases. Given #{usecases.class}" unless usecases.is_a?(Eco::API::UseCases)
|
19
21
|
usecases.define(self.name, type: self.type, &self.method(:main))
|
@@ -5,8 +5,7 @@ class Eco::API::Common::People::DefaultParsers::CSVParser < Eco::API::Common::Lo
|
|
5
5
|
Eco::CSV.parse(data, headers: true, skip_blanks: true).each_with_object([]) do |row, arr_hash|
|
6
6
|
row_hash = row.headers.uniq.each_with_object({}) do |attr, hash|
|
7
7
|
next if attr.to_s.strip.empty?
|
8
|
-
|
9
|
-
hash[attr.strip] = value.to_s.empty?? nil : value
|
8
|
+
hash[attr.strip] = parse_string(row[attr])
|
10
9
|
end
|
11
10
|
arr_hash.push(row_hash)
|
12
11
|
end
|
@@ -23,4 +22,18 @@ class Eco::API::Common::People::DefaultParsers::CSVParser < Eco::API::Common::Lo
|
|
23
22
|
CSV::Table.new(arr_rows).to_csv
|
24
23
|
end
|
25
24
|
|
25
|
+
private
|
26
|
+
|
27
|
+
def parse_string(value)
|
28
|
+
return nil if value.to_s.empty?
|
29
|
+
return nil if null?(value)
|
30
|
+
value
|
31
|
+
end
|
32
|
+
|
33
|
+
def null?(value)
|
34
|
+
return true if !value
|
35
|
+
str = value.strip.upcase
|
36
|
+
["NULL"].any? {|token| str == token}
|
37
|
+
end
|
38
|
+
|
26
39
|
end
|
@@ -170,14 +170,25 @@ module Eco
|
|
170
170
|
end
|
171
171
|
|
172
172
|
# Setter to fill in all the `core` properties of the `Person` that are present in the `Entry`.
|
173
|
-
# @note
|
174
|
-
#
|
173
|
+
# @note
|
174
|
+
# 1. it only sets those core properties defined in the entry.
|
175
|
+
# Meaning that if an core property is not present in the entry, this will not be set on the target person.
|
176
|
+
# 2. if there's an incorrect email exception, it blanks the email and logs a warning message
|
175
177
|
# @param person [Ecoportal::API::V1::Person] the person we want to set the core values to.
|
176
178
|
# @param exclude [String, Array<String>] core attributes that should not be set/changed to the person.
|
177
179
|
def set_core(person, exclude: nil)
|
178
180
|
scoped_attrs = @emap.core_attrs - into_a(exclude)
|
179
181
|
@final_entry.slice(*scoped_attrs).each do |attr, value|
|
180
|
-
|
182
|
+
begin
|
183
|
+
set_part(person, attr, value)
|
184
|
+
rescue Exception => e
|
185
|
+
if attr == "email"
|
186
|
+
logger.error(e.to_s + " - setting blank email instead.")
|
187
|
+
set_part(person, attr, nil)
|
188
|
+
else
|
189
|
+
raise
|
190
|
+
end
|
191
|
+
end
|
181
192
|
end
|
182
193
|
end
|
183
194
|
|
@@ -460,6 +471,7 @@ module Eco
|
|
460
471
|
obj.send("#{attr}=", value)
|
461
472
|
end
|
462
473
|
rescue Exception => e
|
474
|
+
# add more info to the error
|
463
475
|
raise e.append_message " -- Entry #{to_s(:identify)}"
|
464
476
|
end
|
465
477
|
end
|
@@ -5,9 +5,12 @@ module Eco
|
|
5
5
|
class Logger
|
6
6
|
DEFAULT_TIMESTAMP_PATTERN = '%Y-%m-%dT%H:%M:%S'
|
7
7
|
|
8
|
+
attr_reader :cache
|
9
|
+
|
8
10
|
def initialize(console_level: nil, file_level: ::Logger::DEBUG, log_file: nil, timestamp_console: false, enviro: nil)
|
9
11
|
raise "Required Environment object (enviro:). Given: #{enviro}" if enviro && !enviro.is_a?(Eco::API::Common::Session::Environment)
|
10
12
|
@enviro = enviro
|
13
|
+
@cache = Logger::Cache.new
|
11
14
|
|
12
15
|
timestamp_console = fetch_timestamp_console(timestamp_console)
|
13
16
|
@console_logger = ::Logger.new(STDOUT).tap do |_logger|
|
@@ -21,7 +24,9 @@ module Eco
|
|
21
24
|
if log_file = fetch_log_file(log_file)
|
22
25
|
@file_logger = ::Logger.new(log_file).tap do |_logger|
|
23
26
|
_logger.formatter = proc do |severity, datetime, progname, msg|
|
24
|
-
"#{severity.to_s[0]}: #{datetime.strftime(DEFAULT_TIMESTAMP_PATTERN)} > #{msg}\n"
|
27
|
+
"#{severity.to_s[0]}: #{datetime.strftime(DEFAULT_TIMESTAMP_PATTERN)} > #{msg}\n".tap do |formatted|
|
28
|
+
cache.add(severity, datetime, msg, formatted)
|
29
|
+
end
|
25
30
|
end
|
26
31
|
_logger.level = fetch_file_level(file_level)
|
27
32
|
end
|
@@ -107,3 +112,6 @@ module Eco
|
|
107
112
|
end
|
108
113
|
end
|
109
114
|
end
|
115
|
+
|
116
|
+
require_relative "logger/cache"
|
117
|
+
require_relative "logger/log"
|
@@ -0,0 +1,91 @@
|
|
1
|
+
module Eco
|
2
|
+
module API
|
3
|
+
module Common
|
4
|
+
module Session
|
5
|
+
class Logger
|
6
|
+
class Cache
|
7
|
+
LEVELS = ["UNKNOWN", "FATAL", "ERROR", "WARN", "INFO", "DEBUG"]
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
reset
|
11
|
+
end
|
12
|
+
|
13
|
+
def level(level)
|
14
|
+
cache[to_level(level)] ||= []
|
15
|
+
end
|
16
|
+
|
17
|
+
def add(level, datetime, message, formatted)
|
18
|
+
Logger::Log.new(level, datetime, message, formatted).tap do |log|
|
19
|
+
self.level(level).push(log)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def cache
|
24
|
+
@cache ||= {}
|
25
|
+
end
|
26
|
+
|
27
|
+
def reset(level: nil, start_time: nil, end_time: nil)
|
28
|
+
where(start_time, end_time) do |cond|
|
29
|
+
to_levels(level).map do |lev|
|
30
|
+
self.level(lev).reject(&cond)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
self
|
34
|
+
end
|
35
|
+
|
36
|
+
def logs(level: nil, start_time: nil, end_time: nil)
|
37
|
+
where(start_time, end_time) do |cond|
|
38
|
+
to_levels(level).map do |lev|
|
39
|
+
self.level(lev).select(&cond)
|
40
|
+
end.flatten
|
41
|
+
end.sort
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def where(start_time, end_time)
|
47
|
+
tstart = to_datetime(start_time)
|
48
|
+
tend = to_datetime(end_time)
|
49
|
+
condition = Proc.new do |log|
|
50
|
+
next true unless tstart || tend
|
51
|
+
log.after?(tstart) && log.before?(tend)
|
52
|
+
end
|
53
|
+
|
54
|
+
yield(condition)
|
55
|
+
end
|
56
|
+
|
57
|
+
def to_datetime(value)
|
58
|
+
return nil unless value
|
59
|
+
Time.parse(value)
|
60
|
+
end
|
61
|
+
|
62
|
+
def to_levels(value)
|
63
|
+
levels = [value].flatten.map {|v| to_level(v)}.compact
|
64
|
+
levels = levels.empty?? LEVELS : levels
|
65
|
+
end
|
66
|
+
|
67
|
+
def to_level(value)
|
68
|
+
nil_or_upcase(value).tap do |out|
|
69
|
+
valid_level!(out)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def valid_level!(str)
|
74
|
+
return true if !str
|
75
|
+
unless LEVELS.any? {|lev| str == lev}
|
76
|
+
raise "Unknown level #{str}. Should be one of #{LEVELS}"
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def nil_or_upcase(value)
|
81
|
+
value = value.to_s.upcase if value
|
82
|
+
return yield(value) if block_given?
|
83
|
+
value
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module Eco
|
2
|
+
module API
|
3
|
+
module Common
|
4
|
+
module Session
|
5
|
+
class Logger
|
6
|
+
class Log
|
7
|
+
|
8
|
+
attr_accessor :level, :datetime, :message, :formatted
|
9
|
+
|
10
|
+
def initialize(level, datetime, message, formatted)
|
11
|
+
@level = level
|
12
|
+
@datetime = datetime
|
13
|
+
@message = message
|
14
|
+
@formatted = formatted
|
15
|
+
end
|
16
|
+
|
17
|
+
def to_s
|
18
|
+
self.formatted
|
19
|
+
end
|
20
|
+
|
21
|
+
def <=>(other)
|
22
|
+
self.datetime <=> other.datetime
|
23
|
+
end
|
24
|
+
|
25
|
+
def before?(value)
|
26
|
+
return true if !value
|
27
|
+
datetime <= to_datetime(value)
|
28
|
+
end
|
29
|
+
|
30
|
+
def after?(value)
|
31
|
+
return true if !value
|
32
|
+
datetime >= to_datetime(value)
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def to_datetime(value)
|
38
|
+
return value if value.is_a?(Time)
|
39
|
+
return nil unless value
|
40
|
+
Time.parse(value)
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|