eco-helpers 1.5.4 → 1.5.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +41 -0
- data/lib/eco/api/common/version_patches.rb +1 -0
- data/lib/eco/api/common/version_patches/object.rb +10 -0
- data/lib/eco/api/organization/tag_tree.rb +10 -0
- data/lib/eco/api/session.rb +5 -3
- data/lib/eco/api/session/batch/job.rb +1 -1
- data/lib/eco/api/session/batch/jobs.rb +22 -3
- data/lib/eco/api/session/batch/jobs_groups.rb +9 -0
- data/lib/eco/api/usecases/default_cases/org_data_convert_case.rb +25 -7
- data/lib/eco/api/usecases/default_cases/refresh_case.rb +1 -1
- data/lib/eco/api/usecases/default_cases/restore_db_case.rb +25 -13
- data/lib/eco/api/usecases/use_case.rb +1 -1
- data/lib/eco/api/usecases/use_case_io.rb +0 -1
- data/lib/eco/cli/config/default/usecases.rb +21 -0
- data/lib/eco/cli/config/default/workflow.rb +1 -1
- data/lib/eco/cli/config/use_cases.rb +1 -1
- data/lib/eco/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 37896bf21f1661d488b3af20ac7ed8ee298536d3e96324308f84459ad0e2abb2
|
4
|
+
data.tar.gz: 05e8eac1fcb530509af91b62c17e89380f3b5ac0926a3a445bd29a309a440c44
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 75e90bf526e20a8dde18a64445f07d5bcaadd7038cb5e2070d8e777341a9799f604da94f4aae359772959a7d92da01db658311afa2d765c31882bf59b138dabe
|
7
|
+
data.tar.gz: 338389f47335ae1f01f683ba3d54974ecce8eb70e90243534d835aa5cede39ab44458a37aa800206c018e023ff0e45eb228c7a52721a3e95801606743ae2b971
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,47 @@
|
|
1
1
|
# Change Log
|
2
2
|
All notable changes to this project will be documented in this file.
|
3
3
|
|
4
|
+
## [1.5.9] - 2021-01-08
|
5
|
+
|
6
|
+
### Added
|
7
|
+
- `Eco::API::Organization::TagTree#subtags` to get all the tags but those of the highest level.
|
8
|
+
|
9
|
+
### Changed
|
10
|
+
### Fixed
|
11
|
+
|
12
|
+
|
13
|
+
## [1.5.8] - 2021-01-05
|
14
|
+
|
15
|
+
### Added
|
16
|
+
### Changed
|
17
|
+
### Fixed
|
18
|
+
- `Eco::API::Session::Batch::Jobs#job` shouldn't be calling the post-launch callback function on creation.
|
19
|
+
- `Eco::API::Session#new_job` should include a `&block` parameter.
|
20
|
+
- `Eco::API::UseCases::DefaultCases::RefreshCase`: fixed typo
|
21
|
+
|
22
|
+
## [1.5.7] - 2020-12-17
|
23
|
+
|
24
|
+
### Added
|
25
|
+
### Changed
|
26
|
+
### Fixed
|
27
|
+
- `Eco::API::Sesssion#parse_attribute` was not using phase argument
|
28
|
+
|
29
|
+
## [1.5.6] - 2020-12-04
|
30
|
+
|
31
|
+
### Added
|
32
|
+
### Changed
|
33
|
+
### Fixed
|
34
|
+
- `Eco::API::UseCases::DefaultCases::RestoreDBCase` fixed typo and slightly improved
|
35
|
+
- fixed some back-end errors when chaining usecases
|
36
|
+
- `Eco::API::UseCases::DefaultCases::OrgDataConvertCase` improved
|
37
|
+
|
38
|
+
## [1.5.5] - 2020-12-03
|
39
|
+
|
40
|
+
### Added
|
41
|
+
### Changed
|
42
|
+
### Fixed
|
43
|
+
- rubies previous to `2.5` do not have `yield_self`
|
44
|
+
|
4
45
|
## [1.5.4] - 2020-12-02
|
5
46
|
|
6
47
|
### Added
|
@@ -46,6 +46,10 @@ module Eco
|
|
46
46
|
@has_tags.empty?
|
47
47
|
end
|
48
48
|
|
49
|
+
# Gets all the tags of the current node tree.
|
50
|
+
# @note
|
51
|
+
# - this will include the upper level tag(s) as well
|
52
|
+
# - to get all but the upper level tag(s) use `subtags` method instead
|
49
53
|
# @param depth [Integer] if empty, returns the list of tag nodes of that level. Otherwise the list of tag nodes of the entire subtree.
|
50
54
|
# @return [Array<String>]
|
51
55
|
def tags(depth: nil)
|
@@ -58,6 +62,12 @@ module Eco
|
|
58
62
|
end
|
59
63
|
end
|
60
64
|
|
65
|
+
# Gets all but the upper level tags of the current node tree.
|
66
|
+
# @return [Array<String>]
|
67
|
+
def subtags
|
68
|
+
tags - tags(depth: depth)
|
69
|
+
end
|
70
|
+
|
61
71
|
# Verifies if a tag exists in the tree.
|
62
72
|
# @param key [String] tag to verify.
|
63
73
|
# @return [Boolean]
|
data/lib/eco/api/session.rb
CHANGED
@@ -126,7 +126,7 @@ module Eco
|
|
126
126
|
unless parsers = entry_factory.person_parser
|
127
127
|
raise "There are no parsers defined"
|
128
128
|
end
|
129
|
-
parsers.parse(attr, source)
|
129
|
+
parsers.parse(attr, source, phase)
|
130
130
|
end
|
131
131
|
|
132
132
|
# @see Eco::API::Common::People::EntryFactory#export
|
@@ -217,6 +217,7 @@ module Eco
|
|
217
217
|
@job_groups ||= Batch::JobsGroups.new(enviro)
|
218
218
|
end
|
219
219
|
|
220
|
+
# It retrives the group of `Batch::Jobs` named `name`. It creates it if it doesn't exist.
|
220
221
|
# @return [Eco::API::Session::Batch::Jobs]
|
221
222
|
def job_group(name, order: :last)
|
222
223
|
case
|
@@ -228,9 +229,10 @@ module Eco
|
|
228
229
|
end
|
229
230
|
|
230
231
|
# Shortcut to create a job of certain type within a group
|
232
|
+
# @param [see @Eco::API::Session::Batch::Jobs#new]
|
231
233
|
# @return [Eco::API::Session::Batch::Job]
|
232
|
-
def new_job(group, name, type, usecase, sets = [:core, :details, :account])
|
233
|
-
job_group(group).new(name, usecase: usecase, type: type, sets: sets)
|
234
|
+
def new_job(group, name, type, usecase, sets = [:core, :details, :account], &block)
|
235
|
+
job_group(group).new(name, usecase: usecase, type: type, sets: sets, &block)
|
234
236
|
end
|
235
237
|
|
236
238
|
# @see Eco::API::Session::Batch::JobsGroups#launch
|
@@ -96,7 +96,7 @@ module Eco
|
|
96
96
|
# @param entry [Ecoportal::API::V1::Person, Enumberable<Person>] the person(s) we want to update, carrying the changes to be done.
|
97
97
|
# @param unique [Boolean] specifies if repeated entries should be avoided in the queue.
|
98
98
|
# @yield [person] callback before launching the batch job request against the server.
|
99
|
-
# @yieldparam
|
99
|
+
# @yieldparam person [Person] current person object that that should be treated by the callback before launching the batch.
|
100
100
|
# @return [Eco::API::Session::Batch::Job] this `Batch::Job`.
|
101
101
|
def add(entry, unique: true, &block)
|
102
102
|
case entry
|
@@ -42,13 +42,23 @@ module Eco
|
|
42
42
|
@jobs.key?(name)
|
43
43
|
end
|
44
44
|
|
45
|
+
# It retrieves an existing job named `name` or creates it if it doesn't exist.
|
46
|
+
# @note
|
47
|
+
# - the block should only be passed when creating the job
|
48
|
+
# @param [see @Eco::API::Session::Batch::Jobs#new]
|
49
|
+
# @return [Eco::API::Session::Batch::Job]
|
45
50
|
def job(name, type: nil, sets: nil, usecase: nil, &block)
|
51
|
+
fatal "Can't give a job post-launch callback &block to an already existing job" if exists?(name)
|
46
52
|
new(name, type: type, sets: sets, usecase: usecase, &block) unless exists?(name)
|
47
|
-
self[name]
|
48
|
-
block.call(job) if block
|
49
|
-
end
|
53
|
+
self[name]
|
50
54
|
end
|
51
55
|
|
56
|
+
# Creates a new `Batch::Job` included as part of this `Batch::Jobs`.
|
57
|
+
# @param [see Eco::API::Session::Job#new]
|
58
|
+
# @yield [job, status] callback after launching the batch job request against the server.
|
59
|
+
# @yieldparam job [Eco::API::Session::Batch::Job] the job we have launched against the server.
|
60
|
+
# @yieldparam status [Eco::API::Session::Batch::Status] the status of the batch job launch.
|
61
|
+
# @return [Eco::API::Session::Batch::Job]
|
52
62
|
def new(name, type:, sets:, usecase: nil, &block)
|
53
63
|
fatal "Can't create job named '#{name}' because it already exists." if exists?(name)
|
54
64
|
|
@@ -57,6 +67,11 @@ module Eco
|
|
57
67
|
end
|
58
68
|
end
|
59
69
|
|
70
|
+
# @param job [Eco::API::Session::Batch::Job] the `Batch::Job` to add.
|
71
|
+
# @yield [job, status] callback after launching the batch job request against the server.
|
72
|
+
# @yieldparam job [Eco::API::Session::Batch::Job] the job we have launched against the server.
|
73
|
+
# @yieldparam status [Eco::API::Session::Batch::Status] the status of the batch job launch.
|
74
|
+
# @return [Eco::API::Session::Batch::Job]
|
60
75
|
def add(job)
|
61
76
|
fatal "Expected Eco::API::Session::Batch::Job object. Given #{job.class}" unless job.is_a?(Eco::API::Session::Batch::Job)
|
62
77
|
@jobs[job.name] = job
|
@@ -67,6 +82,10 @@ module Eco
|
|
67
82
|
any? {|job| job.pending?}
|
68
83
|
end
|
69
84
|
|
85
|
+
# Launches every `Batch::Job` in the group.
|
86
|
+
# @note
|
87
|
+
# - if there was post-launch callback for a `Batch::Job`, it calls it.
|
88
|
+
# @return [Hash<Eco::API::Session::Batch::Job, Eco::API::Session::Batch::Status>]
|
70
89
|
def launch(simulate: false)
|
71
90
|
each do |job|
|
72
91
|
if job.pending?
|
@@ -58,6 +58,11 @@ module Eco
|
|
58
58
|
@groups.key?(name)
|
59
59
|
end
|
60
60
|
|
61
|
+
# Creates a new group of `Batch::Jobs` named `name`.
|
62
|
+
# @yield [group, group_status] callback after launching the batch job request against the server.
|
63
|
+
# @yieldparam group [Eco::API::Session::Batch::Jobs] the group of jobs we have launched against the server.
|
64
|
+
# @yieldparam group_status [Hash<Eco::API::Session::Batch::Job, Eco::API::Session::Batch::Status>] the status of the launched batch jobs.
|
65
|
+
# @return [Eco::API::Session::Batch::Jobs] the group of jobs.
|
61
66
|
def new(name, order: :last)
|
62
67
|
fatal "Can't create job group named '#{name}' because it already exists." if exists?(name)
|
63
68
|
|
@@ -78,6 +83,10 @@ module Eco
|
|
78
83
|
any? {|group| group.pending?}
|
79
84
|
end
|
80
85
|
|
86
|
+
# Launches every `Batch::Jobs` group in the current `Batch::JobGroups`
|
87
|
+
# @note
|
88
|
+
# - if there was post-launch callback for a `Batch::Jobs` groups, it calls it.
|
89
|
+
# @return [Hash<Eco::API::Session::Batch::Jobs,Hash<Eco::API::Session::Batch::Job, Eco::API::Session::Batch::Status>>]
|
81
90
|
def launch(simulate: false)
|
82
91
|
@order.each_with_index do |group, idx|
|
83
92
|
if group.pending?
|
@@ -2,6 +2,8 @@ class Eco::API::UseCases::DefaultCases::OrgDataConvertCase < Eco::API::Common::L
|
|
2
2
|
name "org-data-convert"
|
3
3
|
type :import
|
4
4
|
|
5
|
+
attr_reader :session, :options
|
6
|
+
|
5
7
|
def org_data_convert(people)
|
6
8
|
pp "Going to convert data from '#{source_enviro}' to '#{ASSETS.active_config}'"
|
7
9
|
puts "\n"
|
@@ -50,27 +52,43 @@ class Eco::API::UseCases::DefaultCases::OrgDataConvertCase < Eco::API::Common::L
|
|
50
52
|
|
51
53
|
def policy_groups_convert(ids)
|
52
54
|
ids.map do |id|
|
53
|
-
unless name =
|
54
|
-
|
55
|
+
unless name = source_policy_groups.to_name(id) || ignore_missing_policy_groups?
|
56
|
+
msg = "Ops, do not know #{id} usergroup for source environment"
|
57
|
+
msg += "\nUse the option -ignore-missing-policy-groups if you do not care"
|
58
|
+
error(msg)
|
55
59
|
end
|
56
60
|
session.policy_groups.to_id(name).tap do |new_id|
|
57
|
-
unless new_id
|
58
|
-
|
61
|
+
unless new_id || ignore_missing_policy_groups?
|
62
|
+
msg = "Ops, do not know #{name} usergroup for destination environment"
|
63
|
+
msg += "\nUse the option -ignore-missing-policy-groups if you do not care"
|
64
|
+
error(msg)
|
59
65
|
end
|
60
66
|
end
|
61
|
-
end
|
67
|
+
end.compact
|
68
|
+
end
|
69
|
+
|
70
|
+
def source_policy_groups
|
71
|
+
source_config.policy_groups
|
62
72
|
end
|
63
73
|
|
64
74
|
def source_config
|
65
|
-
@source_config ||= ASSETS.config(key: source_enviro, update_active: false)
|
75
|
+
@source_config ||= ASSETS.config(key: source_enviro, update_active: false).tap do |config|
|
76
|
+
unless config
|
77
|
+
error("The source environment '#{source_enviro}' does not exit or is not configured")
|
78
|
+
end
|
79
|
+
end
|
66
80
|
end
|
67
81
|
|
68
82
|
def source_enviro
|
69
83
|
@source_enviro ||= options.dig(:source_enviro).tap do |enviro|
|
70
|
-
error("A source
|
84
|
+
error("A source environment is required to migrate data from") unless enviro
|
71
85
|
end
|
72
86
|
end
|
73
87
|
|
88
|
+
def ignore_missing_policy_groups?
|
89
|
+
options.dig(:ignore, :missing, :policy_groups)
|
90
|
+
end
|
91
|
+
|
74
92
|
def logger
|
75
93
|
@session.logger
|
76
94
|
end
|
@@ -4,7 +4,7 @@ class Eco::API::UseCases::DefaultCases::RefreshCase < Eco::API::Common::Loaders:
|
|
4
4
|
|
5
5
|
def main(people, session, options, usecase)
|
6
6
|
update = session.new_job("main", "update", :update, usecase)
|
7
|
-
people.each {|person|
|
7
|
+
people.each {|person| update.add(person)}
|
8
8
|
end
|
9
9
|
|
10
10
|
end
|
@@ -2,7 +2,11 @@ class Eco::API::UseCases::DefaultCases::RestoreDBCase < Eco::API::Common::Loader
|
|
2
2
|
name "restore-db"
|
3
3
|
type :sync
|
4
4
|
|
5
|
+
attr_reader :session, :options
|
6
|
+
|
5
7
|
def main(entries, people, session, options, usecase)
|
8
|
+
@session = session; @options = options
|
9
|
+
|
6
10
|
micro = session.micro
|
7
11
|
require_people_as_entries!(entries)
|
8
12
|
|
@@ -26,21 +30,21 @@ class Eco::API::UseCases::DefaultCases::RestoreDBCase < Eco::API::Common::Loader
|
|
26
30
|
|
27
31
|
person.new? ? restart.add(person) : update.add(person)
|
28
32
|
|
29
|
-
core_copy(entry, person
|
30
|
-
person.details = entry.details
|
33
|
+
core_copy(entry, person) unless options.dig(:exclude, :core)
|
34
|
+
person.details = entry.details unless options.dig(:exclude, :details)
|
31
35
|
|
32
36
|
unless options.dig(:exclude, :account) || !entry.account
|
33
37
|
person.account ||= {}
|
34
|
-
account_copy(entry.account, person.account
|
38
|
+
account_copy(entry.account, person.account)
|
35
39
|
end
|
36
40
|
end
|
37
41
|
|
38
|
-
report_re_starters(re_starters
|
42
|
+
report_re_starters(re_starters)
|
39
43
|
end
|
40
44
|
|
41
45
|
private
|
42
46
|
|
43
|
-
def core_copy(entry, person
|
47
|
+
def core_copy(entry, person)
|
44
48
|
person.external_id = entry.external_id unless options.dig(:exclude, :external_id)
|
45
49
|
person.name = entry.name unless options.dig(:exclude, :name)
|
46
50
|
person.email = entry.email unless options.dig(:exclude, :email)
|
@@ -49,8 +53,8 @@ class Eco::API::UseCases::DefaultCases::RestoreDBCase < Eco::API::Common::Loader
|
|
49
53
|
person.freemium = entry.freemium
|
50
54
|
end
|
51
55
|
|
52
|
-
def account_copy(src, dst
|
53
|
-
if src
|
56
|
+
def account_copy(src, dst)
|
57
|
+
if src
|
54
58
|
dst.default_tag = src.default_tag unless options.dig(:exclude, :filter_tags)
|
55
59
|
dst.policy_group_ids = src.policy_group_ids unless options.dig(:exclude, :policy_groups)
|
56
60
|
|
@@ -59,27 +63,31 @@ class Eco::API::UseCases::DefaultCases::RestoreDBCase < Eco::API::Common::Loader
|
|
59
63
|
dst.permissions_custom = src.permissions_custom
|
60
64
|
end
|
61
65
|
|
62
|
-
|
63
|
-
|
66
|
+
unless options.dig(:exclude, :login_providers) || options.dig(:source_enviro)
|
67
|
+
dst.login_provider_ids = src.login_provider_ids
|
68
|
+
end
|
64
69
|
|
65
70
|
if src.preferences
|
66
71
|
dst.doc["preferences"] = JSON.parse((src.doc["preferences"] || {}).to_json)
|
67
72
|
end
|
68
73
|
|
69
|
-
|
70
|
-
|
74
|
+
unless options.dig(:source_enviro)
|
75
|
+
dst.starred_ids = src.starred_ids
|
76
|
+
dst.landing_page_id = src.landing_page_id
|
77
|
+
end
|
78
|
+
|
71
79
|
dst&.send_invites = options[:send_invites] if options.key?(:send_invites)
|
72
80
|
end
|
73
81
|
end
|
74
82
|
|
75
|
-
def require_people_as_entries!(entries
|
83
|
+
def require_people_as_entries!(entries)
|
76
84
|
unless entries.is_a?(Eco::API::Organization::People)
|
77
85
|
logger.error("Your input should be an 'Eco::API::Organization::People' object. Got: #{entries.class}")
|
78
86
|
exit(1)
|
79
87
|
end
|
80
88
|
end
|
81
89
|
|
82
|
-
def report_re_starters(re_starters
|
90
|
+
def report_re_starters(re_starters)
|
83
91
|
unless re_starters.empty?
|
84
92
|
logger.error("There were #{re_starters.length} entries of the backup that do not exist in the (filtered?) people manager")
|
85
93
|
logger.error("Some examples:")
|
@@ -89,4 +97,8 @@ class Eco::API::UseCases::DefaultCases::RestoreDBCase < Eco::API::Common::Loader
|
|
89
97
|
end
|
90
98
|
end
|
91
99
|
|
100
|
+
def logger
|
101
|
+
session.logger
|
102
|
+
end
|
103
|
+
|
92
104
|
end
|
@@ -36,7 +36,7 @@ module Eco
|
|
36
36
|
# @option kargs [Eco::API:Session] :session
|
37
37
|
# @option kargs [Hash] :options hash with symbol keys (i.e. behaviour modifiers, cli trackers, filters, etc.)
|
38
38
|
def launch(io: nil, **kargs)
|
39
|
-
params = io&.params(keyed: true) || {}
|
39
|
+
params = io&.params(keyed: true, all: true) || {}
|
40
40
|
kargs = params.merge(kargs).merge(usecase: self)
|
41
41
|
|
42
42
|
UseCaseIO.new(**kargs).tap do |uio|
|
@@ -55,6 +55,27 @@ ASSETS.cli.config do |cnf|
|
|
55
55
|
options.deep_merge!(super: {new: new_id})
|
56
56
|
end
|
57
57
|
|
58
|
+
desc = "Usage '-org-data-convert backup.json -restore-db-from'."
|
59
|
+
desc += " Transforms an input .json file to the values of the destination environment "
|
60
|
+
desc += " (names missmatch won't solve: i.e. usergroups)"
|
61
|
+
cases.add("-org-data-convert", :import, desc, case_name: "org-data-convert") do |input, session, options|
|
62
|
+
unless input && input.is_a?(Eco::API::Organization::People)
|
63
|
+
file = SCR.get_file("-org-data-convert", required: true)
|
64
|
+
input = Eco::API::Organization::People.new(JSON.parse(File.read(file)))
|
65
|
+
session.logger.info("Source DB: loaded #{input.length} entries.")
|
66
|
+
end
|
67
|
+
|
68
|
+
if source_enviro = SCR.get_arg("-source-enviro", with_param: true)
|
69
|
+
options.merge!(source_enviro: source_enviro)
|
70
|
+
else
|
71
|
+
session.logger.error("You need to specify a -source-enviro for the conversion to work out")
|
72
|
+
exit(1)
|
73
|
+
end
|
74
|
+
|
75
|
+
options.deep_merge!(ignore: {missing: {policy_groups: true}}) if SCR.get_arg("-ignore-missing-policy-groups")
|
76
|
+
|
77
|
+
end
|
78
|
+
|
58
79
|
desc = "Restores the people manager by using a backup.json file"
|
59
80
|
cases.add("-restore-db-from", :sync, desc, case_name: "restore-db") do |input, people, session, options|
|
60
81
|
unless input && input.is_a?(Eco::API::Organization::People)
|
@@ -94,7 +94,7 @@ module Eco
|
|
94
94
|
when Eco::API::UseCases::UseCaseIO
|
95
95
|
io.chain(usecase: usecase)
|
96
96
|
when Eco::API::UseCases::BaseIO
|
97
|
-
params = io.params(keyed: true).merge(usecase: usecase)
|
97
|
+
params = io.params(keyed: true, all: true).merge(usecase: usecase)
|
98
98
|
Eco::API::UseCases::UseCaseIO.new(**params)
|
99
99
|
end
|
100
100
|
end
|
data/lib/eco/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eco-helpers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.5.
|
4
|
+
version: 1.5.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Oscar Segura
|
@@ -296,6 +296,7 @@ files:
|
|
296
296
|
- lib/eco/api/common/version_patches/exception.rb
|
297
297
|
- lib/eco/api/common/version_patches/hash.rb
|
298
298
|
- lib/eco/api/common/version_patches/hash/deep_merge.rb
|
299
|
+
- lib/eco/api/common/version_patches/object.rb
|
299
300
|
- lib/eco/api/custom.rb
|
300
301
|
- lib/eco/api/custom/error_handler.rb
|
301
302
|
- lib/eco/api/custom/namespace.rb
|