eco-helpers 2.5.10 → 2.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (99) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -2
  3. data/CHANGELOG.md +64 -4
  4. data/eco-helpers.gemspec +20 -16
  5. data/lib/eco/api/common/loaders/base.rb +2 -9
  6. data/lib/eco/api/common/loaders/use_case.rb +27 -1
  7. data/lib/eco/api/common/people/default_parsers.rb +2 -2
  8. data/lib/eco/api/common/people/person_entry.rb +3 -0
  9. data/lib/eco/api/common/people/person_entry_attribute_mapper.rb +111 -16
  10. data/lib/eco/api/common/session/base_session.rb +4 -0
  11. data/lib/eco/api/common/session/environment.rb +4 -0
  12. data/lib/eco/api/common/session/sftp.rb +1 -1
  13. data/lib/eco/api/organization/tag_tree.rb +20 -23
  14. data/lib/eco/api/session/batch/job.rb +4 -4
  15. data/lib/eco/api/session/batch/jobs.rb +2 -2
  16. data/lib/eco/api/session/batch/jobs_groups.rb +2 -2
  17. data/lib/eco/api/session/config/files.rb +2 -2
  18. data/lib/eco/api/session/config/people.rb +2 -2
  19. data/lib/eco/api/session/config/sftp.rb +4 -0
  20. data/lib/eco/api/session/config/tagtree.rb +9 -8
  21. data/lib/eco/api/session/config/workflow.rb +3 -2
  22. data/lib/eco/api/session/config.rb +7 -0
  23. data/lib/eco/api/session.rb +17 -2
  24. data/lib/eco/api/usecases/cli/dsl.rb +84 -0
  25. data/lib/eco/api/usecases/cli/option.rb +19 -0
  26. data/lib/eco/api/usecases/cli.rb +13 -0
  27. data/lib/eco/api/usecases/default/locations/cli/tagtree_extract_cli.rb +24 -0
  28. data/lib/eco/api/usecases/{default_cases → default/locations}/codes_to_tags_case.rb +1 -1
  29. data/lib/eco/api/usecases/{default_cases → default/locations}/create_tag_paths_case.rb +1 -1
  30. data/lib/eco/api/usecases/{default_cases → default/locations}/csv_to_tree_case.rb +1 -1
  31. data/lib/eco/api/usecases/default/locations/tagtree_extract_case.rb +173 -0
  32. data/lib/eco/api/usecases/default/locations.rb +15 -0
  33. data/lib/eco/api/usecases/{default_cases → default/people}/analyse_people_case.rb +1 -1
  34. data/lib/eco/api/usecases/{default_cases → default/people}/change_email_case.rb +1 -1
  35. data/lib/eco/api/usecases/default/people/clean_unknown_tags_case.rb +66 -0
  36. data/lib/eco/api/usecases/{default_cases → default/people}/clear_abilities_case.rb +1 -1
  37. data/lib/eco/api/usecases/{default_cases → default/people}/org_data_convert_case.rb +1 -1
  38. data/lib/eco/api/usecases/{default_cases → default/people}/refresh_case.rb +1 -1
  39. data/lib/eco/api/usecases/{default_cases → default/people}/reinvite_sync_case.rb +1 -1
  40. data/lib/eco/api/usecases/{default_cases → default/people}/reinvite_trans_case.rb +1 -1
  41. data/lib/eco/api/usecases/default/people/reinvite_trans_cli.rb +5 -0
  42. data/lib/eco/api/usecases/{default_cases → default/people}/restore_db_case.rb +1 -1
  43. data/lib/eco/api/usecases/{default_cases → default/people}/set_default_tag_case.rb +1 -1
  44. data/lib/eco/api/usecases/{default_cases → default/people}/supers_cyclic_identify_case.rb +1 -1
  45. data/lib/eco/api/usecases/{default_cases → default/people}/supers_hierarchy_case.rb +1 -1
  46. data/lib/eco/api/usecases/{default_cases → default/people}/switch_supervisor_case.rb +1 -1
  47. data/lib/eco/api/usecases/{default_cases → default/people}/transfer_account_case.rb +1 -1
  48. data/lib/eco/api/usecases/default/people.rb +25 -0
  49. data/lib/eco/api/usecases/default.rb +16 -0
  50. data/lib/eco/api/usecases/default_cases/samples/cli/sftp_cli.rb +46 -0
  51. data/lib/eco/api/usecases/default_cases/samples/sftp_case.rb +21 -9
  52. data/lib/eco/api/usecases/default_cases.rb +2 -30
  53. data/lib/eco/api/usecases/graphql/utils/sftp.rb +1 -1
  54. data/lib/eco/api/usecases/use_case.rb +21 -7
  55. data/lib/eco/api/usecases/use_case_chain.rb +2 -2
  56. data/lib/eco/api/usecases.rb +4 -1
  57. data/lib/eco/assets.rb +1 -3
  58. data/lib/eco/cli/config/filters/people_filters.rb +0 -1
  59. data/lib/eco/cli/config/filters.rb +2 -6
  60. data/lib/eco/cli/config/help.rb +0 -1
  61. data/lib/eco/cli/config/input.rb +0 -1
  62. data/lib/eco/cli/config/options_set.rb +3 -4
  63. data/lib/eco/cli/config/use_cases.rb +13 -6
  64. data/lib/eco/cli/config.rb +4 -5
  65. data/lib/eco/cli/scripting/args_helpers.rb +1 -1
  66. data/lib/eco/cli/scripting/argument.rb +0 -1
  67. data/lib/eco/cli/scripting/arguments.rb +0 -2
  68. data/lib/eco/cli.rb +0 -1
  69. data/lib/eco/{cli/config/default → cli_default}/input_filters.rb +0 -1
  70. data/lib/eco/{cli/config/default → cli_default}/people_filters.rb +0 -1
  71. data/lib/eco/{cli/config/default → cli_default}/usecases.rb +2 -52
  72. data/lib/eco/{cli/config/default → cli_default}/workflow.rb +3 -2
  73. data/lib/eco/cli_default.rb +13 -0
  74. data/lib/eco/csv/table.rb +0 -1
  75. data/lib/eco/data/files/encoding.rb +1 -1
  76. data/lib/eco/data/files/helpers.rb +1 -1
  77. data/lib/eco/data/locations/convert.rb +8 -4
  78. data/lib/eco/data/locations/node_base/csv_convert.rb +4 -4
  79. data/lib/eco/data/mapper.rb +6 -1
  80. data/lib/eco/version.rb +1 -1
  81. metadata +156 -79
  82. data/lib/eco/api/usecases/default_cases/abstract_policygroup_abilities_case.rb +0 -160
  83. data/lib/eco/api/usecases/default_cases/append_usergroups_case.rb +0 -14
  84. data/lib/eco/api/usecases/default_cases/clean_unknown_tags_case.rb +0 -74
  85. data/lib/eco/api/usecases/default_cases/create_details_case.rb +0 -20
  86. data/lib/eco/api/usecases/default_cases/create_details_with_supervisor_case.rb +0 -21
  87. data/lib/eco/api/usecases/default_cases/email_as_id_case.rb +0 -12
  88. data/lib/eco/api/usecases/default_cases/new_email_case.rb +0 -13
  89. data/lib/eco/api/usecases/default_cases/new_id_case.rb +0 -12
  90. data/lib/eco/api/usecases/default_cases/remove_account_sync_case.rb +0 -10
  91. data/lib/eco/api/usecases/default_cases/remove_account_trans_case.rb +0 -16
  92. data/lib/eco/api/usecases/default_cases/reset_landing_page_case.rb +0 -18
  93. data/lib/eco/api/usecases/default_cases/set_supervisor_case.rb +0 -16
  94. data/lib/eco/api/usecases/default_cases/tagtree_case.rb +0 -42
  95. data/lib/eco/api/usecases/default_cases/update_details_case.rb +0 -15
  96. data/lib/eco/cli/config/default.rb +0 -16
  97. /data/lib/eco/{cli/config/default → cli_default}/input.rb +0 -0
  98. /data/lib/eco/{cli/config/default → cli_default}/options.rb +0 -0
  99. /data/lib/eco/{cli/config/default → cli_default}/people.rb +0 -0
