eco-helpers 1.5.0 → 1.5.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +147 -2
- data/LICENSE +21 -0
- data/eco-helpers.gemspec +11 -10
- data/lib/eco/api.rb +3 -0
- data/lib/eco/api/common.rb +5 -1
- data/lib/eco/api/common/base_loader.rb +54 -0
- data/lib/eco/api/common/class_auto_loader.rb +109 -0
- data/lib/eco/api/common/class_helpers.rb +33 -0
- data/lib/eco/api/common/class_hierarchy.rb +1 -1
- data/lib/eco/api/common/class_meta_basics.rb +16 -0
- data/lib/eco/api/common/loaders.rb +13 -0
- data/lib/eco/api/common/loaders/error_handler.rb +41 -0
- data/lib/eco/api/common/loaders/parser.rb +127 -0
- data/lib/eco/api/common/loaders/policy.rb +25 -0
- data/lib/eco/api/common/loaders/use_case.rb +40 -0
- data/lib/eco/api/common/people/default_parsers.rb +5 -10
- data/lib/eco/api/common/people/default_parsers/boolean_parser.rb +13 -23
- data/lib/eco/api/common/people/default_parsers/csv_parser.rb +20 -35
- data/lib/eco/api/common/people/default_parsers/date_parser.rb +15 -26
- data/lib/eco/api/common/people/default_parsers/freemium_parser.rb +20 -0
- data/lib/eco/api/common/people/default_parsers/login_providers_parser.rb +26 -0
- data/lib/eco/api/common/people/default_parsers/multi_parser.rb +15 -27
- data/lib/eco/api/common/people/default_parsers/numeric_parser.rb +14 -19
- data/lib/eco/api/common/people/default_parsers/policy_groups_parser.rb +31 -0
- data/lib/eco/api/common/people/default_parsers/send_invites_parser.rb +15 -24
- data/lib/eco/api/common/people/entries.rb +54 -24
- data/lib/eco/api/common/people/entry_factory.rb +18 -15
- data/lib/eco/api/common/people/person_attribute_parser.rb +29 -12
- data/lib/eco/api/common/people/person_entry.rb +308 -216
- data/lib/eco/api/common/people/person_entry_attribute_mapper.rb +5 -2
- data/lib/eco/api/common/people/person_parser.rb +52 -19
- data/lib/eco/api/common/session/base_session.rb +3 -6
- data/lib/eco/api/common/session/environment.rb +2 -23
- data/lib/eco/api/common/session/logger.rb +4 -0
- data/lib/eco/api/common/version_patches.rb +1 -0
- data/lib/eco/api/common/version_patches/ecoportal_api/external_person.rb +2 -0
- data/lib/eco/api/common/version_patches/ecoportal_api/internal_person.rb +9 -1
- data/lib/eco/api/common/version_patches/exception.rb +22 -0
- data/lib/eco/api/common/version_patches/object.rb +10 -0
- data/lib/eco/api/custom.rb +13 -0
- data/lib/eco/api/custom/error_handler.rb +20 -0
- data/lib/eco/api/custom/namespace.rb +7 -0
- data/lib/eco/api/custom/parser.rb +50 -0
- data/lib/eco/api/custom/policy.rb +28 -0
- data/lib/eco/api/custom/use_case.rb +16 -0
- data/lib/eco/api/error.rb +1 -0
- data/lib/eco/api/error/handlers.rb +10 -3
- data/lib/eco/api/microcases.rb +35 -0
- data/lib/eco/api/microcases/account_excluded.rb +24 -0
- data/lib/eco/api/microcases/append_usergroups.rb +19 -0
- data/lib/eco/api/microcases/core_excluded.rb +20 -0
- data/lib/eco/api/microcases/fix_default_group.rb +34 -0
- data/lib/eco/api/microcases/fix_filter_tags.rb +42 -0
- data/lib/eco/api/microcases/people_cache.rb +17 -0
- data/lib/eco/api/microcases/people_load.rb +59 -0
- data/lib/eco/api/microcases/people_refresh.rb +31 -0
- data/lib/eco/api/microcases/people_search.rb +65 -0
- data/lib/eco/api/microcases/refresh_abilities.rb +19 -0
- data/lib/eco/api/microcases/refresh_default_tag.rb +27 -0
- data/lib/eco/api/microcases/s3upload_targets.rb +39 -0
- data/lib/eco/api/microcases/set_account.rb +20 -0
- data/lib/eco/api/microcases/set_core.rb +18 -0
- data/lib/eco/api/microcases/set_core_with_supervisor.rb +23 -0
- data/lib/eco/api/microcases/set_supervisor.rb +30 -0
- data/lib/eco/api/microcases/strict_search.rb +19 -0
- data/lib/eco/api/microcases/with_each.rb +27 -0
- data/lib/eco/api/microcases/with_each_leaver.rb +24 -0
- data/lib/eco/api/microcases/with_each_present.rb +30 -0
- data/lib/eco/api/microcases/with_each_starter.rb +30 -0
- data/lib/eco/api/microcases/with_each_subordinate.rb +34 -0
- data/lib/eco/api/microcases/with_supervisor.rb +36 -0
- data/lib/eco/api/organization/people.rb +72 -35
- data/lib/eco/api/organization/presets_factory.rb +13 -4
- data/lib/eco/api/organization/presets_values.json +1 -0
- data/lib/eco/api/policies.rb +11 -7
- data/lib/eco/api/session.rb +62 -29
- data/lib/eco/api/session/batch.rb +2 -45
- data/lib/eco/api/session/batch/base_policy.rb +7 -6
- data/lib/eco/api/session/batch/errors.rb +28 -4
- data/lib/eco/api/session/batch/feedback.rb +7 -1
- data/lib/eco/api/session/batch/job.rb +40 -23
- data/lib/eco/api/session/batch/jobs.rb +9 -4
- data/lib/eco/api/session/batch/jobs_groups.rb +1 -1
- data/lib/eco/api/session/batch/request_stats.rb +95 -58
- data/lib/eco/api/session/batch/status.rb +35 -31
- data/lib/eco/api/session/config.rb +106 -44
- data/lib/eco/api/session/config/api.rb +132 -7
- data/lib/eco/api/session/config/apis.rb +24 -25
- data/lib/eco/api/session/config/logger.rb +2 -2
- data/lib/eco/api/session/config/post_launch.rb +1 -1
- data/lib/eco/api/session/config/workflow.rb +8 -7
- data/lib/eco/api/usecases.rb +47 -33
- data/lib/eco/api/usecases/backup/append_usergroups_case.rb +36 -0
- data/lib/eco/api/usecases/backup/create_case.rb +104 -0
- data/lib/eco/api/usecases/backup/create_details_case.rb +31 -0
- data/lib/eco/api/usecases/backup/create_details_with_supervisor_case.rb +48 -0
- data/lib/eco/api/usecases/backup/hris_case.rb +124 -0
- data/lib/eco/api/usecases/backup/set_default_tag_case.rb +49 -0
- data/lib/eco/api/usecases/backup/set_supervisor_case.rb +41 -0
- data/lib/eco/api/usecases/backup/transfer_account_case.rb +90 -0
- data/lib/eco/api/usecases/backup/update_case.rb +112 -0
- data/lib/eco/api/usecases/backup/update_details_case.rb +64 -0
- data/lib/eco/api/usecases/backup/upsert_case.rb +114 -0
- data/lib/eco/api/usecases/base_case.rb +2 -0
- data/lib/eco/api/usecases/base_io.rb +3 -3
- data/lib/eco/api/usecases/default_cases.rb +23 -53
- data/lib/eco/api/usecases/default_cases/append_usergroups_case.rb +10 -31
- data/lib/eco/api/usecases/default_cases/change_email_case.rb +23 -47
- data/lib/eco/api/usecases/default_cases/codes_to_tags_case.rb +56 -43
- data/lib/eco/api/usecases/default_cases/create_case.rb +15 -101
- data/lib/eco/api/usecases/default_cases/create_details_case.rb +11 -26
- data/lib/eco/api/usecases/default_cases/create_details_with_supervisor_case.rb +12 -43
- data/lib/eco/api/usecases/default_cases/delete_sync_case.rb +11 -0
- data/lib/eco/api/usecases/default_cases/delete_trans_case.rb +14 -0
- data/lib/eco/api/usecases/default_cases/email_as_id_case.rb +10 -21
- data/lib/eco/api/usecases/default_cases/hris_case.rb +23 -120
- data/lib/eco/api/usecases/default_cases/new_email_case.rb +10 -23
- data/lib/eco/api/usecases/default_cases/new_id_case.rb +11 -25
- data/lib/eco/api/usecases/default_cases/new_id_case0.rb +14 -0
- data/lib/eco/api/usecases/default_cases/org_data_convert_case.rb +83 -0
- data/lib/eco/api/usecases/default_cases/refresh_abilities_case.rb +30 -0
- data/lib/eco/api/usecases/default_cases/refresh_case.rb +7 -20
- data/lib/eco/api/usecases/default_cases/reinvite_sync_case.rb +11 -0
- data/lib/eco/api/usecases/default_cases/reinvite_trans_case.rb +17 -0
- data/lib/eco/api/usecases/default_cases/remove_account_sync_case.rb +11 -0
- data/lib/eco/api/usecases/default_cases/remove_account_trans_case.rb +17 -0
- data/lib/eco/api/usecases/default_cases/reset_landing_page_case.rb +9 -19
- data/lib/eco/api/usecases/default_cases/restore_db_case.rb +92 -0
- data/lib/eco/api/usecases/default_cases/set_default_tag_case.rb +32 -40
- data/lib/eco/api/usecases/default_cases/set_supervisor_case.rb +15 -33
- data/lib/eco/api/usecases/default_cases/switch_supervisor_case.rb +66 -57
- data/lib/eco/api/usecases/default_cases/to_csv_case.rb +36 -44
- data/lib/eco/api/usecases/default_cases/to_csv_detailed_case.rb +40 -55
- data/lib/eco/api/usecases/default_cases/transfer_account_case.rb +264 -84
- data/lib/eco/api/usecases/default_cases/update_case.rb +15 -109
- data/lib/eco/api/usecases/default_cases/update_details_case.rb +14 -61
- data/lib/eco/api/usecases/default_cases/upsert_case.rb +16 -111
- data/lib/eco/api/usecases/use_case_io.rb +9 -9
- data/lib/eco/cli/config.rb +10 -2
- data/lib/eco/cli/config/default.rb +2 -1
- data/lib/eco/cli/config/default/input_filters.rb +58 -0
- data/lib/eco/cli/config/default/options.rb +60 -25
- data/lib/eco/cli/config/default/people.rb +4 -4
- data/lib/eco/cli/config/default/people_filters.rb +108 -0
- data/lib/eco/cli/config/default/usecases.rb +69 -32
- data/lib/eco/cli/config/default/workflow.rb +37 -27
- data/lib/eco/cli/config/filters.rb +50 -0
- data/lib/eco/cli/config/filters/input_filters.rb +29 -0
- data/lib/eco/cli/config/filters/people_filters.rb +29 -0
- data/lib/eco/cli/config/help.rb +49 -0
- data/lib/eco/cli/config/options_set.rb +17 -1
- data/lib/eco/cli/config/use_cases.rb +79 -53
- data/lib/eco/cli/scripting.rb +10 -2
- data/lib/eco/cli/scripting/args_helpers.rb +25 -15
- data/lib/eco/cli/scripting/argument.rb +1 -0
- data/lib/eco/cli/scripting/arguments.rb +1 -1
- data/lib/eco/csv/table.rb +1 -1
- data/lib/eco/data/crypto/encryption.rb +3 -0
- data/lib/eco/language/match.rb +19 -9
- data/lib/eco/language/match_modifier.rb +13 -5
- data/lib/eco/language/models/collection.rb +77 -56
- data/lib/eco/language/models/parser_serializer.rb +39 -15
- data/lib/eco/version.rb +1 -1
- metadata +149 -62
- data/lib/eco/api/session/task.rb +0 -175
- data/lib/eco/api/usecases/default_case.rb +0 -19
- data/lib/eco/api/usecases/default_cases/delete_case.rb +0 -32
- data/lib/eco/api/usecases/default_cases/recover_db_case.rb +0 -98
- data/lib/eco/api/usecases/default_cases/refresh_presets_case.rb +0 -26
- data/lib/eco/api/usecases/default_cases/reinvite_case.rb +0 -41
- data/lib/eco/api/usecases/default_cases/remove_account_case.rb +0 -38
- data/lib/eco/cli/config/default/filters.rb +0 -70
- data/lib/eco/cli/config/people_filters.rb +0 -38
@@ -30,7 +30,7 @@ module Eco
|
|
30
30
|
# @param e [Eco::API::Common::Session::Environment] requires a session environment, as any child of `Eco::API::Common::Session::BaseSession`
|
31
31
|
# @param queue [Array<Hash>, Array<Ecoportal::API::V1::Person>, Array<Ecoportal::API::Internal::Person>] the `source_queue`
|
32
32
|
# @param method [Symbol] the type of `batch operation`
|
33
|
-
# @param mode [Symbol] the mode of `batch operation`
|
33
|
+
# @param mode [Symbol] the mode of `batch operation`. It can be `:search` or `:exact`
|
34
34
|
def initialize(e, queue:, method:, mode: :exact)
|
35
35
|
super(e)
|
36
36
|
fatal("In batch operations you must batch an Enumerable. Received: #{queue}") unless queue && queue.is_a?(Enumerable)
|
@@ -96,6 +96,39 @@ module Eco
|
|
96
96
|
@responses[to_index(key)] = response
|
97
97
|
end
|
98
98
|
|
99
|
+
# Has the _entry_ `key` been queried to the server?
|
100
|
+
# @param key [Integer, Hash, Ecoportal::API::V1::Person, Ecoportal::API::Internal::Person]
|
101
|
+
# @return [Boolean] `true` if input entry `key` has an associated `Ecoportal::API::Common::BatchResponse`
|
102
|
+
def received?(key)
|
103
|
+
!!self[key]
|
104
|
+
end
|
105
|
+
|
106
|
+
# Has the _entry_ `key` 's query to the server been successful
|
107
|
+
# @param key [Integer, Hash, Ecoportal::API::V1::Person, Ecoportal::API::Internal::Person]
|
108
|
+
# @return [Boolean] `true` if input entry `key` has not had a server Error during the query
|
109
|
+
def success?(key)
|
110
|
+
self[key]&.success?
|
111
|
+
end
|
112
|
+
|
113
|
+
# Helper to transform any `key` to an `Integer` index
|
114
|
+
# @param key [Integer, Hash, Ecoportal::API::V1::Person, Ecoportal::API::Internal::Person]
|
115
|
+
# @return [Integer] the index that `key` has in the final `queue`
|
116
|
+
def to_index(key)
|
117
|
+
key.is_a?(Integer) ? valid_index(index: key) : valid_index(entry: key)
|
118
|
+
end
|
119
|
+
|
120
|
+
# _Index_ validator to make this object reliable
|
121
|
+
# @return [Integer] the actual `index`
|
122
|
+
def valid_index(index: nil, entry: nil)
|
123
|
+
index ||= @hash[entry]
|
124
|
+
unless index && index < @queue.length
|
125
|
+
fatal "You must provide either the index on the final 'queue' or the original entry object of the batch"
|
126
|
+
end
|
127
|
+
index
|
128
|
+
end
|
129
|
+
|
130
|
+
# @!group Get-specific helpers
|
131
|
+
|
99
132
|
# The _person_ we got from the Server wrapped to the `Person` object for the input entry object `key`
|
100
133
|
# @note it only makes sense when the used batch method was `get`
|
101
134
|
# @param key [Integer, Hash, Ecoportal::API::V1::Person, Ecoportal::API::Internal::Person]
|
@@ -129,20 +162,6 @@ module Eco
|
|
129
162
|
@people_match[to_index(key)] = people
|
130
163
|
end
|
131
164
|
|
132
|
-
# Has the _entry_ `key` been queried to the server?
|
133
|
-
# @param key [Integer, Hash, Ecoportal::API::V1::Person, Ecoportal::API::Internal::Person]
|
134
|
-
# @return [Boolean] `true` if input entry `key` has an associated `Ecoportal::API::Common::BatchResponse`
|
135
|
-
def received?(key)
|
136
|
-
!!self[key]
|
137
|
-
end
|
138
|
-
|
139
|
-
# Has the _entry_ `key` 's query to the server been successful
|
140
|
-
# @param key [Integer, Hash, Ecoportal::API::V1::Person, Ecoportal::API::Internal::Person]
|
141
|
-
# @return [Boolean] `true` if input entry `key` has not had a server Error during the query
|
142
|
-
def success?(key)
|
143
|
-
self[key]&.success?
|
144
|
-
end
|
145
|
-
|
146
165
|
# When the batch _method_ has been `get`, it gathers into an `Array` the people found.
|
147
166
|
# @note here is where the used `mode` gets relevance:
|
148
167
|
# - while `:exact` mode will keep the order of found people as per order of final `queue`
|
@@ -167,22 +186,7 @@ module Eco
|
|
167
186
|
end
|
168
187
|
out
|
169
188
|
end
|
170
|
-
|
171
|
-
# Helper to transform any `key` to an `Integer` index
|
172
|
-
# @param key [Integer, Hash, Ecoportal::API::V1::Person, Ecoportal::API::Internal::Person]
|
173
|
-
# @return [Integer] the index that `key` has in the final `queue`
|
174
|
-
def to_index(key)
|
175
|
-
key.is_a?(Integer) ? valid_index(index: key) : valid_index(entry: key)
|
176
|
-
end
|
177
|
-
|
178
|
-
# _Index_ validator to make this object reliable
|
179
|
-
def valid_index(index: nil, entry: nil)
|
180
|
-
index ||= @hash[entry]
|
181
|
-
unless index && index < @queue.length
|
182
|
-
fatal "You must provide either the index on the final 'queue' or the original entry object of the batch"
|
183
|
-
end
|
184
|
-
index
|
185
|
-
end
|
189
|
+
# @!endgroup
|
186
190
|
|
187
191
|
end
|
188
192
|
end
|
@@ -10,6 +10,8 @@ module Eco
|
|
10
10
|
self["org"] = {}
|
11
11
|
end
|
12
12
|
|
13
|
+
# @!group Config instance pure methods
|
14
|
+
|
13
15
|
def clone(name)
|
14
16
|
keys.each_with_object(self.class.new(name)) do |key, cnf|
|
15
17
|
begin
|
@@ -23,40 +25,36 @@ module Eco
|
|
23
25
|
def reopen
|
24
26
|
yield(self)
|
25
27
|
end
|
28
|
+
# @!endgroup
|
26
29
|
|
27
|
-
|
28
|
-
self["apis"] ||= Eco::API::Session::Config::Apis.new(config: self)
|
29
|
-
end
|
30
|
+
# @!group Additional resources
|
30
31
|
|
32
|
+
# Helper to manage `SFTP` files and folders.
|
33
|
+
# @return [Eco::API::Session::Config::SFTP]
|
31
34
|
def sftp
|
32
35
|
self["sftp"] ||= Eco::API::Session::Config::SFTP.new(config: self)
|
33
36
|
end
|
34
37
|
|
35
|
-
|
36
|
-
|
37
|
-
end
|
38
|
-
|
38
|
+
# Helper to upload files and folders to `S3`.
|
39
|
+
# @return [Eco::API::Session::Config::S3Storage]
|
39
40
|
def s3storage
|
40
41
|
self["s3_storage"] ||= Eco::API::Session::Config::S3Storage.new(config: self)
|
41
42
|
end
|
42
43
|
|
43
|
-
|
44
|
-
|
45
|
-
end
|
46
|
-
|
44
|
+
# Helper to send emails.
|
45
|
+
# @return [Eco::API::Session::Config::Mailer]
|
47
46
|
def mailer
|
48
47
|
self["mailer"] ||= Eco::API::Session::Config::Mailer.new(config: self)
|
49
48
|
end
|
49
|
+
# @!endgroup
|
50
50
|
|
51
|
-
|
52
|
-
self["org"]
|
53
|
-
end
|
51
|
+
# @!group Logger
|
54
52
|
|
55
|
-
|
56
|
-
|
53
|
+
# @return [Eco::API::Session::Config::Logger]
|
54
|
+
def logger
|
55
|
+
self["logger"] ||= Eco::API::Session::Config::Logger.new(config: self)
|
57
56
|
end
|
58
57
|
|
59
|
-
# LOGGER
|
60
58
|
def log_console_level=(value)
|
61
59
|
logger.console_level= value
|
62
60
|
end
|
@@ -76,51 +74,86 @@ module Eco
|
|
76
74
|
def log_connection=(value)
|
77
75
|
logger.log_connection = value
|
78
76
|
end
|
77
|
+
# @!endgroup
|
79
78
|
|
80
|
-
# API
|
81
|
-
def dry_run!
|
82
|
-
self["dry-run"] = true
|
83
|
-
end
|
79
|
+
# @!group Session and API
|
84
80
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
def run_mode=(mode)
|
90
|
-
apis.active_api.mode = mode
|
91
|
-
end
|
92
|
-
|
93
|
-
def run_mode_local?
|
94
|
-
apis.active_api.local?
|
81
|
+
# @return [Eco::API::Session] the `session` linked to this `config`
|
82
|
+
def session
|
83
|
+
@session ||= Eco::API::Session.new(self)
|
95
84
|
end
|
96
85
|
|
97
|
-
|
98
|
-
|
86
|
+
# @return [Eco::API::Session::Config::Apis]
|
87
|
+
def apis
|
88
|
+
self["apis"] ||= Eco::API::Session::Config::Apis.new(config: self)
|
99
89
|
end
|
100
90
|
|
91
|
+
# @return [Boolean] `true` if there is any api configuration defined, `false` otherwise
|
101
92
|
def apis?
|
102
93
|
apis.apis?
|
103
94
|
end
|
104
95
|
|
96
|
+
# @param (see Eco::API::Session::Config::Apis#add)
|
97
|
+
# @return [Eco::API::Session::Config] this configuration
|
105
98
|
def add_api(name, **kargs)
|
106
99
|
apis.add(name, **kargs)
|
107
100
|
self
|
108
101
|
end
|
109
102
|
|
103
|
+
# Set the active api by `name`
|
104
|
+
# @see Eco::API::Session::Config::Apis#active_api=
|
105
|
+
# @return [Eco::API::Session::Config] this configuration
|
110
106
|
def active_api(name)
|
111
107
|
apis.active_name = name
|
112
108
|
self
|
113
109
|
end
|
114
110
|
|
111
|
+
# @see Eco::API::Session::Config::Apis#active_root_name
|
115
112
|
def active_enviro
|
116
113
|
apis.active_root_name
|
117
114
|
end
|
118
115
|
|
119
|
-
|
120
|
-
|
116
|
+
# @see Eco::API::Session::Config::Apis#api
|
117
|
+
def api(logger = ::Logger.new(IO::NULL), version: nil)
|
118
|
+
apis.api(logger, version: version)
|
121
119
|
end
|
122
120
|
|
123
|
-
#
|
121
|
+
# Sets the `mode` of the active api
|
122
|
+
# @see Eco::API::Session::Config::Api#mode
|
123
|
+
# @param (see Eco::API::Session::Config::Api#mode)
|
124
|
+
def run_mode=(mode)
|
125
|
+
apis.active_api.mode = mode
|
126
|
+
end
|
127
|
+
|
128
|
+
def run_mode_local?
|
129
|
+
apis.active_api.local?
|
130
|
+
end
|
131
|
+
|
132
|
+
def run_mode_remote?
|
133
|
+
apis.active_api.remote?
|
134
|
+
end
|
135
|
+
|
136
|
+
# @deprecated old helper to fix the dry-run mode
|
137
|
+
# @note this is now done via `options[:dry_run]`, parsed as an option
|
138
|
+
def dry_run!
|
139
|
+
self["dry-run"] = true
|
140
|
+
end
|
141
|
+
|
142
|
+
# @deprecated old helper to check if we are in dry-run mode
|
143
|
+
# @note this is now done via `options[:dry_run]`, which is parsed as an option
|
144
|
+
def dry_run?
|
145
|
+
self["dry-run"]
|
146
|
+
end
|
147
|
+
# @!endgroup
|
148
|
+
|
149
|
+
# @!group Files
|
150
|
+
|
151
|
+
# @return [Eco::API::Session::Config::Files]
|
152
|
+
def files
|
153
|
+
self["files"] ||= Eco::API::Session::Config::Files.new(config: self)
|
154
|
+
end
|
155
|
+
|
156
|
+
# Defines in the base folder from where files are expected to be found when relative paths are used
|
124
157
|
def working_directory=(path)
|
125
158
|
files.working_directory = path
|
126
159
|
end
|
@@ -158,8 +191,12 @@ module Eco
|
|
158
191
|
require_relative "#{File.expand_path(file_manager.dir.file(file))}"
|
159
192
|
end
|
160
193
|
end
|
194
|
+
# @!endgroup
|
161
195
|
|
162
|
-
#
|
196
|
+
# @!group Organization related shortcuts
|
197
|
+
def org
|
198
|
+
self["org"]
|
199
|
+
end
|
163
200
|
|
164
201
|
def location_codes=(file)
|
165
202
|
org["location_codes"] = file
|
@@ -179,6 +216,7 @@ module Eco
|
|
179
216
|
org["tagtree"] = file
|
180
217
|
end
|
181
218
|
|
219
|
+
# @return [Eco::API::Organization::TagTree]
|
182
220
|
def tagtree(enviro: nil)
|
183
221
|
return @tagtree if instance_variable_defined?(:@tagtree) && @tagtree.enviro == enviro
|
184
222
|
if tree_file = org["tagtree"]
|
@@ -188,68 +226,87 @@ module Eco
|
|
188
226
|
end
|
189
227
|
end
|
190
228
|
|
229
|
+
# @return [Eco::API::Organization::PolicyGroups]
|
191
230
|
def policy_groups
|
192
231
|
return @policy_groups if instance_variable_defined?(:@policy_groups)
|
193
232
|
pgs = api&.policy_groups.to_a
|
194
233
|
@policy_groups = Eco::API::Organization::PolicyGroups.new(pgs)
|
195
234
|
end
|
196
235
|
|
236
|
+
# @return pEco::API::Organization::PersonSchemas
|
197
237
|
def schemas
|
198
238
|
return @schemas if instance_variable_defined?(:@schemas)
|
199
239
|
schs = api&.person_schemas.to_a
|
200
240
|
@schemas = Eco::API::Organization::PersonSchemas.new(schs)
|
201
241
|
end
|
202
242
|
|
243
|
+
# @return [Eco::API::Organization::LoginProviders]
|
203
244
|
def login_providers
|
204
245
|
return @login_providers if instance_variable_defined?(:@login_providers)
|
205
246
|
provs = api&.login_providers.to_a
|
206
247
|
@login_providers = Eco::API::Organization::LoginProviders.new(provs)
|
207
248
|
end
|
208
249
|
|
209
|
-
|
210
|
-
|
250
|
+
# @!endgroup
|
251
|
+
|
252
|
+
# @!group People shortcuts
|
253
|
+
|
254
|
+
# @return [Eco::API::Session::Config::People]
|
255
|
+
def people
|
256
|
+
self["people"] ||= Eco::API::Session::Config::People.new(config: self)
|
211
257
|
end
|
212
258
|
|
213
|
-
#
|
259
|
+
# Define the default usergroup that should be given to people with no usergroups.
|
214
260
|
def default_usergroup=(value)
|
215
261
|
people.default_usergroup = value
|
216
262
|
end
|
217
263
|
|
264
|
+
# Specify the file that holds the `csv` with people to be excluded from `API` updates.
|
218
265
|
def discarded_people_file=(value)
|
219
266
|
people.discarded_file = value
|
220
267
|
end
|
221
268
|
|
269
|
+
# Set the base folder/name.ext name of the fieles where people will be cached.
|
222
270
|
def people_cache=(file)
|
223
271
|
people.cache = file
|
224
272
|
end
|
225
273
|
|
274
|
+
# Set the base folder name where requests launched to the server will be saved for future reference.
|
226
275
|
def requests_backup_folder=(folder)
|
227
276
|
people.requests_folder = folder
|
228
277
|
end
|
229
278
|
|
230
|
-
#
|
279
|
+
# Specify the `.json` file name with the mappings [`DataInputColumnName`, `internal-name`].
|
231
280
|
def person_fields_mapper=(file)
|
232
281
|
people.fields_mapper = file
|
233
282
|
end
|
234
283
|
|
284
|
+
# Set the **default schema** this `api` org configuration should work on.
|
235
285
|
def default_schema=(name)
|
236
286
|
people.default_schema = name
|
237
287
|
end
|
238
288
|
|
239
|
-
#
|
289
|
+
# Specify the file with the account custom abilities presets
|
240
290
|
def presets_custom=(file)
|
241
291
|
people.presets_custom = file
|
242
292
|
end
|
243
293
|
|
294
|
+
# Specify the file with the usergroup to custom presets mapping
|
244
295
|
def presets_map=(file)
|
245
296
|
people.presets_map = file
|
246
297
|
end
|
247
298
|
|
248
|
-
#
|
299
|
+
# @see Eco::API::Session::Config::People
|
300
|
+
# @param (see Eco::API::Session::Config::People)
|
301
|
+
# @return [Eco::API::Common::People::PersonParser] parser/serializer for the defined `format`.
|
249
302
|
def person_parser(format: :csv, &block)
|
250
303
|
people.parser(format: format, &block)
|
251
304
|
end
|
305
|
+
# @!endgroup
|
252
306
|
|
307
|
+
# @!group Session workflow and batch job launces
|
308
|
+
|
309
|
+
# @return [Eco::API::UseCases]
|
253
310
|
def usecases
|
254
311
|
@usecases = self["usecases"] ||= Eco::API::UseCases.new
|
255
312
|
if block_given?
|
@@ -260,10 +317,12 @@ module Eco
|
|
260
317
|
end
|
261
318
|
end
|
262
319
|
|
320
|
+
# @return [Eco::API::Session::Config::PostLaunch]
|
263
321
|
def post_launch
|
264
322
|
self["post_launch"] ||= Eco::API::Session::Config::PostLaunch.new(config: self)
|
265
323
|
end
|
266
324
|
|
325
|
+
# @return [Eco::API::Policies]
|
267
326
|
def policies
|
268
327
|
@policies = self["policies"] ||= Eco::API::Policies.new
|
269
328
|
if block_given?
|
@@ -274,6 +333,7 @@ module Eco
|
|
274
333
|
end
|
275
334
|
end
|
276
335
|
|
336
|
+
# @return [Eco::API::Session::Batch::Policies]
|
277
337
|
def batch_policies
|
278
338
|
@batch_policies = self["batch_policies"] ||= Eco::API::Session::Batch::Policies.new("batch_policy")
|
279
339
|
if block_given?
|
@@ -284,6 +344,7 @@ module Eco
|
|
284
344
|
end
|
285
345
|
end
|
286
346
|
|
347
|
+
# @return [Eco::API::Error::Handlers]
|
287
348
|
def error_handlers
|
288
349
|
@error_handlers = self["error_handlers"] ||= Eco::API::Error::Handlers.new
|
289
350
|
if block_given?
|
@@ -294,13 +355,14 @@ module Eco
|
|
294
355
|
end
|
295
356
|
end
|
296
357
|
|
358
|
+
# @return [Eco::API::Session::Config::Workflow]
|
297
359
|
def workflow
|
298
360
|
@workflow = self["workflow"] ||= Eco::API::Session::Config::Workflow.new(config: self)
|
299
361
|
@workflow.tap do |wf|
|
300
362
|
yield(wf) if block_given?
|
301
363
|
end
|
302
364
|
end
|
303
|
-
|
365
|
+
# @!endgroup
|
304
366
|
|
305
367
|
end
|
306
368
|
end
|
@@ -4,27 +4,111 @@ module Eco
|
|
4
4
|
class Config
|
5
5
|
class Api < Hash
|
6
6
|
|
7
|
-
|
7
|
+
class << self
|
8
|
+
|
9
|
+
def to_version(str)
|
10
|
+
case str.to_sym
|
11
|
+
when :external, :v1
|
12
|
+
:v1
|
13
|
+
when :v2, :oozes
|
14
|
+
:v2
|
15
|
+
else # :internal, :v0
|
16
|
+
:v0
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def api_class(version = :v0)
|
21
|
+
case to_version(version)
|
22
|
+
when :v0
|
23
|
+
Ecoportal::API::Internal
|
24
|
+
when :v1
|
25
|
+
Ecoportal::API::V1
|
26
|
+
when :v2
|
27
|
+
Ecoportal::API::V2
|
28
|
+
else
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
def initialize(name, key:, host:, version:, mode: :local, root:, user_key: nil, external_key: nil)
|
8
35
|
super(nil)
|
9
36
|
@root = root
|
10
|
-
|
11
|
-
self["
|
12
|
-
self["
|
13
|
-
self["
|
37
|
+
@apis = {}
|
38
|
+
self["name"] = name
|
39
|
+
self["key"] = key
|
40
|
+
self["host"] = host
|
41
|
+
self["version"] = version
|
42
|
+
self["mode"] = mode
|
43
|
+
self["user_key"] = user_key
|
44
|
+
self["external_key"] = external_key
|
45
|
+
end
|
46
|
+
|
47
|
+
# @return [Eco::API::Session::Config] the `root` config
|
48
|
+
def config
|
49
|
+
@root.config
|
50
|
+
end
|
51
|
+
|
52
|
+
# Obtain an `API` object of a specific `version`.
|
53
|
+
# @param version [Symbol] any of the available `API` versions [`:v0`, `:v1`, `:v2`].
|
54
|
+
# @param logger [Logger] the logger that will be used with this api instance.
|
55
|
+
# @return [Ecoportal::API::Internal, Ecoportal::API::V2, Ecoportal::API::V1]
|
56
|
+
def api(version: nil, logger: nil)
|
57
|
+
version = version ? version : self.version
|
58
|
+
switch_logger = (logger != @logger)
|
59
|
+
@logger = logger if logger
|
60
|
+
|
61
|
+
if (current = get(version)) && !switch_logger
|
62
|
+
return current
|
63
|
+
end
|
64
|
+
|
65
|
+
unless api_params?(version)
|
66
|
+
raise "The api configuration for '#{name}' is missing data for the api version '#{self.version(version)}'"
|
67
|
+
end
|
68
|
+
|
69
|
+
new_api(version).tap do |pi|
|
70
|
+
set(version, pi)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def set(version, api)
|
75
|
+
@apis[self.version(version)] = api
|
76
|
+
end
|
77
|
+
|
78
|
+
def get(version)
|
79
|
+
@apis[self.version(version)]
|
80
|
+
end
|
81
|
+
|
82
|
+
def name
|
83
|
+
self["name"]
|
14
84
|
end
|
15
85
|
|
16
86
|
def key
|
17
87
|
self["key"]
|
18
88
|
end
|
19
89
|
|
90
|
+
def user_key
|
91
|
+
self["user_key"] || @root.default_user_key
|
92
|
+
end
|
93
|
+
|
94
|
+
def external_key
|
95
|
+
self["external_key"] || ([:v1, :v2].include?(version) && key)
|
96
|
+
end
|
97
|
+
|
98
|
+
def internal_key
|
99
|
+
(version == :v0) && self["key"]
|
100
|
+
end
|
101
|
+
|
20
102
|
def host
|
21
103
|
self["host"]
|
22
104
|
end
|
23
105
|
|
106
|
+
# @param mode [Symbol] to define if running on `:remote` or `:local`
|
24
107
|
def mode=(mode)
|
25
108
|
self["mode"] = (mode == :remote)? :remote : :local
|
26
109
|
end
|
27
110
|
|
111
|
+
# @return [Symbol] if running on `:remote` or `:local`
|
28
112
|
def mode
|
29
113
|
self["mode"]
|
30
114
|
end
|
@@ -37,10 +121,51 @@ module Eco
|
|
37
121
|
!local?
|
38
122
|
end
|
39
123
|
|
40
|
-
def version
|
41
|
-
self["version"]
|
124
|
+
def version(value = nil)
|
125
|
+
self.class.to_version(value || self["version"])
|
42
126
|
end
|
43
127
|
|
128
|
+
# if no low level connection messages: use `IO::NULL`
|
129
|
+
def logger
|
130
|
+
@logger ||= ::Logger.new(IO::NULL)
|
131
|
+
log_connection? ? @logger : ::Logger.new(IO::NULL)
|
132
|
+
end
|
133
|
+
|
134
|
+
private
|
135
|
+
|
136
|
+
# Generates a **new** `API` object of version `version`.
|
137
|
+
def new_api(version)
|
138
|
+
klass = self.class.api_class(version)
|
139
|
+
case self.version(version)
|
140
|
+
when :v0
|
141
|
+
klass.new(internal_key, host: host, logger: logger)
|
142
|
+
when :v1
|
143
|
+
klass.new(external_key, host: host, logger: logger)
|
144
|
+
when :v2
|
145
|
+
klass.new(user_key: user_key, org_key: external_key, logger: logger)
|
146
|
+
end.tap do |api|
|
147
|
+
unless !api || log_connection?
|
148
|
+
@logger.info("Created api#{self.version(version)} connection on '#{name}' enviro, pointing to '#{host}' in '#{mode}' mode")
|
149
|
+
api.logger.level = ::Logger::UNKNOWN
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
# Checks if the necessary parameters for a specific `API` version are available.
|
155
|
+
def api_params?(version)
|
156
|
+
case self.class.to_version(version)
|
157
|
+
when :v0
|
158
|
+
internal_key && host
|
159
|
+
when :v1
|
160
|
+
external_key && host
|
161
|
+
when :v2
|
162
|
+
external_key && user_key
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
def log_connection?
|
167
|
+
config.logger.log_connection?
|
168
|
+
end
|
44
169
|
|
45
170
|
end
|
46
171
|
end
|