eco-helpers 2.0.14 → 2.0.19
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +90 -2
- data/eco-helpers.gemspec +6 -4
- data/lib/eco-helpers.rb +2 -0
- data/lib/eco/api/common/base_loader.rb +14 -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/entry_factory.rb +26 -9
- 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 +8 -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 +112 -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/policies/default_policies/99_user_access_policy.rb +0 -30
- data/lib/eco/api/session.rb +6 -22
- 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 +53 -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 +59 -0
- 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 +20 -17
- data/lib/eco/cli/config/default/people_filters.rb +3 -3
- data/lib/eco/cli/config/default/usecases.rb +80 -26
- data/lib/eco/cli/config/default/workflow.rb +16 -4
- 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/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 +161 -0
- data/lib/eco/data/fuzzy_match/array_helpers.rb +75 -0
- data/lib/eco/data/fuzzy_match/chars_position_score.rb +37 -0
- data/lib/eco/data/fuzzy_match/ngrams_score.rb +78 -0
- data/lib/eco/data/fuzzy_match/pairing.rb +101 -0
- data/lib/eco/data/fuzzy_match/result.rb +73 -0
- data/lib/eco/data/fuzzy_match/results.rb +59 -0
- data/lib/eco/data/fuzzy_match/score.rb +44 -0
- data/lib/eco/data/fuzzy_match/stop_words.rb +35 -0
- data/lib/eco/data/fuzzy_match/string_helpers.rb +69 -0
- data/lib/eco/version.rb +1 -1
- metadata +87 -10
- 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
@@ -124,8 +124,9 @@ class Eco::API::UseCases::OozeSamples::OozeUpdateCase < Eco::API::Common::Loader
|
|
124
124
|
end
|
125
125
|
|
126
126
|
def prompt_to_confirm!
|
127
|
-
|
128
|
-
|
127
|
+
prompt_user("Do you want to proceed (y/N)?", default: "Y") do |response|
|
128
|
+
exit(1) unless response.upcase.start_with?("Y")
|
129
|
+
end
|
129
130
|
end
|
130
131
|
|
131
132
|
end
|
data/lib/eco/cli.rb
CHANGED
@@ -23,16 +23,6 @@ module Eco
|
|
23
23
|
def run(session:)
|
24
24
|
io = Eco::API::UseCases::BaseIO.new(session: session, options: options)
|
25
25
|
session.workflow(io: io).run(io: io)
|
26
|
-
#session.workflow(io: io) do |wf, io|
|
27
|
-
# io = wf.run(:options, io: io)
|
28
|
-
# io = wf.run(:load, io: io)
|
29
|
-
# io = wf.run(:usecases, io: io)
|
30
|
-
# io = wf.run(:launch_jobs, io: io)
|
31
|
-
# io = wf.run(:post_launch, io: io)
|
32
|
-
# io = wf.run(:report, io: io)
|
33
|
-
# io = wf.run(:end, io: io)
|
34
|
-
# io = wf.run(:close, io: io)
|
35
|
-
#end
|
36
26
|
end
|
37
27
|
|
38
28
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
ASSETS.cli.config do |cnf|
|
2
2
|
cnf.options_set do |options_set, options|
|
3
|
-
options_set.add("--help", "
|
3
|
+
options_set.add("--help", "Offers a HELP") do |options, sesssion|
|
4
4
|
conf = ASSETS.cli.config
|
5
5
|
puts conf.people_filters.help if hpf = SCR.get_arg("-filters")
|
6
6
|
puts conf.input_filters.help if hif = SCR.get_arg("-input-filters")
|
@@ -11,12 +11,14 @@ ASSETS.cli.config do |cnf|
|
|
11
11
|
" -filters to display available filters on people",
|
12
12
|
" -input-filters to display available filters on input data",
|
13
13
|
" -options to dislpay available options",
|
14
|
-
" -usecases to display available usecases"
|
14
|
+
" -usecases to display available usecases",
|
15
|
+
"",
|
16
|
+
"You may specify the usecase to know its specific options by: -usecase_name --help -options"
|
15
17
|
].join("\n") unless hpf || hif || ho || huc
|
16
18
|
exit
|
17
19
|
end
|
18
20
|
|
19
|
-
desc = "
|
21
|
+
desc = "Fix the current session to work with this schema"
|
20
22
|
options_set.add("-schema-id", desc) do |options, session|
|
21
23
|
sch_name = SCR.get_arg("-schema-id", with_param: true)
|
22
24
|
sch_id = session.schemas.to_id(sch_name)
|
@@ -33,67 +35,68 @@ ASSETS.cli.config do |cnf|
|
|
33
35
|
session.schema = sch_id
|
34
36
|
end
|
35
37
|
|
36
|
-
desc
|
38
|
+
desc = "Used to be used to specify the input file when using -get-partial. "
|
39
|
+
desc += "It can also be useful to obtain `-get-partial` of people base on `:export` use cases (i.e. -people-to-csv)"
|
37
40
|
options_set.add("-entries-from", desc) do |options, session|
|
38
41
|
options.deep_merge!(input: {entries_from: true})
|
39
42
|
end
|
40
43
|
|
41
|
-
desc = "
|
44
|
+
desc = "Locally cache all the people manager by retrieving from the server"
|
42
45
|
options_set.add("-get-people", desc) do |options, session|
|
43
46
|
options.deep_merge!(people: {
|
44
47
|
get: {from: :remote, type: :full}
|
45
48
|
})
|
46
49
|
end
|
47
50
|
|
48
|
-
options_set.add(["-dry-run", "-simulate"], "
|
51
|
+
options_set.add(["-dry-run", "-simulate"], "Runs in dry-run (no requests sent to server)") do |options, session|
|
49
52
|
options[:dry_run] = true
|
50
53
|
options[:simulate] = true
|
51
54
|
session.config.dry_run!
|
52
55
|
end
|
53
56
|
|
54
|
-
desc = "
|
57
|
+
desc = "Ignores threshold limitations on requests for this session (skip batch belt)"
|
55
58
|
options_set.add("-skip-batch-policy", desc) do |options|
|
56
59
|
options.deep_merge!(skip: {batch_policy: true})
|
57
60
|
end
|
58
61
|
|
59
|
-
desc = "
|
62
|
+
desc = "Will not run the api policies defined for the enviro"
|
60
63
|
options_set.add("-skip-api-policies", desc) do |options|
|
61
64
|
options.deep_merge!(skip: {api_policies: true})
|
62
65
|
end
|
63
66
|
|
64
|
-
options_set.add("-feed-only-stats", "
|
67
|
+
options_set.add("-feed-only-stats", "Shows only stats when giving feedback") do |options|
|
65
68
|
options.deep_merge!(feedback: {only_stats: true})
|
66
69
|
end
|
67
70
|
|
68
|
-
desc = "
|
71
|
+
desc = "Deprecated: used to be used to avoid reloading people after launch"
|
69
72
|
options[:end_get] = true
|
70
73
|
options_set.add("-no-get", desc) do |options|
|
71
74
|
options[:end_get] = false
|
72
75
|
end
|
73
76
|
|
74
|
-
desc = "
|
77
|
+
desc = "Force search mode to 'strict' when pairing input entries with existing people."
|
75
78
|
desc += " Besides id and external_id it will not try to find by email unless external_id is not specified"
|
76
79
|
options_set.add("-search-strict", desc) do |options|
|
77
80
|
options.deep_merge!(search: {strict: true})
|
78
81
|
end
|
79
82
|
|
80
|
-
desc = "
|
83
|
+
desc = "Search mode that will try to find people using email when id and external_id have failed"
|
81
84
|
desc += " This option could identify existing people by their email addresses"
|
82
85
|
desc += " (it should not be used in orgs where multiple people usually have the same email address)"
|
83
86
|
options_set.add("-search-soft", desc) do |options|
|
84
87
|
options.deep_merge!(search: {soft: true, strict: false})
|
85
88
|
end
|
86
89
|
|
87
|
-
desc = "
|
90
|
+
desc = "Silence notifications on account creation or invites"
|
88
91
|
options_set.add(["-no-invites", "-exclude-invites"], desc) do |options|
|
89
92
|
options.merge!(send_invites: false)
|
90
93
|
end
|
91
|
-
desc = "
|
94
|
+
desc = "People with account will be reinvited if they haven't accepted the invitation"
|
92
95
|
options_set.add("-send-invites", desc) do |options|
|
93
96
|
options.merge!(send_invites: true)
|
94
97
|
end
|
95
98
|
|
96
|
-
options_set.add("-exclude-core", "
|
99
|
+
options_set.add("-exclude-core", "Core input data is not used on the update") do |options|
|
97
100
|
options.deep_merge!(exclude: {core: true})
|
98
101
|
end
|
99
102
|
options_set.add("-exclude-filter-tags", "filter_tags is not set with the input data") do |options|
|
@@ -112,11 +115,11 @@ ASSETS.cli.config do |cnf|
|
|
112
115
|
options.deep_merge!(exclude: {name: true})
|
113
116
|
end
|
114
117
|
|
115
|
-
options_set.add("-exclude-details", "
|
118
|
+
options_set.add("-exclude-details", "Details are not set with the input data") do |options|
|
116
119
|
options.deep_merge!(exclude: {details: true})
|
117
120
|
end
|
118
121
|
|
119
|
-
options_set.add("-exclude-account", "
|
122
|
+
options_set.add("-exclude-account", "Account is not set with the input data") do |options|
|
120
123
|
options.deep_merge!(exclude: {account: true})
|
121
124
|
end
|
122
125
|
options_set.add("-exclude-policy-groups", "policy_group_ids is not set with the input data") do |options|
|
@@ -52,7 +52,7 @@ ASSETS.cli.config do |cnf|
|
|
52
52
|
|
53
53
|
desc = "only those that have ALL the specified tags separated by '|'"
|
54
54
|
filters.add("-filter-tags-all", desc) do |people, session, options|
|
55
|
-
tags = SCR.get_arg("-filter-tags-all", with_param: true).upcase.split("|")
|
55
|
+
tags = SCR.get_arg("-filter-tags-all", with_param: true).upcase.split("|").compact
|
56
56
|
options.deep_merge!(input: {filter: {filter_tags: {any: tags}}})
|
57
57
|
people.filter_tags_all(tags).tap do |filtered|
|
58
58
|
msg = "Filtered #{filtered.count} people (out of #{people.count}) with 'all' filter_tags #{tags}"
|
@@ -62,7 +62,7 @@ ASSETS.cli.config do |cnf|
|
|
62
62
|
|
63
63
|
desc = "only those that have ANY the specified tags separated by '|'"
|
64
64
|
filters.add("-filter-tags-any", desc) do |people, session, options|
|
65
|
-
tags = SCR.get_arg("-filter-tags-any", with_param: true).upcase.split("|")
|
65
|
+
tags = SCR.get_arg("-filter-tags-any", with_param: true).upcase.split("|").compact
|
66
66
|
options.deep_merge!(input: {filter: {filter_tags_any: tags}})
|
67
67
|
people.filter_tags_any(tags).tap do |filtered|
|
68
68
|
msg = "Filtered #{filtered.count} people (out of #{people.count}) with 'any' filter_tags #{tags}"
|
@@ -72,7 +72,7 @@ ASSETS.cli.config do |cnf|
|
|
72
72
|
|
73
73
|
desc = "only those that have ANY tag in the specified subtrees separated by '|'"
|
74
74
|
filters.add("-filter-tags-tree", desc) do |people, session, options|
|
75
|
-
top_tags = SCR.get_arg("-filter-tags-tree", with_param: true).upcase.split("|")
|
75
|
+
top_tags = SCR.get_arg("-filter-tags-tree", with_param: true).upcase.split("|").compact
|
76
76
|
tags = top_tags.each_with_object([]) do |top, tags|
|
77
77
|
tags.concat(session.tagtree.node(top).tags)
|
78
78
|
end.uniq
|
@@ -1,27 +1,74 @@
|
|
1
1
|
ASSETS.cli.config do |cnf|
|
2
2
|
cnf.usecases do |cases|
|
3
3
|
|
4
|
+
desc = "Draws the Supervisors hiearchy in a file"
|
5
|
+
cases.add("-supers-hierarchy", :export, desc, case_name: "supers-hierarchy") do |people, session, options|
|
6
|
+
options.deep_merge!(output: {file: "supers_hierarchy.txt"}) unless options.dig(:output, :file)
|
7
|
+
end.add_option("-to", "Specify the output file") do |options|
|
8
|
+
file = SCR.get_file("-to", required: true, should_exist: false)
|
9
|
+
options.deep_merge!(output: {file: file})
|
10
|
+
end
|
11
|
+
|
12
|
+
desc = "Draws the Cyclic Supervisors when identified"
|
13
|
+
cases.add("-identify-cyclic-supers", :export, desc, case_name: "identify-cyclic-supers") do |people, session, options|
|
14
|
+
options.deep_merge!(output: {file: "cyclic_supers.txt"}) unless options.dig(:output, :file)
|
15
|
+
end.add_option("-to", "Specify the output file") do |options|
|
16
|
+
file = SCR.get_file("-to", required: true, should_exist: false)
|
17
|
+
options.deep_merge!(output: {file: file})
|
18
|
+
end
|
19
|
+
|
20
|
+
desc = "Abstracts the Abilities that each Usergroup should probably have"
|
21
|
+
cases.add("-abstract-policygroup-abilities", :export, desc, case_name: "abstract-policygroup-abilities") do |people, session, options|
|
22
|
+
options.deep_merge!(output: {file: "suggested_usergroup_abilities.txt"}) unless options.dig(:output, :file)
|
23
|
+
end.add_option("-to", "Specify the output file") do |options|
|
24
|
+
file = SCR.get_file("-to", required: true, should_exist: false)
|
25
|
+
options.deep_merge!(output: {file: file})
|
26
|
+
end
|
27
|
+
|
28
|
+
desc = "Provides a set of tools to analyse a set of people (i.e. detect duplicates)"
|
29
|
+
cases.add("-analyse-people", :export, desc, case_name: "-analyse-people") do |people, session, options|
|
30
|
+
options.deep_merge!(output: {file: "people_analysis.txt"}) unless options.dig(:output, :file)
|
31
|
+
end.add_option("-to", "Specify the output file") do |options|
|
32
|
+
file = SCR.get_file("-to", required: true, should_exist: false)
|
33
|
+
options.deep_merge!(output: {file: file})
|
34
|
+
end
|
35
|
+
|
4
36
|
desc = "It exports to a CSV the (filtered) people"
|
5
37
|
cases.add("-people-to-csv", :export, desc) do |people, session, options|
|
6
38
|
file = SCR.get_file("-people-to-csv", required: true, should_exist: false)
|
7
39
|
options.deep_merge!(export: {file: {name: file, format: :csv}})
|
8
|
-
|
9
|
-
options.
|
10
|
-
case_name = SCR.get_arg("-detailed")? "to-csv-detailed" : "to-csv"
|
40
|
+
|
41
|
+
case_name = options.dig(:export, :options, :detailed) ? "to-csv-detailed" : "to-csv"
|
11
42
|
session.usecases.case(case_name)
|
43
|
+
end.add_option("-nice-header", "Outputs more descriptive standard headers") do |options|
|
44
|
+
options.deep_merge!(export: {options: {nice_header: true}})
|
45
|
+
end.add_option("-internal-names", "It is the most raw export. Useful to see all the data when name mappings override/overlap") do |options|
|
46
|
+
options.deep_merge!(export: {options: {internal_names: true}})
|
47
|
+
end.add_option("-detailed", "Includes much more information to the file (i.e. permissions_merged abilities, preferences)") do |options|
|
48
|
+
options.deep_merge!(export: {options: {detailed: true}})
|
49
|
+
end.add_option("-permissions-custom", "Used with -detailed. Adds the permissions_custom abilities") do |options|
|
50
|
+
options.deep_merge!(export: {options: {permissions_custom: true}})
|
51
|
+
end.add_option("-split-schemas", "It will generate 1 file per each schema") do |options|
|
52
|
+
options.deep_merge!(export: {options: {split_schemas: true}})
|
12
53
|
end
|
13
54
|
|
14
55
|
desc = "Adds a column 'ecoPortalTag' to the input CSV with the tags that the location codes map to"
|
15
|
-
cases.add("-codes-to-tags-from", :other, desc, case_name: "codes-to-tags-from")
|
56
|
+
cases.add("-codes-to-tags-from", :other, desc, case_name: "codes-to-tags-from")
|
57
|
+
.add_option("-codes-to-tags-from", "Specify the input 'csv' file") do |options|
|
16
58
|
file = SCR.get_file("-codes-to-tags-from", required: true, should_exist: true)
|
17
59
|
options.deep_merge!(other: {file: {name: file, format: :csv}})
|
18
|
-
|
60
|
+
end.add_option("-column", "Specify the input column header with the codes") do |options|
|
19
61
|
col_codes = SCR.get_arg("-column", with_param: true)
|
20
62
|
options.deep_merge!(other: {file: {codes_column: col_codes}})
|
21
63
|
end
|
22
64
|
|
23
|
-
desc = "Removes the landing page"
|
65
|
+
desc = "Removes the landing page or sets it to -page-id"
|
24
66
|
cases.add("-reset-landing-page", :transform, desc, case_name: "reset-landing-page")
|
67
|
+
.add_option("-page-id", "Target landing page to set to the users") do |options|
|
68
|
+
SCR.get_arg("-page-id", with_param: true).tap do |new_id|
|
69
|
+
options.deep_merge!({page_id: new_id})
|
70
|
+
end
|
71
|
+
end
|
25
72
|
|
26
73
|
desc = "Sets as external_id the email of the person"
|
27
74
|
cases.add("-email-as-id", :transform, desc, case_name: "email-as-id")
|
@@ -36,23 +83,29 @@ ASSETS.cli.config do |cnf|
|
|
36
83
|
|
37
84
|
desc = "Sets the supervisor_id"
|
38
85
|
cases.add("-set-supervisor-from", :sync, desc, case_name: "set-supervisor")
|
86
|
+
|
39
87
|
desc = "Sets to -new-super the supervisor_id of the -old-super's subordinates"
|
40
88
|
cases.add("-switch-supervisor", :transform, desc, case_name: "switch-supervisor") do |people, session, options|
|
41
|
-
unless
|
89
|
+
unless options[:super]&.key?(:old)
|
42
90
|
msg = "You must specify an -old-super to target whose supervisor is changing"
|
43
91
|
session.logger.error(msg)
|
44
92
|
exit(1)
|
45
93
|
end
|
46
|
-
|
47
|
-
options.deep_merge!(super: {old: old_id})
|
48
|
-
|
49
|
-
unless new_id = SCR.get_arg("-new-super", with_param: true)
|
94
|
+
unless options[:super]&.key?(:new)
|
50
95
|
msg = "You must specify the -new-super id. To reset to nil the supervisor, please, specify nil."
|
51
96
|
session.logger.error(msg)
|
52
97
|
exit(1)
|
53
98
|
end
|
54
|
-
|
55
|
-
|
99
|
+
end.add_option("-old-super", "The supervisor id to be replaced on the subordinates") do |options|
|
100
|
+
if old_id = SCR.get_arg("-old-super", with_param: true)
|
101
|
+
old_id = old_id == "nil"? nil : old_id
|
102
|
+
options.deep_merge!(super: {old: old_id})
|
103
|
+
end
|
104
|
+
end.add_option("-new-super", "The new supervisor id") do |options|
|
105
|
+
if new_id = SCR.get_arg("-new-super", with_param: true)
|
106
|
+
new_id = new_id == "nil"? nil : new_id
|
107
|
+
options.deep_merge!(super: {new: new_id})
|
108
|
+
end
|
56
109
|
end
|
57
110
|
|
58
111
|
desc = "Usage '-org-data-convert backup.json -restore-db-from'."
|
@@ -65,15 +118,15 @@ ASSETS.cli.config do |cnf|
|
|
65
118
|
session.logger.info("Source DB: loaded #{input.length} entries.")
|
66
119
|
end
|
67
120
|
|
68
|
-
|
69
|
-
options.merge!(source_enviro: source_enviro)
|
70
|
-
else
|
121
|
+
unless options[:source_enviro]
|
71
122
|
session.logger.error("You need to specify a -source-enviro for the conversion to work out")
|
72
123
|
exit(1)
|
73
124
|
end
|
74
125
|
|
75
|
-
|
76
|
-
|
126
|
+
end.add_option("-source-enviro", "The defined -source-enviro API configuration that the backup file was generated from") do |options|
|
127
|
+
options.merge!(source_enviro: SCR.get_arg("-source-enviro", with_param: true))
|
128
|
+
end.add_option("-ignore-missing-policy-groups", "Prevents the script to crash when backup file has missing usergroups in the org") do |options|
|
129
|
+
options.deep_merge!(ignore: {missing: {policy_groups: true}})
|
77
130
|
end
|
78
131
|
|
79
132
|
desc = "Restores the people manager by using a backup.json file"
|
@@ -83,13 +136,15 @@ ASSETS.cli.config do |cnf|
|
|
83
136
|
input = Eco::API::Organization::People.new(JSON.parse(File.read(file)))
|
84
137
|
session.logger.info("Source DB: loaded #{input.length} entries.")
|
85
138
|
end
|
86
|
-
|
87
|
-
options.deep_merge!(include: {delete: true})
|
88
|
-
|
139
|
+
end.add_option("-include-delete", "If it should DELETE people that do not exist in the backup file") do |options|
|
140
|
+
options.deep_merge!(include: {delete: true})
|
141
|
+
end.add_option("-include-create", "If it should CREATE people that do not exist in the people manager") do |options|
|
142
|
+
options.deep_merge!(include: {create: true})
|
89
143
|
end
|
90
144
|
|
91
145
|
desc = "Re-sends invites to all filtered users that have not accepted the invite as yet"
|
92
146
|
cases.add("-reinvite", :transform, desc, case_name: "reinvite")
|
147
|
+
|
93
148
|
desc = "Re-sends invites to target users that have not accepted the invite as yet"
|
94
149
|
cases.add("-reinvite-from", :sync, desc, case_name: "reinvite")
|
95
150
|
|
@@ -112,8 +167,6 @@ ASSETS.cli.config do |cnf|
|
|
112
167
|
|
113
168
|
desc = "It just adds everybody to an update job without doing any change. If the org has policies, it will refresh"
|
114
169
|
cases.add("-refresh", :transform, desc, case_name: "refresh")
|
115
|
-
desc = "Remaps the abilities of every user based on their usergroups mappings thereof in the org api configuration"
|
116
|
-
cases.add("-refresh-abilities", :transform, desc, case_name: "refresh-abilities")
|
117
170
|
|
118
171
|
desc = "Updates details and core (including supervisor) to target people"
|
119
172
|
cases.add("-update-details-from", :sync, desc, case_name: "update-details")
|
@@ -123,9 +176,10 @@ ASSETS.cli.config do |cnf|
|
|
123
176
|
desc = "Updates the people specified in the input data"
|
124
177
|
cases.add("-update-from", :sync, desc, case_name: "update")
|
125
178
|
|
126
|
-
desc = "Does an actual transfer of
|
127
|
-
cases.add("-transfer-account-from", :sync, desc, case_name: "transfer-account")
|
128
|
-
|
179
|
+
desc = "Does an actual transfer of USER from id|external_id account to 'destination-id' person"
|
180
|
+
cases.add("-transfer-account-from", :sync, desc, case_name: "transfer-account")
|
181
|
+
.add_option("-include-email", "Specifies if the email should also be moved. Otherwise it only moves the account") do |options|
|
182
|
+
options.deep_merge!(include: {email: true})
|
129
183
|
end
|
130
184
|
|
131
185
|
desc = "Tries to find the input entries and update them. It creates them if not found"
|
@@ -2,10 +2,19 @@ ASSETS.cli.config do |config|
|
|
2
2
|
ASSETS.config.workflow do |wf|
|
3
3
|
|
4
4
|
io = nil
|
5
|
+
rescued = false
|
6
|
+
|
5
7
|
# default rescue
|
6
8
|
wf.rescue do |exception, io|
|
7
|
-
|
8
|
-
|
9
|
+
begin
|
10
|
+
next io if rescued
|
11
|
+
rescued = true
|
12
|
+
|
13
|
+
io.session.logger.debug(exception.patch_full_message)
|
14
|
+
wf.run(:close, io: io)
|
15
|
+
rescue Exception => e
|
16
|
+
puts "Some problem in workflow.rescue: #{e}"
|
17
|
+
end
|
9
18
|
io
|
10
19
|
end
|
11
20
|
|
@@ -19,12 +28,15 @@ ASSETS.cli.config do |config|
|
|
19
28
|
cases_with_input = config.usecases.active(io: io).select do |usecase, data|
|
20
29
|
io.class.input_required?(usecase.type)
|
21
30
|
end
|
22
|
-
|
31
|
+
|
32
|
+
input_is_required = !cases_with_input.empty? || io.options.dig(:input, :entries_from)
|
33
|
+
missing_input = !io.input || io.input.empty?
|
34
|
+
next io unless missing_input && input_is_required
|
23
35
|
|
24
36
|
if io.options.dig(:input, :entries_from)
|
25
37
|
io = io.new(input: config.input.get(io: io))
|
26
38
|
else
|
27
|
-
opt_case = cases_with_input.values.first
|
39
|
+
opt_case = cases_with_input.values.first.option
|
28
40
|
io = io.new(input: config.input.get(io: io, option: opt_case))
|
29
41
|
end
|
30
42
|
io
|
data/lib/eco/cli/config/help.rb
CHANGED
@@ -16,6 +16,7 @@ module Eco
|
|
16
16
|
# Creatas a well aligned line
|
17
17
|
def help_line(key, desc, keys_max_len = key.length, line_len = 100)
|
18
18
|
blanks = keys_max_len + 3 - key.length
|
19
|
+
blanks = blanks < 0 ? 0 : blanks
|
19
20
|
top_line = " #{key}#{" "*blanks} "
|
20
21
|
indent = top_line.length
|
21
22
|
first = true
|
@@ -5,31 +5,53 @@ module Eco
|
|
5
5
|
include Eco::CLI::Config::Help
|
6
6
|
attr_reader :core_config
|
7
7
|
|
8
|
+
class OptConfig < Struct.new(:name, :namespace, :description, :callback)
|
9
|
+
end
|
10
|
+
|
8
11
|
def initialize(core_config:)
|
9
12
|
@core_config = core_config
|
10
|
-
@
|
11
|
-
@description = {}
|
13
|
+
@sets = {}
|
12
14
|
end
|
13
15
|
|
14
16
|
# @return [String] summary of the options.
|
15
17
|
def help
|
18
|
+
indent = 2
|
19
|
+
spaces = any_non_general_space_active? ? active_namespaces : namespaces
|
20
|
+
|
16
21
|
["The following are the available options:"].yield_self do |lines|
|
17
|
-
max_len = keys_max_len(
|
18
|
-
|
19
|
-
|
22
|
+
max_len = keys_max_len(options_args(spaces)) + indent
|
23
|
+
spaces.each do |namespace|
|
24
|
+
is_general = (namespace == :general)
|
25
|
+
str_indent = is_general ? "" : " " * indent
|
26
|
+
lines << help_line(namespace, "", max_len) unless is_general
|
27
|
+
options_set(namespace).each do |arg, option|
|
28
|
+
lines << help_line(" " * indent + "#{option.name}", option.description, max_len)
|
29
|
+
end
|
20
30
|
end
|
21
31
|
lines
|
22
32
|
end.join("\n")
|
23
33
|
end
|
24
34
|
|
25
|
-
# @
|
35
|
+
# @return [Array<String>] all the argument of the options in `namespaces`
|
36
|
+
def options_args(namespaces)
|
37
|
+
namespaces.each_with_object([]) do |space, args|
|
38
|
+
args.concat(options_set(space).keys)
|
39
|
+
end.uniq
|
40
|
+
end
|
41
|
+
|
42
|
+
# @param option [String, Array<String>] the command line option(s).
|
43
|
+
# @param namespace [String] preceding command(s) argument that enables this option.
|
26
44
|
# @param desc [String] description of the option.
|
27
|
-
def add(option, desc = nil)
|
45
|
+
def add(option, desc = nil, namespace: :general)
|
28
46
|
raise "Missing block to define the options builder" unless block_given?
|
29
|
-
|
30
|
-
[option].flatten.compact
|
31
|
-
|
32
|
-
|
47
|
+
|
48
|
+
opts = [option].flatten.compact
|
49
|
+
unless opts.empty?
|
50
|
+
callback = Proc.new
|
51
|
+
opts.each do |opt|
|
52
|
+
puts "Overriding option '#{option}' in '#{namespace}' namespace" if option_exists?(opt, namespace)
|
53
|
+
options_set(namespace)[opt] = OptConfig.new(opt, namespace, desc, callback)
|
54
|
+
end
|
33
55
|
end
|
34
56
|
self
|
35
57
|
end
|
@@ -39,12 +61,83 @@ module Eco
|
|
39
61
|
raise "You need to provide Eco::API::UseCases::BaseIO object. Given: #{io.class}"
|
40
62
|
end
|
41
63
|
|
42
|
-
|
43
|
-
callback.call(io.options, io.session)
|
64
|
+
active_options.each do |option|
|
65
|
+
option.callback.call(io.options, io.session)
|
44
66
|
end
|
67
|
+
|
45
68
|
io.options
|
46
69
|
end
|
47
70
|
|
71
|
+
def active_options
|
72
|
+
@active_options ||= sets.select do |namespace, opts_set|
|
73
|
+
active_namespace?(namespace)
|
74
|
+
end.each_with_object([]) do |(namespace, opts_set), options|
|
75
|
+
opts_set.each do |arg, option|
|
76
|
+
options << option if active_option?(arg, namespace)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def all_options
|
82
|
+
sets.each_with_object([]) do |(namespace, opts_set), options|
|
83
|
+
options << opts_set.values
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def namespaces
|
88
|
+
sets.keys.sort_by do |key|
|
89
|
+
key == :general
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def any_non_general_space_active?
|
94
|
+
(active_namespaces - [:general]).length > 0
|
95
|
+
end
|
96
|
+
|
97
|
+
def active_namespaces
|
98
|
+
@active_namespaces ||= [].tap do |active|
|
99
|
+
active << :general
|
100
|
+
other = (namespaces - [:general]).select {|nm| SCR.arg?(nm)}
|
101
|
+
active.concat(other)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
|
106
|
+
private
|
107
|
+
|
108
|
+
def active_namespace?(namespace)
|
109
|
+
(namespace == :general) || SCR.get_arg(namespace)
|
110
|
+
end
|
111
|
+
|
112
|
+
# Is the option active?
|
113
|
+
# 1. If :general namespace, it does just a direct check
|
114
|
+
# 2. Otherwise, the `namespace` wording should come first in the `cli` or it is considered inactive
|
115
|
+
def active_option?(opt, namespace = :general)
|
116
|
+
if namespace == :general
|
117
|
+
SCR.get_arg(opt)
|
118
|
+
else
|
119
|
+
active_namespace?(namespace) && SCR.arg_order?(namespace, opt) && SCR.get_arg(opt)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
def option_exists?(opt, namespace = :general)
|
124
|
+
options_set(namespace).key?(opt)
|
125
|
+
end
|
126
|
+
|
127
|
+
def sets
|
128
|
+
@sets ||= {
|
129
|
+
general: {}
|
130
|
+
}
|
131
|
+
end
|
132
|
+
|
133
|
+
def namespaces
|
134
|
+
@sets.keys
|
135
|
+
end
|
136
|
+
|
137
|
+
def options_set(namespace = :general)
|
138
|
+
@sets[namespace] ||= {}
|
139
|
+
end
|
140
|
+
|
48
141
|
end
|
49
142
|
end
|
50
143
|
end
|