@@ -0,0 +1,25 @@
1
+ module Eco
2
+ module API
3
+ class UseCases
4
+ class Default
5
+ module People
6
+ end
7
+ end
8
+ end
9
+ end
10
+ end
11
+
12
+ require_relative 'people/analyse_people_case'
13
+ require_relative 'people/change_email_case'
14
+ require_relative 'people/clean_unknown_tags_case'
15
+ require_relative 'people/clear_abilities_case'
16
+ require_relative 'people/reinvite_trans_case'
17
+ require_relative 'people/reinvite_sync_case'
18
+ require_relative 'people/org_data_convert_case'
19
+ require_relative 'people/refresh_case'
20
+ require_relative 'people/restore_db_case'
21
+ require_relative 'people/set_default_tag_case'
22
+ require_relative 'people/supers_hierarchy_case'
23
+ require_relative 'people/supers_cyclic_identify_case'
24
+ require_relative 'people/switch_supervisor_case'
25
+ require_relative 'people/transfer_account_case'
@@ -0,0 +1,16 @@
1
+ module Eco
2
+ module API
3
+ class UseCases
4
+ class Default < Eco::API::UseCases
5
+ # autoloads_children_of "Eco::API::Common::Loaders::UseCase"
6
+ # autoload_namespace "Eco::API::UseCases::Default"
7
+ # autoload_namespace "Eco::API::UseCases::DefaultCases"
8
+ # autoload_namespace "Eco::API::UseCases::OozeCases"
9
+ # autoload_namespace "Eco::API::UseCases::GraphQL::Cases"
10
+ end
11
+ end
12
+ end
13
+ end
14
+
15
+ require_relative 'default/people'
16
+ require_relative 'default/locations'
@@ -0,0 +1,46 @@
1
+ class Eco::API::UseCases::DefaultCases::Samples::Sftp
2
+ class Cli < Eco::API::UseCases::Cli
3
+ desc "SFTP case: manages remote files that match a file pattern"
4
+
5
+ add_option("-file-pattern-const", "Constant that should be used as a pattern") do |options|
6
+ pattern_const = SCR.get_arg("-file-pattern-const", with_param: true)
7
+ options.deep_merge!(sftp: {file_pattern_const: pattern_const})
8
+ end
9
+
10
+ add_option("-list", "It lists all the files present in the remote folder for the current environment.") do |options|
11
+ options.deep_merge!(sftp: {command: :list})
12
+ end
13
+
14
+ add_option("-get-last", "It gets the last file present in the remote folder for the current environment.") do |options|
15
+ options.deep_merge!(sftp: {command: :get_last})
16
+ end
17
+
18
+ add_option("-get", "It gets all the files present in the remote folder for the current environment.") do |options|
19
+ options.deep_merge!(sftp: {command: :get})
20
+ end
21
+
22
+ add_option("-archive", "It moves all the files present in the remote folder to the archive subfolder.") do |options|
23
+ options.deep_merge!(sftp: {command: :archive})
24
+ end
25
+
26
+ add_option("-local-folder", "Local folder to pull the remote files to.") do |options|
27
+ local_folder = SCR.get_file("-local-folder", required: true, should_exist: true)
28
+ options.deep_merge!(sftp: {local_folder: local_folder})
29
+ end
30
+
31
+ add_option("-remote-subfolder", "Remote sub folder to pull the remote files from.") do |options|
32
+ remote_subfolder = SCR.get_arg("-remote-subfolder", with_param: true)
33
+ options.deep_merge!(sftp: {remote_subfolder: remote_subfolder})
34
+ end
35
+
36
+ add_option("-remote-target-folder", "Overrides -remote-subfolder and -remote-folder.") do |options|
37
+ remote_target_folder = SCR.get_arg("-remote-target-folder", with_param: true)
38
+ options.deep_merge!(sftp: {remote_target_folder: remote_target_folder})
39
+ end
40
+
41
+ add_option("-remote-folder", "Overrides -remote-folder (but not -remote-subfolder).") do |options|
42
+ remote_folder = SCR.get_arg("-remote-folder", with_param: true)
43
+ options.deep_merge!(sftp: {remote_folder: remote_folder})
44
+ end
45
+ end
46
+ end
@@ -1,5 +1,9 @@
1
1
  class Eco::API::UseCases::DefaultCases::Samples::Sftp < Eco::API::Common::Loaders::UseCase
