eco-helpers 2.0.15 → 2.0.21
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +109 -3
- data/eco-helpers.gemspec +11 -5
- data/lib/eco-helpers.rb +2 -0
- data/lib/eco/api/common/base_loader.rb +14 -0
- data/lib/eco/api/common/loaders/parser.rb +1 -0
- data/lib/eco/api/common/people/default_parsers/date_parser.rb +11 -1
- data/lib/eco/api/common/people/default_parsers/login_providers_parser.rb +1 -1
- data/lib/eco/api/common/people/default_parsers/policy_groups_parser.rb +11 -11
- data/lib/eco/api/common/people/entries.rb +1 -0
- data/lib/eco/api/common/people/entry_factory.rb +74 -23
- data/lib/eco/api/common/people/person_entry.rb +5 -2
- data/lib/eco/api/common/people/supervisor_helpers.rb +27 -0
- data/lib/eco/api/common/session.rb +1 -0
- data/lib/eco/api/common/session/base_session.rb +2 -0
- data/lib/eco/api/common/session/file_manager.rb +2 -2
- data/lib/eco/api/common/session/helpers.rb +30 -0
- data/lib/eco/api/common/session/helpers/prompt_user.rb +34 -0
- data/lib/eco/api/common/session/mailer.rb +0 -1
- data/lib/eco/api/common/session/s3_uploader.rb +0 -1
- data/lib/eco/api/common/session/sftp.rb +0 -1
- data/lib/eco/api/common/version_patches/ecoportal_api/external_person.rb +1 -1
- data/lib/eco/api/common/version_patches/ecoportal_api/internal_person.rb +7 -4
- data/lib/eco/api/common/version_patches/exception.rb +11 -4
- data/lib/eco/api/microcases.rb +3 -1
- data/lib/eco/api/microcases/append_usergroups.rb +0 -1
- data/lib/eco/api/microcases/people_cache.rb +2 -2
- data/lib/eco/api/microcases/people_load.rb +2 -2
- data/lib/eco/api/microcases/people_refresh.rb +2 -2
- data/lib/eco/api/microcases/people_search.rb +6 -6
- data/lib/eco/api/microcases/preserve_default_tag.rb +23 -0
- data/lib/eco/api/microcases/preserve_filter_tags.rb +28 -0
- data/lib/eco/api/microcases/preserve_policy_groups.rb +30 -0
- data/lib/eco/api/microcases/set_account.rb +0 -1
- data/lib/eco/api/microcases/with_each.rb +67 -6
- data/lib/eco/api/microcases/with_each_present.rb +4 -2
- data/lib/eco/api/microcases/with_each_starter.rb +4 -2
- data/lib/eco/api/organization.rb +1 -0
- data/lib/eco/api/organization/people.rb +98 -22
- data/lib/eco/api/organization/people_similarity.rb +272 -0
- data/lib/eco/api/organization/person_schemas.rb +5 -1
- data/lib/eco/api/organization/policy_groups.rb +5 -1
- data/lib/eco/api/organization/presets_factory.rb +40 -80
- data/lib/eco/api/organization/presets_integrity.json +6 -0
- data/lib/eco/api/organization/presets_values.json +5 -4
- data/lib/eco/api/organization/tag_tree.rb +33 -0
- data/lib/eco/api/policies/default_policies/99_user_access_policy.rb +0 -30
- data/lib/eco/api/session.rb +10 -24
- data/lib/eco/api/session/batch.rb +25 -7
- data/lib/eco/api/session/config.rb +16 -15
- data/lib/eco/api/session/config/api.rb +4 -0
- data/lib/eco/api/session/config/apis.rb +80 -0
- data/lib/eco/api/session/config/files.rb +7 -0
- data/lib/eco/api/session/config/people.rb +3 -19
- data/lib/eco/api/usecases/default_cases.rb +4 -1
- data/lib/eco/api/usecases/default_cases/abstract_policygroup_abilities_case.rb +161 -0
- data/lib/eco/api/usecases/default_cases/analyse_people_case.rb +223 -0
- data/lib/eco/api/usecases/default_cases/clean_unknown_tags_case.rb +37 -0
- data/lib/eco/api/usecases/default_cases/codes_to_tags_case.rb +2 -3
- data/lib/eco/api/usecases/default_cases/reset_landing_page_case.rb +11 -1
- data/lib/eco/api/usecases/default_cases/restore_db_case.rb +1 -2
- data/lib/eco/api/usecases/default_cases/supers_cyclic_identify_case.rb +72 -0
- data/lib/eco/api/usecases/default_cases/supers_hierarchy_case.rb +1 -1
- data/lib/eco/api/usecases/default_cases/to_csv_case.rb +132 -29
- data/lib/eco/api/usecases/default_cases/to_csv_detailed_case.rb +61 -36
- data/lib/eco/api/usecases/ooze_samples/ooze_update_case.rb +3 -2
- data/lib/eco/cli.rb +0 -10
- data/lib/eco/cli/config/default/options.rb +48 -17
- data/lib/eco/cli/config/default/people.rb +18 -24
- data/lib/eco/cli/config/default/people_filters.rb +3 -3
- data/lib/eco/cli/config/default/usecases.rb +105 -28
- data/lib/eco/cli/config/default/workflow.rb +21 -12
- data/lib/eco/cli/config/help.rb +1 -0
- data/lib/eco/cli/config/options_set.rb +106 -13
- data/lib/eco/cli/config/use_cases.rb +33 -33
- data/lib/eco/cli/scripting/args_helpers.rb +30 -3
- data/lib/eco/csv.rb +4 -2
- data/lib/eco/csv/table.rb +121 -21
- data/lib/eco/data.rb +1 -0
- data/lib/eco/data/crypto/encryption.rb +3 -3
- data/lib/eco/data/files/directory.rb +28 -20
- data/lib/eco/data/files/helpers.rb +6 -4
- data/lib/eco/data/fuzzy_match.rb +201 -0
- data/lib/eco/data/fuzzy_match/array_helpers.rb +75 -0
- data/lib/eco/data/fuzzy_match/chars_position_score.rb +38 -0
- data/lib/eco/data/fuzzy_match/ngrams_score.rb +82 -0
- data/lib/eco/data/fuzzy_match/pairing.rb +95 -0
- data/lib/eco/data/fuzzy_match/result.rb +87 -0
- data/lib/eco/data/fuzzy_match/results.rb +77 -0
- data/lib/eco/data/fuzzy_match/score.rb +49 -0
- data/lib/eco/data/fuzzy_match/stop_words.rb +35 -0
- data/lib/eco/data/fuzzy_match/string_helpers.rb +82 -0
- data/lib/eco/version.rb +1 -1
- metadata +168 -11
- data/lib/eco/api/microcases/refresh_abilities.rb +0 -19
- data/lib/eco/api/organization/presets_reference.json +0 -59
- data/lib/eco/api/usecases/default_cases/refresh_abilities_case.rb +0 -30
@@ -44,7 +44,11 @@ module Eco
|
|
44
44
|
end
|
45
45
|
|
46
46
|
def policy_group(id_name)
|
47
|
-
|
47
|
+
self[id_name]
|
48
|
+
end
|
49
|
+
|
50
|
+
def [](id_name)
|
51
|
+
@by_id[policy_group_id(id_name)]
|
48
52
|
end
|
49
53
|
|
50
54
|
def user_pg_ids(initial: [], final: [], non_custom: (non_custom_not_used = true; []), preserve_custom: true)
|
@@ -5,42 +5,57 @@ module Eco
|
|
5
5
|
class PresetsFactory
|
6
6
|
ABILITIES = File.join(__dir__, 'presets_values.json')
|
7
7
|
INTEGRITY = File.join(__dir__, 'presets_integrity.json')
|
8
|
-
DEFAULT_CUSTOM = 'presets_custom.json'
|
9
|
-
DEFAULT_MAP = 'presets_map.json'
|
10
8
|
|
11
|
-
|
12
|
-
fatal("Expecting Environment object. Given: #{enviro}") if enviro && !enviro.is_a?(Eco::API::Common::Session::Environment)
|
13
|
-
@enviro = enviro
|
9
|
+
class << self
|
14
10
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
end
|
11
|
+
def all_abilities(hash = {})
|
12
|
+
Hash[abilities.each_with_object(nil).to_a].merge(hash)
|
13
|
+
end
|
19
14
|
|
20
|
-
|
15
|
+
def abilities_model
|
16
|
+
@abilities_model ||= JSON.load(File.open(ABILITIES))
|
17
|
+
end
|
21
18
|
|
22
|
-
|
23
|
-
|
24
|
-
end
|
19
|
+
def integrity_model
|
20
|
+
@integrity_model ||= JSON.load(File.open(INTEGRITY))
|
21
|
+
end
|
25
22
|
|
26
|
-
|
27
|
-
|
28
|
-
else # option to do not use preset mapping (so just the policy group name)
|
29
|
-
preset_names = names
|
23
|
+
def abilities
|
24
|
+
@abilities ||= abilities_model.keys
|
30
25
|
end
|
31
|
-
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
def initialize(enviro: nil, policy_groups: nil)
|
30
|
+
fatal("Expecting Environment object. Given: #{enviro}") if enviro && !enviro.is_a?(Eco::API::Common::Session::Environment)
|
31
|
+
@enviro = enviro
|
32
|
+
@policy_groups = policy_groups
|
32
33
|
end
|
33
34
|
|
34
35
|
# @return [Array<String>] all the abilities
|
35
36
|
def keys
|
36
|
-
|
37
|
+
self.class.abilities
|
38
|
+
end
|
39
|
+
|
40
|
+
def valid?(preset)
|
41
|
+
validate(perset).length == 0
|
42
|
+
end
|
43
|
+
|
44
|
+
def validate(preset)
|
45
|
+
[].tap do |errors|
|
46
|
+
if err = preset_errors(preset)
|
47
|
+
errors << "{ '#{key}' preset -> #{err}}"
|
48
|
+
end
|
49
|
+
if err = preset_integrity(preset)
|
50
|
+
errors << "{ '#{key}' preset -> #{err}}"
|
51
|
+
end
|
52
|
+
end
|
37
53
|
end
|
38
54
|
|
39
55
|
private
|
40
56
|
|
41
|
-
def compile(*
|
42
|
-
|
43
|
-
@presets_custom.values_at(*preset_names).compact.reduce({}) do |p1, p2|
|
57
|
+
def compile(*presets)
|
58
|
+
presets.compact.reduce({}) do |p1, p2|
|
44
59
|
merge(p1, p2)
|
45
60
|
end
|
46
61
|
end
|
@@ -58,11 +73,6 @@ module Eco
|
|
58
73
|
end
|
59
74
|
end
|
60
75
|
|
61
|
-
# unsused: only play with the given abilities
|
62
|
-
def empty_model
|
63
|
-
JSON.parse(abilities_model.to_json).transform_values {|v| nil }
|
64
|
-
end
|
65
|
-
|
66
76
|
def preset_errors(preset)
|
67
77
|
return "No preset given" if !preset
|
68
78
|
errors = preset.map do |k, v|
|
@@ -111,7 +121,7 @@ module Eco
|
|
111
121
|
end
|
112
122
|
|
113
123
|
def integrity_model
|
114
|
-
|
124
|
+
self.class.integrity_model
|
115
125
|
end
|
116
126
|
|
117
127
|
def value_exists?(ability, value)
|
@@ -125,11 +135,11 @@ module Eco
|
|
125
135
|
end
|
126
136
|
|
127
137
|
def ability_value_idx(ability, value)
|
128
|
-
abilities_model[ability].index(value)
|
138
|
+
abilities_model[ability].index(value) || -1
|
129
139
|
end
|
130
140
|
|
131
141
|
def abilities_model
|
132
|
-
|
142
|
+
self.class.abilities_model
|
133
143
|
end
|
134
144
|
|
135
145
|
def policy_groups
|
@@ -142,56 +152,6 @@ module Eco
|
|
142
152
|
@policy_groups
|
143
153
|
end
|
144
154
|
|
145
|
-
def presets_custom
|
146
|
-
return @presets_custom if instance_variable_defined?(:@presets_custom)
|
147
|
-
@presets_custom = nil
|
148
|
-
if @presets_custom_file
|
149
|
-
if (file = File.expand_path(@presets_custom_file)) && File.exists?(file)
|
150
|
-
@presets_custom = JSON.load(File.open(file)).tap do |custom_presets|
|
151
|
-
errors = custom_presets.each_with_object([]) do |(key, preset), errors|
|
152
|
-
if err = preset_errors(preset)
|
153
|
-
errors << "{ '#{key}' preset -> #{err}}"
|
154
|
-
end
|
155
|
-
if err = preset_integrity(preset)
|
156
|
-
errors << "{ '#{key}' preset -> #{err}}"
|
157
|
-
end
|
158
|
-
end
|
159
|
-
|
160
|
-
fatal("File '#{file}' contains invalid presets:\n #{errors.join("\n ")}") if errors.length > 0
|
161
|
-
end
|
162
|
-
end
|
163
|
-
end
|
164
|
-
end
|
165
|
-
|
166
|
-
def presets_map
|
167
|
-
return @presets_map if instance_variable_defined?(:@presets_map)
|
168
|
-
@presets_map = nil
|
169
|
-
if @presets_map_file
|
170
|
-
if (file = File.expand_path(@presets_map_file)) && File.exists?(file)
|
171
|
-
fatal("Maps file specified without 'presets_custom.json' file. Aborting!") if !presets_custom
|
172
|
-
@presets_map = JSON.load(File.open(file)).tap do |map_presets|
|
173
|
-
|
174
|
-
errors = []
|
175
|
-
if policy_groups.length > 0
|
176
|
-
errors = policy_groups.map do |pg|
|
177
|
-
exists = map_presets[pg.name.downcase] || presets_custom[pg.name.downcase]
|
178
|
-
exists ? nil : "'#{pg.name}'"
|
179
|
-
end.compact
|
180
|
-
|
181
|
-
warn("No maps or no preset for policy group(s): #{errors.join(", ")}") if errors.length > 0
|
182
|
-
end
|
183
|
-
|
184
|
-
errors = map_presets.map do |source, dest|
|
185
|
-
presets_custom[dest] ? nil : "'#{dest}'"
|
186
|
-
end.compact
|
187
|
-
|
188
|
-
warn("Unexisting mapped preset(s): #{errors.uniq.join(", ")}") if errors.length > 0
|
189
|
-
|
190
|
-
end
|
191
|
-
end
|
192
|
-
end
|
193
|
-
end
|
194
|
-
|
195
155
|
def fatal(msg)
|
196
156
|
raise msg if !@enviro
|
197
157
|
@enviro.logger.fatal(msg)
|
@@ -2,14 +2,15 @@
|
|
2
2
|
"files": [null, "download", "upload", "browse", "administrate"],
|
3
3
|
"data": [null, "view", "update", "administrate", "implement"],
|
4
4
|
"reports": [null, "view", "edit", "administrate"],
|
5
|
+
"pages": [null, "view", "update", "create", "administrate"],
|
6
|
+
"page_editor": [null, "basic", "intermediate", "advanced", "implement"],
|
7
|
+
"registers": [null, "view", "dashboard", "administrate", "implement"],
|
5
8
|
"tasks": [null, "reassign_self", "reassign", "administrate"],
|
6
9
|
"organization": [null, "view", "administrate", "implement"],
|
7
10
|
"person_core": [null, "attach", "view_people_manager", "dashboard"],
|
8
11
|
"person_core_create": [null, "create"],
|
9
12
|
"person_core_edit": [null, "edit"],
|
10
|
-
"person_account": [null, "view", "create", "edit"],
|
11
13
|
"person_details": [null, "view", "edit_public", "view_private", "edit_private"],
|
12
|
-
"
|
13
|
-
"
|
14
|
-
"registers": [null, "view", "dashboard", "administrate", "implement"]
|
14
|
+
"person_account": [null, "view", "create", "edit"],
|
15
|
+
"person_abilities": [null, "view", "edit"]
|
15
16
|
}
|
@@ -42,6 +42,39 @@ module Eco
|
|
42
42
|
init_hashes
|
43
43
|
end
|
44
44
|
|
45
|
+
# Updates the tag of the current tree
|
46
|
+
def tag=(value)
|
47
|
+
@tag = value
|
48
|
+
end
|
49
|
+
|
50
|
+
# @return [Eco::API::Organization::TagTree]
|
51
|
+
def dup
|
52
|
+
self.class.new(as_json)
|
53
|
+
end
|
54
|
+
|
55
|
+
# @return [Array] with the differences
|
56
|
+
def diff(tagtree, differences: {}, level: 0, **options)
|
57
|
+
require 'hashdiff'
|
58
|
+
Hashdiff.diff(self.as_json, tagtree.as_json, **options.slice(:array_path, :similarity, :use_lcs))
|
59
|
+
end
|
60
|
+
|
61
|
+
def top?
|
62
|
+
depth == -1
|
63
|
+
end
|
64
|
+
|
65
|
+
# @return [Array[Hash]] where `Hash` is a `node` `{"tag" => TAG, "nodes": Array[Hash]}`
|
66
|
+
def as_json
|
67
|
+
nodes_json = nodes.map {|node| node.as_json}
|
68
|
+
if top?
|
69
|
+
nodes_json
|
70
|
+
else
|
71
|
+
{
|
72
|
+
"tag" => tag,
|
73
|
+
"nodes" => nodes_json
|
74
|
+
}
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
45
78
|
# @return [Boolean] `true` if there are tags in the node, `false` otherwise.
|
46
79
|
def empty?
|
47
80
|
@has_tags.empty?
|
@@ -12,7 +12,6 @@ class Eco::API::Policies::DefaultPolicies::UserAccess < Eco::API::Common::Loader
|
|
12
12
|
people.each do |person|
|
13
13
|
remove_account_when_no_email!(person) if person.email.to_s.empty?
|
14
14
|
person.account.policy_group_ids = defid if no_policy_group_ids?(person)
|
15
|
-
refresh_abilities!(person)
|
16
15
|
end
|
17
16
|
|
18
17
|
warn_account_removal!
|
@@ -40,39 +39,10 @@ class Eco::API::Policies::DefaultPolicies::UserAccess < Eco::API::Common::Loader
|
|
40
39
|
return !!person.original_doc["account"]
|
41
40
|
end
|
42
41
|
|
43
|
-
def refresh_abilities!(person)
|
44
|
-
return nil if options.dig(:exclude, :abilities)
|
45
|
-
return nil unless account = person.account
|
46
|
-
account.permissions_custom = session.new_preset(person)
|
47
|
-
account.permissions_custom = min_abilities if no_abilities?(person)
|
48
|
-
end
|
49
|
-
|
50
42
|
def no_policy_group_ids?(person)
|
51
43
|
(account = person.account) && account.policy_group_ids.empty?
|
52
44
|
end
|
53
45
|
|
54
|
-
def no_abilities?(person)
|
55
|
-
return true unless account = person.account
|
56
|
-
account.permissions_custom && account.permissions_custom.values.all?(&:nil?)
|
57
|
-
end
|
58
|
-
|
59
|
-
def min_abilities
|
60
|
-
{
|
61
|
-
"files" => "upload",
|
62
|
-
"data" => nil,
|
63
|
-
"reports" => nil,
|
64
|
-
"pages" => "create",
|
65
|
-
"page_editor" => "basic",
|
66
|
-
"registers" => "view",
|
67
|
-
"organization" => nil,
|
68
|
-
"person_core" => "attach",
|
69
|
-
"person_core_edit" => nil,
|
70
|
-
"person_core_create" => nil,
|
71
|
-
"person_details" => "view",
|
72
|
-
"person_account" => nil
|
73
|
-
}
|
74
|
-
end
|
75
|
-
|
76
46
|
def defid
|
77
47
|
@defid ||= policy_groups.to_id([default_group]).compact
|
78
48
|
end
|
data/lib/eco/api/session.rb
CHANGED
@@ -61,28 +61,9 @@ module Eco
|
|
61
61
|
self
|
62
62
|
end
|
63
63
|
|
64
|
-
# Builds the presets using the usergroup ids of the input.
|
65
|
-
# @note for each flag/ability it will take the highest among those mapped for the present usergroups.
|
66
|
-
# @param input [Ecoportal::API::Internal::Person, Array<String>] the array should be of usegroup names or ids.
|
67
|
-
# @return [Hash] with custom presets.
|
68
|
-
def new_preset(input)
|
69
|
-
case input
|
70
|
-
when Ecoportal::API::Internal::Person
|
71
|
-
presets_factory.new(*input&.account&.policy_group_ids)
|
72
|
-
when Array
|
73
|
-
presets_factory.new(*input)
|
74
|
-
else
|
75
|
-
presets_factory.new(input)
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
64
|
# Helper to state the abilities that a person should have with given their usergroups
|
80
65
|
def presets_factory
|
81
|
-
@presets_factory ||= Eco::API::Organization::PresetsFactory.new(
|
82
|
-
presets_custom: file_manager.dir.file(config.people.presets_custom, should_exist: true),
|
83
|
-
presets_map: file_manager.dir.file(config.people.presets_map, should_exist: true),
|
84
|
-
enviro: enviro
|
85
|
-
})
|
66
|
+
@presets_factory ||= Eco::API::Organization::PresetsFactory.new(enviro: enviro)
|
86
67
|
end
|
87
68
|
|
88
69
|
# Helper to obtain a EntryFactory
|
@@ -93,12 +74,15 @@ module Eco
|
|
93
74
|
def entry_factory(schema: nil)
|
94
75
|
schema = to_schema(schema) || self.schema
|
95
76
|
return @entry_factories[schema&.id] if @entry_factories.key?(schema&.id)
|
77
|
+
unless @entry_factories.empty?
|
78
|
+
@entry_factories[schema&.id] = @entry_factories.values.first.newFactory(schema: schema)
|
79
|
+
return @entry_factories[schema&.id]
|
80
|
+
end
|
96
81
|
|
97
82
|
mappings = []
|
98
83
|
if map_file = config.people.fields_mapper
|
99
84
|
mappings = map_file ? file_manager.load_json(map_file) : []
|
100
85
|
end
|
101
|
-
|
102
86
|
@entry_factories[schema&.id] = Eco::API::Common::People::EntryFactory.new(
|
103
87
|
enviro,
|
104
88
|
schema: schema,
|
@@ -122,11 +106,13 @@ module Eco
|
|
122
106
|
# @param attr [String] type (`Symbol`) or attribute (`String`) to target a specific parser.
|
123
107
|
# @param source [Any] source value to be parsed.
|
124
108
|
# @param phase [Symbol] the phase when this parser should be active.
|
125
|
-
|
109
|
+
# @param phase [Symbol] the phase when this parser should be active.
|
110
|
+
# @return [Object] the parsed attribute.
|
111
|
+
def parse_attribute(attr, source, phase = :internal, deps: {})
|
126
112
|
unless parsers = entry_factory.person_parser
|
127
113
|
raise "There are no parsers defined"
|
128
114
|
end
|
129
|
-
parsers.parse(attr, source, phase)
|
115
|
+
parsers.parse(attr, source, phase, deps: deps)
|
130
116
|
end
|
131
117
|
|
132
118
|
# @see Eco::API::Common::People::EntryFactory#export
|
@@ -146,7 +132,7 @@ module Eco
|
|
146
132
|
# @see Eco::API::Common::People::EntryFactory#new
|
147
133
|
# @return [Eco::API::Common::People::PersonEntry] parsed entry.
|
148
134
|
def new_entry(data, dependencies: {})
|
149
|
-
entry_factory.new(data, dependencies: dependencies)
|
135
|
+
entry_factory(schema: data&.details&.schema_id).new(data, dependencies: dependencies)
|
150
136
|
end
|
151
137
|
|
152
138
|
# @see Eco::API::Common::People::EntryFactory#entries
|
@@ -114,14 +114,16 @@ module Eco
|
|
114
114
|
logger.info(msg) unless silent
|
115
115
|
|
116
116
|
start_slice = Time.now
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
117
|
+
offer_retry_on(Ecoportal::API::Errors::TimeOut) do
|
118
|
+
people_api.batch do |batch|
|
119
|
+
slice.each do |person|
|
120
|
+
batch.public_send(method, person) do |response|
|
121
|
+
faltal("Request with no response") unless !!response
|
122
|
+
status[person] = response
|
123
|
+
end
|
122
124
|
end
|
123
|
-
end
|
124
|
-
end
|
125
|
+
end # end batch
|
126
|
+
end
|
125
127
|
|
126
128
|
iteration += 1
|
127
129
|
done += slice.length
|
@@ -129,6 +131,22 @@ module Eco
|
|
129
131
|
end
|
130
132
|
end
|
131
133
|
|
134
|
+
def offer_retry_on(error_type, retries_left = 3, &block)
|
135
|
+
begin
|
136
|
+
block.call
|
137
|
+
rescue error_type => e
|
138
|
+
raise unless retries_left > 0
|
139
|
+
explanation = "Batch TimeOut. You have #{retries_left} retries left."
|
140
|
+
prompt_user("Do you want to retry (y/N)?", explanation, default: "Y", timeout: 10) do |response|
|
141
|
+
if response.upcase.start_with?("Y")
|
142
|
+
offer_retry_on(error_type, retries_left - 1, &block)
|
143
|
+
else
|
144
|
+
raise
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
132
150
|
def str_stats(start, count)
|
133
151
|
now = Time.now
|
134
152
|
secs = (now - start).round(3)
|
@@ -159,6 +159,8 @@ module Eco
|
|
159
159
|
end
|
160
160
|
|
161
161
|
def working_directory(mode: nil)
|
162
|
+
return files.working_directory if apis.active_api&.one_off?
|
163
|
+
|
162
164
|
unless mode
|
163
165
|
wd = files.working_directory
|
164
166
|
return wd unless wd.to_s.strip.empty?
|
@@ -183,12 +185,21 @@ module Eco
|
|
183
185
|
end
|
184
186
|
|
185
187
|
def require(file = nil, match: nil)
|
186
|
-
|
187
|
-
|
188
|
-
|
188
|
+
begin
|
189
|
+
if match
|
190
|
+
file_manager.dir.dir_files(pattern: match).each do |file|
|
191
|
+
require_relative File.expand_path(file)
|
192
|
+
end
|
193
|
+
else
|
194
|
+
target = File.expand_path(file_manager.dir.file(file))
|
195
|
+
require_relative target
|
196
|
+
end
|
197
|
+
rescue LoadError => e
|
198
|
+
if apis.active_api.one_off?
|
199
|
+
pp e.to_s
|
200
|
+
else
|
201
|
+
raise
|
189
202
|
end
|
190
|
-
else
|
191
|
-
require_relative "#{File.expand_path(file_manager.dir.file(file))}"
|
192
203
|
end
|
193
204
|
end
|
194
205
|
# @!endgroup
|
@@ -286,16 +297,6 @@ module Eco
|
|
286
297
|
people.default_schema = name
|
287
298
|
end
|
288
299
|
|
289
|
-
# Specify the file with the account custom abilities presets
|
290
|
-
def presets_custom=(file)
|
291
|
-
people.presets_custom = file
|
292
|
-
end
|
293
|
-
|
294
|
-
# Specify the file with the usergroup to custom presets mapping
|
295
|
-
def presets_map=(file)
|
296
|
-
people.presets_map = file
|
297
|
-
end
|
298
|
-
|
299
300
|
# @see Eco::API::Session::Config::People
|
300
301
|
# @param (see Eco::API::Session::Config::People)
|
301
302
|
# @return [Eco::API::Common::People::PersonParser] parser/serializer for the defined `format`.
|