eco-helpers 2.5.10 → 2.6.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (136) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -2
  3. data/CHANGELOG.md +132 -4
  4. data/README.md +5 -0
  5. data/eco-helpers.gemspec +20 -16
  6. data/lib/eco/api/common/class_helpers.rb +1 -1
  7. data/lib/eco/api/common/loaders/base.rb +2 -9
  8. data/lib/eco/api/common/loaders/case_base.rb +0 -2
  9. data/lib/eco/api/common/loaders/config/workflow/mailer.rb +78 -0
  10. data/lib/eco/api/common/loaders/config/workflow.rb +11 -0
  11. data/lib/eco/api/common/loaders/config.rb +29 -0
  12. data/lib/eco/api/common/loaders/error_handler.rb +0 -2
  13. data/lib/eco/api/common/loaders/parser.rb +0 -1
  14. data/lib/eco/api/common/loaders/policy.rb +0 -2
  15. data/lib/eco/api/common/loaders/use_case.rb +27 -1
  16. data/lib/eco/api/common/loaders.rb +1 -0
  17. data/lib/eco/api/common/people/default_parsers.rb +2 -2
  18. data/lib/eco/api/common/people/person_entry.rb +3 -0
  19. data/lib/eco/api/common/people/person_entry_attribute_mapper.rb +111 -16
  20. data/lib/eco/api/common/session/base_session.rb +4 -0
  21. data/lib/eco/api/common/session/environment.rb +4 -0
  22. data/lib/eco/api/common/session/mailer.rb +3 -1
  23. data/lib/eco/api/common/session/sftp.rb +1 -1
  24. data/lib/eco/api/common/version_patches/exception.rb +2 -2
  25. data/lib/eco/api/common/version_patches/ruby3/object.rb +18 -0
  26. data/lib/eco/api/common/version_patches/ruby3.rb +1 -0
  27. data/lib/eco/api/common/version_patches.rb +3 -0
  28. data/lib/eco/api/custom/config.rb +10 -0
  29. data/lib/eco/api/custom/mailer.rb +9 -0
  30. data/lib/eco/api/custom/namespace.rb +2 -0
  31. data/lib/eco/api/custom/workflow.rb +9 -0
  32. data/lib/eco/api/custom.rb +3 -0
  33. data/lib/eco/api/organization/tag_tree.rb +20 -23
  34. data/lib/eco/api/session/batch/base_policy.rb +13 -5
  35. data/lib/eco/api/session/batch/job.rb +14 -11
  36. data/lib/eco/api/session/batch/jobs.rb +2 -2
  37. data/lib/eco/api/session/batch/jobs_groups.rb +2 -2
  38. data/lib/eco/api/session/config/files.rb +2 -2
  39. data/lib/eco/api/session/config/people.rb +2 -2
  40. data/lib/eco/api/session/config/sftp.rb +4 -0
  41. data/lib/eco/api/session/config/tagtree.rb +9 -8
  42. data/lib/eco/api/session/config/workflow.rb +95 -58
  43. data/lib/eco/api/session/config.rb +9 -2
  44. data/lib/eco/api/session.rb +17 -2
  45. data/lib/eco/api/usecases/base_io.rb +50 -4
  46. data/lib/eco/api/usecases/cli/dsl.rb +94 -0
  47. data/lib/eco/api/usecases/cli/option.rb +19 -0
  48. data/lib/eco/api/usecases/cli.rb +13 -0
  49. data/lib/eco/api/usecases/default/locations/cli/tagtree_extract_cli.rb +29 -0
  50. data/lib/eco/api/usecases/{default_cases → default/locations}/codes_to_tags_case.rb +1 -1
  51. data/lib/eco/api/usecases/{default_cases → default/locations}/create_tag_paths_case.rb +1 -1
  52. data/lib/eco/api/usecases/{default_cases → default/locations}/csv_to_tree_case.rb +1 -1
  53. data/lib/eco/api/usecases/default/locations/tagtree_extract_case.rb +181 -0
  54. data/lib/eco/api/usecases/default/locations.rb +15 -0
  55. data/lib/eco/api/usecases/{default_cases → default/people}/analyse_people_case.rb +1 -1
  56. data/lib/eco/api/usecases/{default_cases → default/people}/change_email_case.rb +1 -1
  57. data/lib/eco/api/usecases/default/people/clean_unknown_tags_case.rb +66 -0
  58. data/lib/eco/api/usecases/{default_cases → default/people}/clear_abilities_case.rb +1 -1
  59. data/lib/eco/api/usecases/{default_cases → default/people}/org_data_convert_case.rb +1 -1
  60. data/lib/eco/api/usecases/{default_cases → default/people}/refresh_case.rb +1 -1
  61. data/lib/eco/api/usecases/{default_cases → default/people}/reinvite_sync_case.rb +1 -1
  62. data/lib/eco/api/usecases/{default_cases → default/people}/reinvite_trans_case.rb +1 -1
  63. data/lib/eco/api/usecases/default/people/reinvite_trans_cli.rb +5 -0
  64. data/lib/eco/api/usecases/{default_cases → default/people}/restore_db_case.rb +1 -1
  65. data/lib/eco/api/usecases/{default_cases → default/people}/set_default_tag_case.rb +1 -1
  66. data/lib/eco/api/usecases/{default_cases → default/people}/supers_cyclic_identify_case.rb +1 -1
  67. data/lib/eco/api/usecases/{default_cases → default/people}/supers_hierarchy_case.rb +1 -1
  68. data/lib/eco/api/usecases/{default_cases → default/people}/switch_supervisor_case.rb +1 -1
  69. data/lib/eco/api/usecases/{default_cases → default/people}/transfer_account_case.rb +1 -1
  70. data/lib/eco/api/usecases/default/people.rb +25 -0
  71. data/lib/eco/api/usecases/default.rb +16 -0
  72. data/lib/eco/api/usecases/default_cases/samples/cli/sftp_cli.rb +46 -0
  73. data/lib/eco/api/usecases/default_cases/samples/sftp_case.rb +21 -9
  74. data/lib/eco/api/usecases/default_cases.rb +2 -30
  75. data/lib/eco/api/usecases/graphql/helpers/location/base.rb +1 -2
  76. data/lib/eco/api/usecases/graphql/utils/sftp.rb +1 -1
  77. data/lib/eco/api/usecases/ooze_samples/register_update_case.rb +3 -3
  78. data/lib/eco/api/usecases/use_case.rb +31 -7
  79. data/lib/eco/api/usecases/use_case_chain.rb +2 -2
  80. data/lib/eco/api/usecases.rb +4 -1
  81. data/lib/eco/assets.rb +3 -5
  82. data/lib/eco/cli/config/filters/people_filters.rb +0 -1
  83. data/lib/eco/cli/config/filters.rb +2 -6
  84. data/lib/eco/cli/config/help.rb +0 -1
  85. data/lib/eco/cli/config/input.rb +0 -1
  86. data/lib/eco/cli/config/options_set.rb +3 -4
  87. data/lib/eco/cli/config/use_cases.rb +13 -6
  88. data/lib/eco/cli/config.rb +4 -5
  89. data/lib/eco/cli/scripting/args_helpers.rb +1 -1
  90. data/lib/eco/cli/scripting/argument.rb +0 -1
  91. data/lib/eco/cli/scripting/arguments.rb +0 -2
  92. data/lib/eco/cli.rb +0 -1
  93. data/lib/eco/{cli/config/default → cli_default}/input_filters.rb +0 -1
  94. data/lib/eco/{cli/config/default → cli_default}/people_filters.rb +0 -1
  95. data/lib/eco/{cli/config/default → cli_default}/usecases.rb +2 -52
  96. data/lib/eco/cli_default/workflow.rb +171 -0
  97. data/lib/eco/cli_default.rb +13 -0
  98. data/lib/eco/csv/table.rb +0 -1
  99. data/lib/eco/data/files/encoding.rb +1 -1
  100. data/lib/eco/data/files/helpers.rb +1 -1
  101. data/lib/eco/data/locations/convert.rb +8 -4
  102. data/lib/eco/data/locations/node_base/csv_convert.rb +4 -4
  103. data/lib/eco/data/locations/node_base/tag_validations.rb +19 -9
  104. data/lib/eco/data/locations/node_base/treeify.rb +193 -18
  105. data/lib/eco/data/locations/node_level.rb +1 -1
  106. data/lib/eco/data/locations/node_plain/parsing.rb +1 -1
  107. data/lib/eco/data/locations/node_plain/serial.rb +1 -1
  108. data/lib/eco/data/locations/node_plain.rb +4 -3
  109. data/lib/eco/data/mapper.rb +6 -1
  110. data/lib/eco/language/klass/when_inherited.rb +17 -0
  111. data/lib/eco/language/klass.rb +8 -0
  112. data/lib/eco/language/methods/delegate_missing.rb +28 -0
  113. data/lib/eco/language/methods/dsl_able.rb +25 -0
  114. data/lib/eco/language/methods.rb +9 -0
  115. data/lib/eco/language.rb +2 -0
  116. data/lib/eco/version.rb +1 -1
  117. metadata +169 -79
  118. data/lib/eco/api/usecases/default_cases/abstract_policygroup_abilities_case.rb +0 -160
  119. data/lib/eco/api/usecases/default_cases/append_usergroups_case.rb +0 -14
  120. data/lib/eco/api/usecases/default_cases/clean_unknown_tags_case.rb +0 -74
  121. data/lib/eco/api/usecases/default_cases/create_details_case.rb +0 -20
  122. data/lib/eco/api/usecases/default_cases/create_details_with_supervisor_case.rb +0 -21
  123. data/lib/eco/api/usecases/default_cases/email_as_id_case.rb +0 -12
  124. data/lib/eco/api/usecases/default_cases/new_email_case.rb +0 -13
  125. data/lib/eco/api/usecases/default_cases/new_id_case.rb +0 -12
  126. data/lib/eco/api/usecases/default_cases/remove_account_sync_case.rb +0 -10
  127. data/lib/eco/api/usecases/default_cases/remove_account_trans_case.rb +0 -16
  128. data/lib/eco/api/usecases/default_cases/reset_landing_page_case.rb +0 -18
  129. data/lib/eco/api/usecases/default_cases/set_supervisor_case.rb +0 -16
  130. data/lib/eco/api/usecases/default_cases/tagtree_case.rb +0 -42
  131. data/lib/eco/api/usecases/default_cases/update_details_case.rb +0 -15
  132. data/lib/eco/cli/config/default/workflow.rb +0 -188
  133. data/lib/eco/cli/config/default.rb +0 -16
  134. /data/lib/eco/{cli/config/default → cli_default}/input.rb +0 -0
  135. /data/lib/eco/{cli/config/default → cli_default}/options.rb +0 -0
  136. /data/lib/eco/{cli/config/default → cli_default}/people.rb +0 -0