2
- name "sftp-sample"
2
+ class WrongConst < ArgumentError; end
3
+ class MissRemoteFolder < ArgumentError; end
4
+
5
+ require_relative 'cli/sftp_cli'
6
+ name "sftp"
3
7
  type :other
4
8
 
5
9
  CONST_REFERRAL = /^(?:::)?(?:[A-Z][a-zA-Z0-9_]*(?:::[A-Z][a-zA-Z0-9_]*)*)$/
@@ -22,24 +26,30 @@ class Eco::API::UseCases::DefaultCases::Samples::Sftp < Eco::API::Common::Loader
22
26
  private
23
27
 
24
28
  # Can't pass this via CLI option, as it breaks the regular expression
25
- def file_pattern
29
+ def file_pattern(require: true)
26
30
  fpc = file_pattern_const
27
31
  return fpc if fpc
28
- raise "You should redefine the file_pattern function as a RegEx expression that matches the target remote file"
32
+ raise WrongConst, "(#{self.class}) You should redefine the file_pattern function as a RegEx expression that matches the target remote file" if require
29
33
  end
30
34
 
31
35
  def file_pattern_const
32
36
  if fpc = options.dig(:sftp, :file_pattern_const)
33
- raise "Invalid file pattern const referral: #{fpc}" unless fpc.match(CONST_REFERRAL)
34
- self.eval(fpc)
37
+ raise WrongConst, "(#{self.class}) Invalid file pattern const referral: #{fpc}" unless fpc.match(CONST_REFERRAL)
38
+ begin
39
+ self.eval(fpc)
40
+ rescue NameError
41
+ self.class.const_get(fpc)
42
+ end
35
43
  end
