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
@@ -40,19 +40,26 @@ module Eco
40
40
  # @option kargs [Eco::API::Organization::People] :people object.
41
41
  # @option kargs [Eco::API:Session] :session
42
42
  # @option kargs [Hash] :options hash with symbol keys (i.e. behaviour modifiers, cli trackers, filters, etc.)
43
+ # @return [Eco::API::UseCases::UseCaseIO] an io with the result in output
43
44
  def launch(io: nil, **kargs)
44
45
  params = io&.params(keyed: true, all: true) || {}
45
46
  kargs = params.merge(kargs).merge(usecase: self)
46
47
 
47
48
  UseCaseIO.new(**kargs).tap do |uio|
48
- @options = uio.options
49
+ @options = uio.options
49
50
  uio.session.logger.debug("#{self.class}: going to process '#{name}'")
50
- set_session_n_options(session: uio.session, options: uio.options) if callback_from_loader?
51
- uio.output = @callback.call(*uio.params)
51
+ set_session_n_options(uio) if callback_from_loader?
52
+ uio.output = callback.call(*uio.params)
52
53
  @times_launched += 1
53
54
  end
54
55
  end
55
56
 
57
+ # When it was defined from a Loader class it retrieves the object.
58
+ # @return [Eco::API::Common::Loaders::Base, NilClass]
59
+ def classed_definition
60
+ callback_self if callback_from_loader?
61
+ end
62
+
56
63
  protected
57
64
 
58
65
  def callback
@@ -60,7 +67,7 @@ module Eco
60
67
  end
61
68
 
62
69
  def callback_self
63
- eval("self", @callback.binding)
70
+ eval("self", callback.binding)
64
71
  end
65
72
 
66
73
  def callback_from_loader?
@@ -71,15 +78,32 @@ module Eco
71
78
  # in the use case definition
72
79
  # @note this only works when the use case was defined
73
80
  # via an children class of `Eco::API::Common::Loaders::Base`
74
- def set_session_n_options(session:, options: @options)
81
+ def set_session_n_options(uio)
75
82
  return false unless callback_from_loader?
83
+ opts = uio.options || @options
84
+ sess = uio.session
85
+ peo = uio.people
86
+ ent = uio.input
76
87
  use_case_self = self
88
+
77
89
  callback_self.instance_eval do
78
- @session = session
79
- @options = options
90
+ @session = sess
91
+ @options = opts
92
+ if peo
93
+ @people = peo
94
+ self.singleton_class.attr_reader(:people) unless respond_to?(:people)
95
+ end
96
+
97
+ if ent # entries/input
98
+ @input = ent
99
+ self.singleton_class.attr_reader(:input) unless respond_to?(:input)
100
+ end
101
+
80
102
  # `self` is the use case itself (when used the Loader)
81
103
  next unless self.is_a?(Eco::API::Common::Loaders::CaseBase)
104
+
82
105
  @usecase = use_case_self
106
+ self.singleton_class.attr_reader(:usecase) unless respond_to?(:usecase)
83
107
  end
84
108
  true
85
109
  end
@@ -56,12 +56,12 @@ module Eco
56
56
  end
57
57
  end
58
58
 
59
- def chain(usecase = nil)
59
+ def chain(usecase = nil, &block)
60
60
  @@num_chains += 1
61
61
  raise "Reached maximum number of chained use cases (#{MAX_CHAINS}). Looks like a recursive cyclic chain 'use'" if @@num_chains >= MAX_CHAINS
62
62
  raise "A UseCase can only be chained with another UseCase" if usecase && !usecase.is_a?(UseCase)
63
63
  raise "Missuse. Please use either parameter or block but not both" if block_given? && usecase
64
- usecase = block_given?? Proc.new : usecase
64
+ usecase = block_given?? block : usecase
65
65
  @chains.push(usecase)
66
66
  self
67
67
  end
@@ -1,5 +1,6 @@
1
1
  module Eco
2
2
  module API
3
+ # Autoloading children is done on init and each time usecases it's queried
3
4
  class UseCases
4
5
 
5
6
  class UnknownCase < StandardError
@@ -161,7 +162,9 @@ require_relative 'usecases/use_case'
161
162
  require_relative 'usecases/use_case_chain'
162
163
  require_relative 'usecases/base_io'
163
164
  require_relative 'usecases/use_case_io'
165
+ require_relative 'usecases/cli'
164
166
  require_relative 'usecases/default_cases'
167
+ require_relative 'usecases/graphql'
165
168
  require_relative 'usecases/ooze_samples'