@@ -1,160 +0,0 @@
1
- class Eco::API::UseCases::DefaultCases::AbstractPolicyGroupAbilities < Eco::API::Common::Loaders::UseCase
2
- name "abstract-policygroup-abilities"
3
- type :export
4
-
5
- attr_reader :people
6
-
7
- def main(people, session, options, usecase)
8
- options[:end_get] = false
9
- @people = people
10
-
11
- generate_csv!
12
- end
13
-
14
- private
15
-
16
- def file
17
- @file ||= options.dig(:output, :file) || "suggested_abilities.csv"
18
- end
19
-
20
- def generate_csv!
21
- policy_groups.each_with_object({}) do |group, data|
22
- data[group.id] ||= {}
23
- data[group.id][:name] = group.name
24
- data[group.id][:suggested] = group_suggestions(group.id)
25
- data[group.id][:percents] = group_abilities(group.id)
26
- end.yield_self do |data|
27
- abilities_list = Eco::API::Organization::PresetsFactory.abilities
28
- CSV.open(file, "w") do |csv|
29
- csv << ["Type", "UserGroup", "ID", *abilities_list]
30
- # Dump the final suggestions
31
- data.each do |id, meta|
32
- csv << ["Suggested", meta[:name], id, *meta[:suggested].values_at(*abilities_list)]
33
- end
34
- # Dump the percentaged levels of each ability
35
- data.each do |id, meta|
36
- analysis = meta[:percents].values_at(*abilities_list).each_with_object([]) do |levels, values|
37
- values << levels.map do |level, percentil|
38
- "#{level ? level : "null"} => #{percentil}"
39
- end.join("\n")
40
- end
41
- csv << ["Analysis", meta[:name], id, *analysis]
42
- end
43
- end
44
- puts "Generated file #{file}"
45
- end
46
- end
47
-
48
- def policy_groups
49
- @policy_groups ||= session.policy_groups
50
- end
51
-
52
- # Suggests 1 final set of abilities for a usergroup
53
- def group_suggestions(id)
54
- group_abilities(id).each_with_object({}) do |(key, levels), set|
55
- data = levels.to_a.sort_by(&:last).reverse.first
56
- set[key] = data ? data.shift : nil
57
- end
58
- end
59
-
60
- # Cleans up each ability's levels by:
61
- # 1. cutting at some minimum threshold percentage
62
- # 2. directly selecting those greater than 70%
63
- def group_abilities(id)
64
- @group_abilities ||= {}
65
- @group_abilities[id] ||= ability_levels_percent(id).each_with_object({}) do |(ability, levels), out|
66
- outstanding = nil
67
- levels.select do |level, percentil|
68
- outstanding ||= level if percentil >= 75
69
- percentil > 15
70
- end.yield_self do |filtered|
71
- out[ability] = outstanding ? filtered.slice(outstanding) : filtered
72
- end
73
- end
74
- end
75
-
76
- # With given the percentages of sets of abilities
77
- # it abstracts the percentage of each level of each ability
78
- def ability_levels_percent(id)
79
- @ability_levels_percent ||= {}
80
- @ability_levels_percent[id] ||= Eco::API::Organization::PresetsFactory.abilities.each_with_object({}) do |key, out|
81
- out[key] ||= {}
82
- ability_sets_percent(id).each_with_object(out[key]) do |(set, percentil), levels|
83
- levels[set[key]] ||= 0
84
- levels[set[key]] = (levels[set[key]] + percentil).round(2)
85
- end
86
- end
87
- end
88
-
89
- # Give a percentage to each set of abilities
90
- def ability_sets_percent(id)
91
- @ability_sets_percent ||= {}
92
- @ability_sets_percent[id] ||= scoped_relevant_raw_data(id).yield_self do |data|
93
- # Transform ability sets counter to percentage
94
- total = data[:count]
95
- abilities = data[:abilities]
96
- data[:abilities].transform_values do |val|
97
- percent(val, total)
98
- end
99
- end
100
- end
101
-
102
- # Get rid of data simingly irrelevant
103
- def scoped_relevant_raw_data(id)
104
- sp = single_percent(id)
105
- sing = single(id); mult = multiple(id)
106
-
107
- # Scope Relevant Raw Data
108
- case
109
- when sp >= 3 # >= 80
110
- sing
111
- #when sp < 15
112
- # mult
113
- else # combine
114
- all_abilities = sing[:abilities].keys | mult[:abilities].keys
115
- data = {count: sing[:count] + mult[:count], abilities: {}}
116
- all_abilities.each_with_object(data) do |abilities, merged|
117
- scount = sing[:abilities][abilities] || 0
118
- mcount = mult[:abilities][abilities] || 0
119
- merged[:abilities][abilities] = scount + mcount
120
- end
121
- end
122
- end
123
-
124
- def single_percent(id)
125
- percent(single(id)[:count], count(id))
126
- end
127
-
128
- def single(id)
129
- groups_abilities.dig(id, :single) || {count: 0, abilities: {}}
130
- end
131
-
132
- def multiple(id)
133
- groups_abilities.dig(id, :multiple) || {count: 0, abilities: {}}
134
- end
135
-
136
- def count(id)
137
- groups_abilities.dig(id, :count) || 0
138
- end
139
-
140
- def groups_abilities
141
- @groups_abilities ||= people.users.each_with_object({}) do |user, groups|
142
- abilities = Eco::API::Organization::PresetsFactory.all_abilities(user.account.permissions_custom)
143
- ids = user.account.policy_group_ids
144
- category = ids.count > 1 ? :multiple : :single
145
-
146
- ids.each do |id|
147
- groups[id] ||= {count: 0}
148
- groups[id][:count] += 1
149
- groups[id][category] ||= {count: 0, abilities: {}}
150
- groups[id][category][:count] += 1
151
- groups[id][category][:abilities][abilities] ||= 0
152
- groups[id][category][:abilities][abilities] += 1
153
- end
154
- end
155
- end
156
-
157
- def percent(num, total)
158
- (100 * num.to_f / total).round(2)
159
- end
160
- end
@@ -1,14 +0,0 @@
1
- class Eco::API::UseCases::DefaultCases::AppendUsergroupsCase < Eco::API::Common::Loaders::UseCase
2
- name "append-usergroups"
3
- type :sync
4
-
5
- def main(entries, people, session, options, usecase)
6
- micro = session.micro
7
- update = session.new_job("main", "update", :update, usecase)
8
-
9
- micro.with_each_present(entries, people, options, log_starter: true) do |entry, person|
10
- update.add(person)
11
- micro.append_usergroups(entry, person, options)
12
- end
13
- end
14
- end
@@ -1,74 +0,0 @@
1
- class Eco::API::UseCases::DefaultCases::CleanUnknownTags < Eco::API::Common::Loaders::UseCase
2
- name "clean-unknown-tags"
3
- type :transform
4
-
5
- UNKNOWN_LOCS_FILE = "unknown_locations.txt"
6
-
7
- REGISTER_TAGS = [
8
- "EVENT", "INJURY", "RISK", "CONTRACTOR", "PERMIT",
9
- "AUDIT", "JSEA",
10
- "TRAINING", "INDUCTION",
11
- "MEETING", "PPE", "CHEMICAL",
12
- "PLANT", "ASSET",
13
- "POLICY", "IDEA", "REPORTS"
14
- ]
15
-
16
- def main(people, session, options, usecase)
17
- update = session.new_job("main", "update", :update, usecase)
18
- people.each do |person|
19
- unknown_tags = person.filter_tags.select {|tag| !tag?(tag)}
20
- person.filter_tags -= unknown_tags
21
- unknown_tag!(*unknown_tags)
22
- if (account = person.account) && tag = account.default_tag
23
- unless tag?(tag)
24
- micro.refresh_default_tag(person.entry, person, options)
25
- unknown_tag!(tag)
26
- end
27
- end
28
- update.add(person)
29
- end
30
- end
31
-
32
- private
33
-
34
- def unknown_tag!(*tags)
35
- tags.each do |value|
36
- unless unknown.include?(value)
37
- unknown << value
38
- File.open(unknown_tags_file, 'a') do |fd|
39
- fd.write("#{value}\n")
40
- end
41
- puts "Custom detected: '#{value}'"
42
- end
43
- end
44
- end
45
-
46
- def register_tags
47
- REGISTER_TAGS
48
- end
49
-
50
- def unknown
51
- @unknown ||= []
52
- end
53
-
54
- def tag?(value)
55
- tagtree.tag?(value).yield_self do |is_loc|
56
- next true if is_loc
57
- if clean_register_tags?
58
- register_tags.any? {|reg| value == reg}
59
- end
60
- end
61
- end
62
-
63
- def tagtree
64
- @tagtree ||= ASSETS.config.tagtree
65
- end
66
-
67
- def unknown_tags_file
68
- File.join(".","#{session.enviro_name}_#{UNKNOWN_LOCS_FILE}")
69
- end
70
-
71
- def clean_register_tags?
72
- !options.dig(:usecase, :include_register_tags)
73
- end
74
- end
@@ -1,20 +0,0 @@
1
- class Eco::API::UseCases::DefaultCases::CreateDetailsCase < Eco::API::Common::Loaders::UseCase
2
- name "create-details"
3
- type :sync
4
-
5
- def main(entries, people, session, options, usecase)
6
- creation = session.new_job("main", "create", :create, usecase)
7
-
8
- micro.with_each_starter(entries, people, options, log_present: true, append_created: append_created) do |entry, person|
9
- creation.add(person)
10
- micro.set_core(entry, person, options)
11
- entry.set_details(person) unless options.dig(:exclude, :details)
12
- end
13
- end
14
-
15
- private
16
-
17
- def append_created
18
- options.dig(:people, :append_created)
19
- end
20
- end
@@ -1,21 +0,0 @@
1
- class Eco::API::UseCases::DefaultCases::CreateDetailsWithSupervisorCase < Eco::API::Common::Loaders::UseCase
2
- name "create-details-with-supervisor"
3
- type :sync
4
-
5
- def main(entries, people, session, options, usecase)
6
- creation = session.new_job("main", "create", :create, usecase)
7
- supers = session.new_job("post", "supers", :update, usecase, :core)
8
-
9
- micro.with_each_starter(entries, people, options, log_present: true, append_created: append_created) do |entry, person|
10
- creation.add(person)
11
- micro.set_core_with_supervisor(entry, person, people, supers, options)
12
- entry.set_details(person) unless options.dig(:exclude, :details)
13
- end
14
- end
15
-
16
- private
17
-
18
- def append_created
19
- options.dig(:people, :append_created)
20
- end
21
- end
@@ -1,12 +0,0 @@
1
- class Eco::API::UseCases::DefaultCases::EmailAsIdCase < Eco::API::Common::Loaders::UseCase
2
- name "email-as-id"
3
- type :transform
4
-
5
- def main(people, session, options, usecase)
6
- update = session.new_job("main", "update", :update, usecase, :core)
7
- people.each do |person|
8
- person.external_id = person.email
9
- update.add(person)
10
- end
11
- end
12
- end
@@ -1,13 +0,0 @@
1
- class Eco::API::UseCases::DefaultCases::NewEmailCase < Eco::API::Common::Loaders::UseCase
2
- name "new-email"
3
- type :sync
4
-
5
- def main(entries, people, session, options, usecase)
6
- update = session.new_job("main", "update", :update, usecase, :core)
7
-
8
- micro.with_each_present(entries, people, options, log_starter: true) do |entry, person|
9
- update.add(person)
10
- person.email = entry.email
11
- end
12
- end
13
- end
@@ -1,12 +0,0 @@
1
- class Eco::API::UseCases::DefaultCases::NewIdCase < Eco::API::Common::Loaders::UseCase
2
- name "new-id"
3
- type :sync
4
-
5
- def main(entries, people, session, options, usecase)
6
- update = session.new_job("main", "update", :update, usecase, :core)
7
- micro.with_each_present(entries, people, options, log_starter: true) do |entry, person|
8
- update.add(person)
9
- person.external_id = entry.external_id
10
- end
11
- end
12
- end
@@ -1,10 +0,0 @@
1
- class Eco::API::UseCases::DefaultCases::RemoveAccountSyncCase < Eco::API::UseCases::DefaultCases::RemoveAccountTransCase
2
- name "remove-account"
3
- type :sync
4
-
5
- def main(entries, people, session, options, usecase)
6
- micro = session.micro
7
- found = micro.with_each_present(entries, people, options, log_starter: true)
8
- remove_account(found.users)
9
- end
10
- end
@@ -1,16 +0,0 @@
1
- class Eco::API::UseCases::DefaultCases::RemoveAccountTransCase < Eco::API::Common::Loaders::UseCase
2
- name "remove-account"
3
- type :transform
4
-
5
- def remove_account(users)
6
- update = session.new_job("main", "update", :update, usecase, :account)
7
- users.each do |user|
8
- user.account = nil
9
- update.add(user)
10
- end
11
- end
12
-
13
- def main(people, session, options, usecase)
14
- remove_account(people.users)
15
- end
16
- end
@@ -1,18 +0,0 @@
1
- class Eco::API::UseCases::DefaultCases::ResetLandingPageCase < Eco::API::Common::Loaders::UseCase
2
- name "reset-landing-page"
3
- type :transform
4
-
5
- def main(people, session, options, usecase)
6
- update = session.new_job("main", "update", :update, usecase, :core)
7
- people.users.each do |user|
8
- user.account.landing_page_id = page_id
9
- update.add(user)
10
- end
11
- end
12
-
13
- private
14
-
15
- def page_id
16
- options[:page_id]
17
- end
18
- end
@@ -1,16 +0,0 @@
1
- class Eco::API::UseCases::DefaultCases::SetSupervisorCase < Eco::API::Common::Loaders::UseCase
2
- name "set-supervisor"
3
- type :sync
4
-
5
- def main(entries, people, session, options, usecase)
6
- update = session.new_job("main", "update", :update, usecase)
7
-
8
- micro.with_each_present(entries, people, options, log_starter: true) do |entry, person|
9
- if entry.supervisor_id?
10
- micro.set_supervisor(person, entry.supervisor_id, people, options) do |unknown_id|
11
- session.logger.warn("Supervisor '#{entry.supervisor_id}' does not exist. Entry: #{entry.to_s(:identify)}")
12
- end
13
- end
14
- end
15
- end
16
- end
@@ -1,42 +0,0 @@
1
- class Eco::API::UseCases::DefaultCases::TagTree < Eco::API::Common::Loaders::UseCase
2
- name "tagtree"
3
- type :other
4
-
5
- def main(session, options, usecase)
6
- puts "Use case still in development"
7
- exit
8
- options[:end_get] = false
9
- operations.keys.each do |key|
10
- process(key)
11
- end
12
- end
13
-
14
- def process(key)
15
- case key
16
- when :diff
17
- require_graphql_auth!
18
-
19
- when :show_backend
20
- require_graphql_auth!
21
-
22
- else
23
- logger.warn("Operation #{key} not supported")
24
- end
25
- end
26
-
27
- private
28
-
29
- def require_graphql_auth!
30
- unless session.config.api.version_available?(:graphql)
31
- logger.error("Missing parameters for to configure a GraphQL connexion.")
32
- end
33
- end
34
-
35
- def operations
36
- (options.dig(:tagtree, :operations) || {})
37
- end
38
-
39
- def graphql
40
- @graphql ||= session.api(version: :graphql)
41
- end
42
- end
@@ -1,15 +0,0 @@
1
- class Eco::API::UseCases::DefaultCases::UpdateDetailsCase < Eco::API::Common::Loaders::UseCase
2
- name "update-details"
3
- type :sync
4
-
5
- def main(entries, people, session, options, usecase)
6
- update = session.new_job("main", "update", :update, usecase)
7
- supers = session.new_job("post", "supers", :update, usecase, :core)
8
-
9
- micro.with_each_present(entries, people, options, log_starter: true) do |entry, person|
10
- update.add(person)
11
- micro.set_core_with_supervisor(entry, person, people, supers, options)
12
- entry.set_details(person) unless options.dig(:exclude, :details)
13
- end
14
- end
15
- end
@@ -1,188 +0,0 @@
1
- ASSETS.cli.config do |config|
2
- ASSETS.config.workflow do |wf|
3
- io = nil
4
- rescued = false
5
- cases_with_input = nil
6
- cases_with_output = nil
7
-
8
- # default rescue
9
- wf.rescue do |exception, io|
10
- begin
11
- next io if rescued
12
- rescued = true
13
-
14
- io.session.logger.debug(exception.patch_full_message)
15
- wf.run(:close, io: io)
16
- rescue Exception => e
17
- puts "Some problem in workflow.rescue: #{e}"
18
- end
19
- io
20
- end
21
-
22
- wf.on(:options) do |wf_options, io|
23
- io = io.new(options: config.options_set.process(io: io))
24
- end
25
-
26
- wf.for(:load) do |wf_load|
27
- wf_load.for(:input) do |wf_input|
28
- wf_input.on(:get) do |wf_input_get, io|
29
- cases_with_input = config.usecases.active(io: io).select do |usecase, data|
30
- io.class.input_required?(usecase.type)
31
- end
32
-
33
- input_is_required = !cases_with_input.empty? || io.options.dig(:input, :entries_from)
34
- missing_input = !io.input || io.input.empty?
35
- next io unless missing_input && input_is_required
36
-
37
- if io.options.dig(:input, :entries_from)
38
- io = io.new(input: config.input.get(io: io))
39
- else
40
- opt_case = cases_with_input.values.first.option
41
- io = io.new(input: config.input.get(io: io, option: opt_case))
42
- end
43
- io
44
- end
45
-
46
- wf_input.on(:filter) do |wf_input_filter, io|
47
- next io unless io.input && !io.input.empty?
48
- io = io.new(input: config.input_filters.process(io: io))
49
- end
50
- end
51
-
52
- wf_load.for(:people) do |wf_people|
53
- wf_people.on(:get) do |wf_people_get, io|
54
- cases_with_people = config.usecases.active(io: io).select do |usecase, data|
55
- io.class.people_required?(usecase.type)
56
- end
57
- next io if cases_with_people.empty? && !io.options.dig(:people, :get)
58
- io = io.new(people: config.people(io: io))
59
- end
60
-
61
- wf_people.on(:filter) do |wf_people_filter, io|
62
- next io unless io.people && !io.people.empty?
63
- io = io.new(people: config.people_filters.process(io: io))
64
- end
65
- end
66
- end
67
-
68
- wf.before(:usecases) do |wf_cases, io|
69
- # save partial entries -> should be native to session.workflow
70
- get_people = io.options.dig(:people, :get)
71
- partial_update = get_people && get_people.dig(:type) == :partial
72
- if !io.options[:dry_run] && partial_update
73
- partial_file = io.session.config.people.partial_cache
74
- io.session.file_manager.save_json(io.people, partial_file, :timestamp)
75
- end
76
- io
77
- end
78
-
79
- wf.on(:usecases) do |wf_cases, io|
80
- unless config.usecases.process(io: io)
81
- msg = "No update operation specified... quitting"
82
- io.session.logger.info(msg)
83
- exit(0)
84
- end
85
- io
86
- end
87
-
88
- wf.before(:launch_jobs) do |wf_jobs, io|
89
- SCR.stop_on_unknown!
90
- io
91
- end
92
-
93
- wf.on(:launch_jobs) do |wf_jobs, io|
94
- io.session.jobs_launch(simulate: io.options[:dry_run])
95
- io
96
- end
97
-
98
- wf.before(:post_launch) do |wf_post, io|
99
- if io.session.post_launch.empty?
100
- wf_post.skip!
101
- else
102
- get_people = io.options.dig(:people, :get)
103
- partial_update = get_people && get_people.dig(:type) == :partial
104
- run_it = !io.options[:dry_run] || io.options.dig(:post_launch, :run)
105
- refresh_data = !io.options[:dry_run] && partial_update
106
- if run_it
107
- if refresh_data
108
- # get target people afresh
109
- people = io.session.micro.people_refresh(people: io.people, include_created: true)
110
- io = io.base.new(people: people)
111
- else
112
- msg = "Although there are post_launch cases, data will not be refreshed before their run"
113
- if io.options[:dry_run]
114
- msg += ", because we are in dry-run (simulate)."
115
- elsif !partial_update
116
- msg += ", because it is not a partial update (-get-partial option not present)."
117
- end
118
- io.session.logger.warn(msg)
119
- end
120
- else
121
- wf_post.skip!
122
- msg = "Although there are post_launch cases, they will NOT be RUN"
123
- if io.options[:dry_run]
124
- msg+= ", because we are in dry-run (simulate)."
125
- end
126
- io.session.logger.info(msg)
127
- end
128
- end
129
- io
130
- end
131
-
132
- wf.for(:post_launch) do |wf_post|
133
-
134
- wf_post.on(:usecases) do |wf_postcases, io|
135
- io.session.post_launch.each do |use|
136
- begin
137
- io = use.launch(io: io).base
138
- rescue Eco::API::UseCases::BaseIO::MissingParameter => e
139
- if e.required == :people
140
- io.session.logger.debug("Skipping use case '#{use.name}' -- no base people detected for the current run")
141
- else
142
- raise
143
- end
144
- end
145
- end
146
- io
147
- end
148
-
149
- wf_post.on(:launch_jobs) do |wf_postlaunch, io|
150
- io.session.jobs_launch(simulate: io.options[:dry_run])
151
- io
152
- end
153
- end
154
-
155
- wf.on(:report) do |wf_report, io|
156
- io.tap do |_io|
157
- if file = io.options.dig(:report, :people, :csv)
158
- io.options.deep_merge!(export: {
159
- options: {internal_names: true, nice_header: true, split_schemas: true},
160
- file: {name: file, format: :csv}
161
- })
162
- aux_io = io.new(people: io.people.updated_or_created)
163
- io.session.process_case("to-csv", io: aux_io, type: :export)
164
- end
165
- end
166
- end
167
-
168
- wf.on(:end) do |wf_end, io|
169
- get_people = io.options.dig(:people, :get)
170
- partial_update = get_people && get_people.dig(:type) == :partial
171
-
172
- unless !io.options[:end_get] || io.options[:dry_run] || partial_update
173
- people_update_cases = config.usecases.active(io: io).any? do |usecase, data|
174
- [:transform, :sync].any? {|type| usecase.type == type}
175
- end
176
-
177
- if !people_update_cases
178
- # Prevent getting people when there were no use cases that used them
179
- io.session.logger.info("Won't be recaching people, as there haven't been any targetted updates")
180
- elsif !io.people
181
- people = io.session.micro.people_cache
182
- io = io.new(people: people)
183
- end
184
- end
185
- io
186
- end
187
- end
188
- end
@@ -1,16 +0,0 @@
1
- module Eco
2
- class CLI
3
- class Config
4
- module Default
5
- end
6
- end
7
- end
8
- end
9
-
10
- require_relative 'default/options'
11
- require_relative 'default/input'
12
- require_relative 'default/input_filters'
13
- require_relative 'default/people'
14
- require_relative 'default/people_filters'
15
- require_relative 'default/usecases'
16
- require_relative 'default/workflow'