44
+ rescue NameError
45
+ raise WrongConst, "(#{self.class}) Unknown constant: #{fpc}"
36
46
  end
37
47
 
38
48
  # Ex: "/IN/Personnel"
39
- def remote_subfolder
49
+ def remote_subfolder(require: true)
40
50
  rm_sf = options.dig(:sftp, :remote_subfolder)
41
51
  return rm_sf if rm_sf
42
- raise "You should redefine remote_subfolder as the folder where the target file sits. Ex: /IN/Personnel"
52
+ raise MissRemoteFolder, "(#{self.class}) You should redefine remote_subfolder as the folder where the target file sits. Ex: /IN/Personnel" if require
43
53
  end
44
54
 
45
55
  # `remote_target_folder` overrides `sftp_config.remote_folder` as well as `remote_subfolder`
@@ -63,8 +73,10 @@ class Eco::API::UseCases::DefaultCases::Samples::Sftp < Eco::API::Common::Loader
63
73
  sftp.files(remote_folder, pattern: file_pattern).each do |remote_file|
64
74
  yield(remote_file) if block_given?
65
75
  end
66
- rescue Net::SFTP::StatusException => e
67
- logger.error("SFTP samplecase: There was an error trying to access the remote folder '#{remote_folder}'")
76
+ rescue ArgumentError
77
+ raise
78
+ rescue ::Net::SFTP::StatusException => e
79
+ logger.error("(#{self.class}) There was an error trying to access the remote folder '#{remote_folder}'")
68
80
  []
69
81
  end
70
82
  end
@@ -3,50 +3,22 @@ module Eco
3
3
  class UseCases
4
4
  class DefaultCases < Eco::API::UseCases
5
5
  autoloads_children_of "Eco::API::Common::Loaders::UseCase"
6
+ autoload_namespace "Eco::API::UseCases::Default"
6
7
  autoload_namespace "Eco::API::UseCases::DefaultCases"
7
8
  autoload_namespace "Eco::API::UseCases::OozeCases"
9
+ autoload_namespace "Eco::API::UseCases::GraphQL::Cases"
8
10
  end
9
11
  end
10
12
  end
11
13
  end
12
14
 
13
15
  require_relative 'default_cases/samples'
14
- require_relative 'default_cases/abstract_policygroup_abilities_case.rb'
15
- require_relative 'default_cases/analyse_people_case'
16
- require_relative 'default_cases/append_usergroups_case'
17
- require_relative 'default_cases/change_email_case'
18
- require_relative 'default_cases/clean_unknown_tags_case'
19
- require_relative 'default_cases/clear_abilities_case'
20
- require_relative 'default_cases/codes_to_tags_case'
21
16
  require_relative 'default_cases/create_case'
22
- require_relative 'default_cases/create_details_case'
23
- require_relative 'default_cases/create_details_with_supervisor_case'
24
- require_relative 'default_cases/create_tag_paths_case'
25
- require_relative 'default_cases/csv_to_tree_case'
26
17
  require_relative 'default_cases/delete_trans_case'
27
18
  require_relative 'default_cases/delete_sync_case'
28
- require_relative 'default_cases/email_as_id_case'
29
19
  require_relative 'default_cases/hris_case'
30
- require_relative 'default_cases/new_id_case'
31
- require_relative 'default_cases/new_email_case'
32
20
  require_relative 'default_cases/entries_to_csv_case'