166
169
  require_relative 'usecases/ooze_cases'
167
- require_relative 'usecases/graphql'
170
+ require_relative 'usecases/default'
data/lib/eco/assets.rb CHANGED
@@ -31,18 +31,16 @@ module Eco
31
31
  @configs ||= {}
32
32
  end
33
33
 
34
- def cli
34
+ def cli(&block)
35
35
  unless @cli_init
36
36
  @cli_init = true
37
- #pp "going to load default cli config..."
38
- require_relative('cli/config/default')
37
+ require_relative('cli_default')
39
38
  end
40
- @cli
39
+ @cli.tap { yield(@cli) if block_given? }
41
40
  end
42
41
  end
43
42
  end
44
43
 
45
44
  require_relative 'assets/language'
46
45
 
47
-
48
46
  ASSETS = Eco::Assets.new
@@ -22,7 +22,6 @@ module Eco
22
22
  end
23
23
  io.people
24
24
  end
25
-
26
25
  end
27
26
  end
28
27
  end
@@ -28,9 +28,9 @@ module Eco
28
28
 
29
29
  # @param option [String] the command line option that activates this filter.
30
30
  # @param desc [String] description of the filter.
31
- def add(option, desc = nil)
31
+ def add(option, desc = nil, &block)
32
32
  raise "Missing block to define the filters builder" unless block_given?
33
- callback = Proc.new
33
+ callback = block
34
34
  [option].flatten.compact.each do |opt|
35
35
  @filters[opt] = callback
36
36
  @description[opt] = desc
@@ -41,10 +41,6 @@ module Eco
41
41
  def process(io:)
42
42
  raise "You need to override this method in child classes"
43
43
  end
44
-
45
- private
46
-
47
-
48
44
  end
49
45
  end
50
46
  end
@@ -43,7 +43,6 @@ module Eco
43
43
  end
44
44
  end
45
45
  end
46
-
47
46
  end
48
47
  end
49
48
  end
@@ -33,7 +33,6 @@ module Eco
33
33
  callback = @callbacks[option] || @callbacks[default_option]
34
34
  callback.call(io.session, option, io.options)
35
35
  end
36
-
37
36
  end
38
37
  end
39
38
  end
@@ -44,14 +44,14 @@ module Eco
44
44
  # @param option [String, Array<String>] the command line option(s).
45
45
  # @param namespace [String] preceding command(s) argument that enables this option.
46
46
  # @param desc [String] description of the option.
47
- def add(option, desc = nil, namespace: :general)
47
+ def add(option, desc = nil, namespace: :general, &block)
48
48
  raise "Missing block to define the options builder" unless block_given?
49
49
 
50
50
  opts = [option].flatten.compact
51
51
  unless opts.empty?
52
- callback = Proc.new
52
+ callback = block
53
53
  opts.each do |opt|
54
- puts "Overriding option '#{option}' in '#{namespace}' namespace" if option_exists?(opt, namespace)
54
+ puts "Overriding CLI option '#{option}' in '#{namespace}' CLI case / namespace" if option_exists?(opt, namespace)
55
55
  options_set(namespace)[opt] = OptConfig.new(opt, namespace, desc, callback)
56
56
  end
57
57
  end
@@ -139,7 +139,6 @@ module Eco
139
139
  def options_set(namespace = :general)
140
140
  @sets[namespace] ||= {}
141
141
  end
142
-
143
142
  end
144
143
  end
145
144
  end
@@ -6,7 +6,6 @@ module Eco
6
6
  attr_reader :core_config
7
7
 
8
8
  class CaseConfig < Struct.new(:cases_config, :option, :type, :description, :casename, :callback)
9
-
10
9
  def add_option(arg, desc = nil, &block)
11
10
  core_config.options_set.add(arg, desc, namespace: option, &block)
12
11
  self
@@ -20,7 +19,6 @@ module Eco
20
19
  end
21
20
 
22
21
  class ActiveCase < Struct.new(:index, :option, :callback)
23
-
24
22
  end
25
23
 
26
24
  def initialize(core_config:)
@@ -47,16 +45,26 @@ module Eco
47
45
  # @param type [Symbol] the type of usecase.
48
46
  # @param desc [String] description of the case.
49
47
  # @param case_name [String, nil] the name of the usecase as defined.
50
- def add(option_case, type, desc = nil, case_name: nil)
48
+ def add(option_case, type, desc = nil, case_name: nil, &callback)
51
49
  Eco::API::UseCases::UseCase.validate_type(type)
52
- unless callback = block_given?? Proc.new : nil
50
+ unless block_given?
53
51
  raise "You must specify a valid 'case_name' when no block is provided" unless case_name
54
52
  raise "'case_name' expected to be a String. Given: #{case_name.class}" unless case_name.is_a?(String)
55
53
  end
56
- puts "Overriding case config '#{option_case}'" if @linked_cases.key?(option_case)
54
+ puts "Overriding CLI case '#{option_case}'" if @linked_cases.key?(option_case)
57
55
  @linked_cases[option_case] = CaseConfig.new(self, option_case, type, desc, case_name, callback)
58
56
  end
59
57
 
58
+ # This method runs on use cases that have lazy configurations
59
+ # @note it only applies to use cases that have been defined via class
60
+ def cli_apply(io:)
61
+ io.session.usecases.each do |usecase|
62
+ next unless usecase.respond_to?(:classed_definition)
63
+ next unless original_case = usecase.classed_definition
64
+ original_case.cli_apply!
65
+ end
66
+ end
67
+
60
68
  # Scopes/identifies which usecases are being invoked from the command line
61
69
  # @note
62
70
  # - this method will sort the active usecases by the position they hold in the command line
@@ -126,7 +134,6 @@ module Eco
126
134
  raise "You need to provide Eco::API::UseCases::BaseIO object. Given: #{io.class}"
127
135
  end
128
136
  end
129
-
130
137
  end
131
138
  end
132
139
  end
@@ -23,19 +23,19 @@ module Eco
23
23
  end
24
24
  end
25
25
 
26
- def input(default_option: nil)
26
+ def input(default_option: nil, &block)
27
27
  @input ||= Eco::CLI::Config::Input.new(core_config: self, default_option: default_option)
28
28
  if block_given?
29
- @input.define(&Proc.new)
29
+ @input.define(&block)
30
30
  self
31
31
  else
32
32
  @input
33
33
  end
34
34
  end
35
35
 
36
- def people(io: nil)
36
+ def people(io: nil, &block)
37
37
  if block_given?
38
- @people_load = Proc.new
38
+ @people_load = block
39
39
  self
40
40
  else
41
41
  raise "There is no definition on how to load people" unless instance_variable_defined?(:@people_load) && @people_load
@@ -68,7 +68,6 @@ module Eco
68
68
  yield(cases) if block_given?
69
69
  end
70
70
  end
71
-
72
71
  end
73
72
  end
74
73
  end
@@ -88,7 +88,7 @@ module Eco
88
88
  private
89
89
 
90
90
  def file_exists?(filename)
91
- File.exists?(filename) || File.exists?(File.expand_path(filename))
91
+ File.exist?(filename) || File.exist?(File.expand_path(filename))
92
92
  end
93
93
  end
94
94
  end
@@ -31,7 +31,6 @@ module Eco
31
31
  def with_param?
32
32
  @with_param
33
33
  end
34
-
35
34
  end
36
35
  end
37
36
  end
@@ -62,8 +62,6 @@ module Eco
62
62
  "Missuse: only able to transform to key a String or an Argument. Given #{value.class}"
63
63
  end
64
64
  end
65
-
66
-
67
65
  end
68
66
  end
69
67
  end
data/lib/eco/cli.rb CHANGED
@@ -24,7 +24,6 @@ module Eco
24
24
  io = Eco::API::UseCases::BaseIO.new(session: session, options: options)
25
25
  session.workflow(io: io).run(io: io)
26
26
  end
27
-
28
27
  end
29
28
  end
30
29
 
@@ -53,6 +53,5 @@ ASSETS.cli.config do |cnf|
53
53
  #end
54
54
  input.supervisor_id(id)
55
55
  end
56
-
57
56
  end
58
57
  end
@@ -103,6 +103,5 @@ ASSETS.cli.config do |cnf|
103
103
  people.newFrom filtered
104
104
  end
105
105
  end
106
-
107
106
  end
108
107
  end
@@ -17,14 +17,6 @@ ASSETS.cli.config do |cnf|
17
17
  options.deep_merge!(output: {file: file})
18
18
  end
19
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
20
  desc = "Provides a set of tools to analyse a set of people (i.e. detect duplicates)"
29
21
  cases.add("-analyse-people", :export, desc, case_name: "analyse-people") do |people, session, options|
30
22
  options.deep_merge!(output: {file: "people_analysis.txt"}) unless options.dig(:output, :file)