33
- require_relative 'default_cases/org_data_convert_case'
34
- require_relative 'default_cases/refresh_case'
35
- require_relative 'default_cases/reinvite_trans_case'
36
- require_relative 'default_cases/reinvite_sync_case'
37
- require_relative 'default_cases/remove_account_trans_case'
38
- require_relative 'default_cases/remove_account_sync_case'
39
- require_relative 'default_cases/reset_landing_page_case'
40
- require_relative 'default_cases/restore_db_case'
41
- require_relative 'default_cases/set_default_tag_case'
42
- require_relative 'default_cases/set_supervisor_case'
43
- require_relative 'default_cases/supers_hierarchy_case'
44
- require_relative 'default_cases/supers_cyclic_identify_case'
45
- require_relative 'default_cases/switch_supervisor_case'
46
- require_relative 'default_cases/tagtree_case'
47
21
  require_relative 'default_cases/to_csv_case'
48
22
  require_relative 'default_cases/to_csv_detailed_case'
49
- require_relative 'default_cases/transfer_account_case'
50
23
  require_relative 'default_cases/update_case'
51
- require_relative 'default_cases/update_details_case'
52
24
  require_relative 'default_cases/upsert_case'
@@ -20,7 +20,7 @@ module Eco::API::UseCases::GraphQL::Utils
20
20
  end
21
21
 
22
22
  def upload(local_file, remote_folder: self.remote_folder, gid: sftp_group_id)
23
- return false unless local_file && File.exists?(local_file)
23
+ return false unless local_file && File.exist?(local_file)
24
24
  dest_file = "#{remote_folder}/#{File.basename(local_file)}"
25
25
  res = sftp_session.upload!(local_file, dest_file)
26
26
  attrs = sftp_session.stat!(dest_file)
@@ -45,14 +45,20 @@ module Eco
45
45
  kargs = params.merge(kargs).merge(usecase: self)
46
46
 
47
47
  UseCaseIO.new(**kargs).tap do |uio|
48
- @options = uio.options
48
+ @options = uio.options
49
49
  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)
50
+ set_session_n_options(uio) if callback_from_loader?
51
+ uio.output = callback.call(*uio.params)
52
52
  @times_launched += 1
53
53
  end
54
54
  end
55
55
 
56
+ # When it was defined from a Loader class it retrieves the object.
57
+ # @return [Eco::API::Common::Loaders::Base, NilClass]
58
+ def classed_definition
59
+ callback_self if callback_from_loader?
60
+ end
61
+
56
62
  protected
57
63
 
58
64
  def callback
@@ -60,7 +66,7 @@ module Eco
60
66
  end
61
67
 
62
68
  def callback_self
63
- eval("self", @callback.binding)
69
+ eval("self", callback.binding)
64
70
  end
65
71
 
66
72
  def callback_from_loader?
@@ -71,12 +77,20 @@ module Eco
71
77
  # in the use case definition
72
78
  # @note this only works when the use case was defined
73
79
  # via an children class of `Eco::API::Common::Loaders::Base`
74
- def set_session_n_options(session:, options: @options)
80
+ def set_session_n_options(uio)
75
81
  return false unless callback_from_loader?
82
+ opts = uio.options || @options
83
+ sess = uio.session
84
+ peo = uio.people
85
+ ent = uio.input
76
86
  use_case_self = self
87
+
77
88
  callback_self.instance_eval do
78
- @session = session
79
- @options = options
89
+ @session = sess
90
+ @options = opts
91
+ @people = peo if peo
92
+ @input = ent if ent
93
+
80
94
  # `self` is the use case itself (when used the Loader)
81
95
  next unless self.is_a?(Eco::API::Common::Loaders::CaseBase)
82
96
  @usecase = use_case_self
@@ -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
@@ -34,8 +34,7 @@ module Eco
34
34
  def cli
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
39
  @cli
41
40
  end
@@ -44,5 +43,4 @@ 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
 
@@ -20,7 +20,8 @@ ASSETS.cli.config do |config|
20
20
  end
21
21
 
22
22
  wf.on(:options) do |wf_options, io|
23
- io = io.new(options: config.options_set.process(io: io))
23
+ config.usecases.cli_apply(io: io)
24
+ io = io.new(options: config.options_set.process(io: io))
24
25
  end
25
26
 
26
27
  wf.for(:load) do |wf_load|
@@ -115,7 +116,7 @@ ASSETS.cli.config do |config|
115
116
  elsif !partial_update
116
117
  msg += ", because it is not a partial update (-get-partial option not present)."
117
118
  end
118
- io.session.logger.warn(msg)
119
+ io.session.logger.info(msg)
119
120
  end
120
121
  else
121
122
  wf_post.skip!