@@ -87,14 +79,6 @@ ASSETS.cli.config do |cnf|
87
79
  options.deep_merge!(other: {file: {codes_column: col_codes}})
88
80
  end
89
81
 
90
- desc = "Allows to perform some checks on tagtree structure (requires GraphQL)"
91
- cases.add("-tagtree", :other, desc, case_name: "tagtree")
92
- .add_option("-show-backend", "Displays the tagtree as per back-end") do |options|
93
- options.deep_merge!(tagtree: {operation: {show_backend: true}})
94
- end.add_option("-diff", "Compares the tagtree.json file with the back-end") do |options|
95
- options.deep_merge!(tagtree: {operation: {diff: true}})
96
- end
97
-
98
82
  desc = "Creates a CSV with the paths to each tag"
99
83
  cases.add("-create-tag-paths", :other, desc, case_name: "create-tag-paths")
100
84
 
@@ -107,32 +91,13 @@ ASSETS.cli.config do |cnf|
107
91
  desc = "Cleans from filter_tags those tags that are not present in the tagtree (as per tagtree.json file)."
108
92
  desc += " It will preserve standard register tags of most common registers (i.e. EVENT, RISK)."
109
93
  cases.add("-clean-unknown-tags", :transform, desc, case_name: "clean-unknown-tags")
110
- .add_option("-include-register-tags", "Will also try to remove register tags") do |options|
111
- options.deep_merge!(usecase: {include_register_tags: true})
112
- end
113
-
114
- desc = "Removes the landing page or sets it to -page-id"
115
- cases.add("-reset-landing-page", :transform, desc, case_name: "reset-landing-page")
116
- .add_option("-page-id", "Target landing page to set to the users") do |options|
117
- SCR.get_arg("-page-id", with_param: true).tap do |new_id|
118
- options.deep_merge!({page_id: new_id})
119
- end
94
+ .add_option("-clear-register-tags", "Will also try to remove register tags") do |options|
95
+ options.deep_merge!(usecase: {clear_register_tags: true})
120
96
  end
121
97
 
122
- desc = "Sets as external_id the email of the person"
123
- cases.add("-email-as-id", :transform, desc, case_name: "email-as-id")
124
-
125
- desc = "Sets the external_id to the one given in the input CSV"
126
- cases.add("-new-id-from", :sync, desc, case_name: "new-id")
127
-
128
- desc = "Sets the email of people. It won't succeed if email taken by any other user in eP"
129
- cases.add("-new-email-from", :sync, desc, case_name: "new-email")
130
98
  desc = "Forces a change of email in the same org. It won't succeed if email taken by an org member user"
131
99
  cases.add("-change-email-from", :sync, desc, case_name: "change-email")
132
100
 
133
- desc = "Sets the supervisor_id"
134
- cases.add("-set-supervisor-from", :sync, desc, case_name: "set-supervisor")
135
-
136
101
  desc = "Sets to -new-super the supervisor_id of the -old-super's subordinates"
137
102
  cases.add("-switch-supervisor", :transform, desc, case_name: "switch-supervisor") do |people, session, options|
138
103
  unless options[:super]&.key?(:old)
@@ -218,10 +183,6 @@ ASSETS.cli.config do |cnf|
218
183
  cases.add("-delete", :transform, desc, case_name: "delete")
219
184
  desc = "Deletes the people specified in the input data"
220
185
  cases.add("-delete-from", :sync, desc, case_name: "delete")
221
- desc = "Removes the account of everybody that has been filtered from the people manager"
222
- cases.add("-remove-account", :transform, desc, case_name: "remove-account")
223
- desc = "Removes the people specified in the input data"
224
- cases.add("-remove-account-from", :sync, desc, case_name: "remove-account")
225
186
 
226
187
  desc = "Re-freshes the default_tag of users"
227
188
  cases.add("-set-default-tag", :transform, desc, case_name: "set-default-tag")
@@ -234,20 +195,9 @@ ASSETS.cli.config do |cnf|
234
195
  options.deep_merge!(people: {append_created: true})
235
196
  end
236
197
 
237
- desc = "Creates people with only details"
238
- cases.add("-create-details-from", :sync, desc, case_name: "create-details")
239
- .add_option("-append-starters", as1) do |options|
240
- options.deep_merge!(people: {append_created: true})
241
- end
242
-
243
198
  desc = "It just adds everybody to an update job without doing any change. If the org has policies, it will refresh"
244
199
  cases.add("-refresh", :transform, desc, case_name: "refresh")
245
200
 
246
- desc = "Updates details and core (including supervisor) to target people"
247
- cases.add("-update-details-from", :sync, desc, case_name: "update-details")
248
-
249
- desc = "Appends the policy_group_ids column to the people with account specified in the input data"
250
- cases.add("-append-usergroups-from", :sync, desc, case_name: "append-usergroups")
251
201
  desc = "Updates the people specified in the input data"
252
202
  cases.add("-update-from", :sync, desc, case_name: "update")
253
203
 
@@ -0,0 +1,171 @@
1
+ ASSETS.cli do |cli|
2
+ ASSETS.config.workflow do |wf|
3
+
4
+ rescued = false
5
+ # default rescue
6
+ wf.rescue do |err, io|
7
+ next io if rescued
8
+ rescued = true
9
+ log(:debug) { err.patch_full_message }
10
+ wf.run(:close, io: io)
11
+ rescue StandardError => e
12
+ puts "Some problem in workflow.rescue: #{e}"
13
+ end
14
+
15
+ wf.on(:options) do |_wf_opt, io|
16
+ cli.config.usecases.cli_apply(io: io)
17
+ io.new(options: cli.config.options_set.process(io: io))
18
+ end
19
+
20
+ wf.for(:load) do |wf_load|
21
+ wf_load.for(:input) do |wf_in|
22
+ wf_in.on(:get) do |_wf_ig, io|
23
+ cases_with_input = cli.config.usecases.active(io: io).select do |usecase, data|
24
+ io.class.input_required?(usecase.type)
25
+ end
26
+
27
+ input_is_required = !cases_with_input.empty? || options.dig(:input, :entries_from)
28
+ missing_input = !input || input.empty?
29
+ next unless missing_input && input_is_required
30
+
31
+ if options.dig(:input, :entries_from)
32
+ io.new(input: cli.config.input.get(io: io))
33
+ else
34
+ opt_case = cases_with_input.values.first.option
35
+ io.new(input: cli.config.input.get(io: io, option: opt_case))
36
+ end
37
+ end
38
+
39
+ wf_in.on(:filter) do |_wf_if, io|
40
+ next unless input && !input.empty?
41
+ io.new(input: cli.config.input_filters.process(io: io))
42
+ end
43
+ end
44
+
45
+ wf_load.for(:people) do |wf_peo|
46
+ wf_peo.on(:get) do |_wf_pg, io|
47
+ cases_with_people = cli.config.usecases.active(io: io).select do |usecase, data|
48
+ io.class.people_required?(usecase.type)
49
+ end
50
+ next if cases_with_people.empty? && !options.dig(:people, :get)
51
+ io.new(people: cli.config.people(io: io))
52
+ end
53
+
54
+ wf_peo.on(:filter) do |_wf_pf, io|
55
+ next unless people && !people.empty?
56
+ io.new(people: cli.config.people_filters.process(io: io))
57
+ end
58
+ end
59
+ end
60
+
61
+ wf.before(:usecases) do |_wf_ca, io|
62
+ # save partial entries -> should be native to session.workflow
63
+ get_people = options.dig(:people, :get)
64
+ partial_update = get_people && get_people.dig(:type) == :partial
65
+ if !options[:dry_run] && partial_update
66
+ partial_file = session.config.people.partial_cache
67
+ session.file_manager.save_json(io.people, partial_file, :timestamp)
68
+ end
69
+ end
70
+
71
+ wf.on(:usecases) do |_wf_ca, io|
72
+ unless cli.config.usecases.process(io: io)
73
+ log(:info) { "No update operation specified... quitting" }
74
+ exit 0
75
+ end
76
+ end
77
+
78
+ wf.before(:launch_jobs) do
79
+ SCR.stop_on_unknown!
80
+ end
81
+
82
+ wf.on(:launch_jobs) do
83
+ session.jobs_launch(simulate: options[:dry_run])
84
+ end
85
+
86
+ wf.before(:post_launch) do |wf_post, io|
87
+ next wf_post.skip! if session.post_launch.empty?
88
+
89
+ run_it = !options[:dry_run] || options.dig(:post_launch, :run)
90
+ unless run_it
91
+ wf_post.skip!
92
+ log(:info) {
93
+ msg = "Although there are post_launch cases, they will NOT be RUN"
94
+ msg += ", because we are in dry-run (simulate)." if options[:dry_run]
95
+ msg
96
+ }
97
+ next
98
+ end
99
+
100
+ get_people = options.dig(:people, :get)
101
+ partial_update = get_people && get_people.dig(:type) == :partial
102
+ refresh_data = !options[:dry_run] && partial_update
103
+
104
+ unless refresh_data
105
+ log(:info) {
106
+ msg = "Although there are post_launch cases, data will not be refreshed before their run"
107
+ if io.options[:dry_run]
108
+ msg += ", because we are in dry-run (simulate)."
109
+ elsif !partial_update
110
+ msg += ", because it is not a partial update (-get-partial option not present)."
111
+ end
112
+ msg
113
+ }
114
+ next
115
+ end
116
+
117
+ # get target people afresh
118
+ peo_aux = session.micro.people_refresh(people: people, include_created: true)
119
+ io.base.new(people: peo_aux)
120
+ end
121
+
122
+ wf.for(:post_launch) do |wf_post|
123
+ wf_post.on(:usecases) do |_wf_pu, io|
124
+ session.post_launch.each do |use|
125
+ use.launch(io: io).base
126
+ rescue Eco::API::UseCases::BaseIO::MissingParameter => e
127
+ raise unless e.required == :people
128
+ log(:debug) {
129
+ "Skipping use case '#{use.name}' -- no base people detected for the current run"
130
+ }
131
+ end
132
+ end
133
+
134
+ wf_post.on(:launch_jobs) do |_wf_pl, io|
135
+ session.jobs_launch(simulate: options[:dry_run])
136
+ end
137
+ end
138
+
139
+ wf.on(:report) do |_wf_rep, io|
140
+ if file = options.dig(:report, :people, :csv)
141
+ options.deep_merge!(export: {
142
+ options: {internal_names: true, nice_header: true, split_schemas: true},
143
+ file: {name: file, format: :csv}
144
+ })
145
+ aux_io = io.new(people: people.updated_or_created)
146
+ session.process_case("to-csv", io: aux_io, type: :export)
147
+ end
148
+ end
149
+
150
+ wf.on(:end) do |_wf_end, io|
151
+ get_people = options.dig(:people, :get)
152
+ partial_update = get_people && get_people.dig(:type) == :partial
153
+
154
+ unless !options[:end_get] || options[:dry_run] || partial_update
155
+ people_update_cases = cli.config.usecases.active(io: io).any? do |usecase, data|
156
+ [:transform, :sync].any? { |type| usecase.type == type }
157
+ end
158
+
159
+ if !people_update_cases
160
+ # Prevent getting people when there were no use cases that used them
161
+ log(:info) {
162
+ "Won't be recaching people, as there haven't been any targetted updates"
163
+ }
164
+ elsif !people
165
+ people = session.micro.people_cache
166
+ io.new(people: people)
167
+ end
168
+ end
169
+ end
170
+ end
171
+ end
@@ -0,0 +1,13 @@
1
+ # Invoked / required when dependencies have been already loaded (i.e. Eco::API, Eco:Assets, Eco::Cli)
2
+ module Eco
3
+ module CliDefault
4
+ end
5
+ end
6
+
7
+ require_relative 'cli_default/options'
8
+ require_relative 'cli_default/input'
9
+ require_relative 'cli_default/input_filters'
10
+ require_relative 'cli_default/people'
11
+ require_relative 'cli_default/people_filters'
12
+ require_relative 'cli_default/usecases'
13
+ require_relative 'cli_default/workflow'
data/lib/eco/csv/table.rb CHANGED
@@ -142,7 +142,6 @@ module Eco
142
142
  end
143
143
 
144
144
  # @note by default it adds as a first column
145
-
146
145
  # @param header_name [String] header of the new column
147
146
  # @param pos [Integer] index where to add the column (i.e. `-1` for last)
148
147
  # @return [Eco::CSV::Table] with a new column named `name` with the row number
@@ -62,7 +62,7 @@ module Eco
62
62
 
63
63
  def file_exists?(file)
64
64
  return false if !file
65
- return File.exists?(file) || File.exists?(File.expand_path(file))
65
+ return File.exist?(file) || File.exist?(File.expand_path(file))
66
66
  end
67
67
 
68
68
  def file_empty?(path)
@@ -68,7 +68,7 @@ module Eco
68
68
 
69
69
  def file_exists?(file)
70
70
  return false if !file
71
- return File.exists?(file) || File.exists?(File.expand_path(file))
71
+ return File.exist?(file) || File.exist?(File.expand_path(file))
72
72
  end
73
73
 
74
74
  def dir_exists?(path)