eco-helpers 0.8.3 → 0.8.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/eco-helpers.gemspec +0 -2
- data/lib/eco-helpers.rb +0 -1
- data/lib/eco/api/common/people/person_entry.rb +67 -30
- data/lib/eco/api/common/version_patches.rb +2 -1
- data/lib/eco/api/common/version_patches/base_model.rb +27 -0
- data/lib/eco/api/organization/people.rb +6 -0
- data/lib/eco/api/organization/tag_tree.rb +6 -0
- data/lib/eco/api/policies/policy.rb +2 -2
- data/lib/eco/api/session.rb +23 -30
- data/lib/eco/api/session/batch.rb +3 -2
- data/lib/eco/api/session/batch_job.rb +18 -10
- data/lib/eco/api/session/batch_status.rb +27 -11
- data/lib/eco/api/session/config.rb +20 -7
- data/lib/eco/api/usecases/default_cases/change_email_case.rb +2 -6
- data/lib/eco/api/usecases/default_cases/refresh_presets_case.rb +3 -2
- data/lib/eco/api/usecases/use_case.rb +6 -5
- data/lib/eco/api/usecases/use_case_chain.rb +3 -3
- data/lib/eco/api/usecases/use_case_io.rb +3 -3
- data/lib/eco/assets.rb +3 -1
- data/lib/eco/{common → assets}/language.rb +2 -2
- data/lib/eco/cli.rb +3 -4
- data/lib/eco/cli/config.rb +10 -0
- data/lib/eco/cli/config/options.rb +11 -0
- data/lib/eco/cli/scripting.rb +23 -0
- data/lib/eco/cli/scripting/args_helpers.rb +55 -0
- data/lib/eco/cli/scripting/argument.rb +31 -0
- data/lib/eco/cli/scripting/arguments.rb +70 -0
- data/lib/eco/common.rb +1 -3
- data/lib/eco/data/crypto/encryption.rb +2 -2
- data/lib/eco/language/models/collection.rb +1 -1
- data/lib/eco/version.rb +1 -1
- metadata +9 -62
- data/lib/eco/cli/api.rb +0 -14
- data/lib/eco/cli/root.rb +0 -9
- data/lib/eco/cli/session.rb +0 -9
- data/lib/eco/cli/session/batch.rb +0 -9
- data/lib/eco/common/base_cli.rb +0 -23
- data/lib/eco/common/base_cli_backup.rb +0 -120
- data/lib/eco/common/meta_thor.rb +0 -111
- data/lib/eco/common/meta_thor/command_group.rb +0 -36
- data/lib/eco/common/meta_thor/command_unit.rb +0 -48
- data/lib/eco/common/meta_thor/input_backup.rb +0 -111
- data/lib/eco/common/meta_thor/input_multi_backup.rb +0 -139
- data/lib/eco/common/meta_thor/pipe.rb +0 -85
- data/lib/eco/common/meta_thor/thor.rb +0 -1
- data/lib/eco/common/meta_thor/thor/command.rb +0 -36
- data/lib/eco/common/meta_thor/value.rb +0 -54
- data/lib/eco/scripting.rb +0 -32
- data/lib/eco/scripting/README.md +0 -11
- data/lib/eco/scripting/args_helpers.rb +0 -53
- data/lib/eco/scripting/argument.rb +0 -29
- data/lib/eco/scripting/arguments.rb +0 -68
@@ -5,8 +5,6 @@ module Eco
|
|
5
5
|
TYPES = [:get, :create, :update, :delete]
|
6
6
|
SETS = [:core, :details, :account]
|
7
7
|
|
8
|
-
attr_reader :name, :status
|
9
|
-
|
10
8
|
class << self
|
11
9
|
def valid_type?(value)
|
12
10
|
TYPES.include?(value)
|
@@ -18,15 +16,20 @@ module Eco
|
|
18
16
|
end
|
19
17
|
end
|
20
18
|
|
21
|
-
|
19
|
+
attr_reader :name, :status
|
20
|
+
attr_reader :usecase
|
21
|
+
|
22
|
+
def initialize(e, name:, type:, sets:, usecase: nil)
|
22
23
|
raise "A name is required to refer a job. Given: #{name}" if !name
|
23
24
|
raise "Type should be one of #{TYPES}. Given: #{type}" if !self.class.valid_type?(type)
|
24
25
|
raise "Sets should be some of #{SETS}. Given: #{sets}" if !self.class.valid_sets?(sets)
|
26
|
+
raise "usecase must be a Eco::API::UseCases::UseCase object. Given: #{usecase.class}" if usecase && !usecase.is_a?(Eco::API::UseCases::UseCase)
|
25
27
|
super(e)
|
26
28
|
|
27
|
-
@name
|
28
|
-
@type
|
29
|
-
@
|
29
|
+
@name = name
|
30
|
+
@type = type
|
31
|
+
@usecase = usecase
|
32
|
+
@sets = [sets].flatten.compact
|
30
33
|
reset
|
31
34
|
end
|
32
35
|
|
@@ -37,8 +40,12 @@ module Eco
|
|
37
40
|
@status = nil
|
38
41
|
end
|
39
42
|
|
43
|
+
def usecase?
|
44
|
+
!!usecase
|
45
|
+
end
|
46
|
+
|
40
47
|
def signature
|
41
|
-
"job \"#{
|
48
|
+
"job \"#{name}\" ['#{@type.to_s.upcase}': #{sets_title}]"
|
42
49
|
end
|
43
50
|
|
44
51
|
def match?(type:, sets:)
|
@@ -47,7 +54,7 @@ module Eco
|
|
47
54
|
end
|
48
55
|
|
49
56
|
def pending?
|
50
|
-
|
57
|
+
!@status
|
51
58
|
end
|
52
59
|
|
53
60
|
def core?
|
@@ -124,7 +131,7 @@ module Eco
|
|
124
131
|
@status.queue.map do |entry|
|
125
132
|
if @status.success?(entry)
|
126
133
|
entry.consolidate! if entry.respond_to?(:consolidate!)
|
127
|
-
#else # shouldn't probably reset, as the model
|
134
|
+
#else # shouldn't probably reset, as the model should remain dirty? (well tracaked)
|
128
135
|
# entry.reset! if entry.respond_to?(:reset!)
|
129
136
|
end
|
130
137
|
end
|
@@ -139,7 +146,8 @@ module Eco
|
|
139
146
|
pre_queue.tap do |entries|
|
140
147
|
policies = session.config.policies
|
141
148
|
unless policies.empty?
|
142
|
-
|
149
|
+
options = usecase?? usecase.options : {}
|
150
|
+
policies.launch(people: people(entries), session: session, options: options)
|
143
151
|
end
|
144
152
|
end
|
145
153
|
end
|
@@ -4,6 +4,7 @@ module Eco
|
|
4
4
|
class BatchStatus < Common::Session::BaseSession
|
5
5
|
TYPES = [:exact, :search]
|
6
6
|
|
7
|
+
attr_reader :source_queue
|
7
8
|
attr_reader :queue, :method, :type
|
8
9
|
attr_reader :root
|
9
10
|
|
@@ -17,9 +18,19 @@ module Eco
|
|
17
18
|
super(e)
|
18
19
|
fatal("In batch operations you must batch an Enumerable. Received: #{queue}") unless queue && queue.is_a?(Enumerable)
|
19
20
|
|
20
|
-
self.type
|
21
|
-
@method
|
21
|
+
self.type = type
|
22
|
+
@method = method
|
23
|
+
@source_queue = queue
|
24
|
+
|
25
|
+
que = queue.to_a
|
26
|
+
que = queue if queue.respond_to?(:uniq)
|
27
|
+
if que.length != que.uniq.length
|
28
|
+
logger.warn("Please, review your entries-to-query builder, you have repeated entries")
|
29
|
+
queue = que.uniq
|
30
|
+
end
|
31
|
+
|
22
32
|
@queue = queue
|
33
|
+
|
23
34
|
@hash = @queue.each_with_index.map do |entry, i|
|
24
35
|
[entry, i]
|
25
36
|
end.to_h
|
@@ -96,12 +107,12 @@ module Eco
|
|
96
107
|
def error_queries
|
97
108
|
queue.each_with_index.map do |query,i|
|
98
109
|
unless self[i]
|
99
|
-
|
100
|
-
msg
|
110
|
+
msg = "Error: query with no response. You might have duplicated entries in your queue.\n"
|
111
|
+
msg += "Queue length: #{queue.length}; Queue elements class: #{queue.first.class}\n"
|
101
112
|
msg += "Query with no response. Person: #{person_ref(query)}\n"
|
102
113
|
queue.map do |entry|
|
103
|
-
if
|
104
|
-
msg += "It could be this peson entry: #{person_ref(entry)}\n"
|
114
|
+
if [:id, :external_id, :email].any? {|attr| (v = get_attr(entry, attr)) && v == get_attr(query, attr)}
|
115
|
+
msg += "It could be this peson entry (idx: #{to_index(entry)}): #{person_ref(entry)}\n"
|
105
116
|
end
|
106
117
|
end
|
107
118
|
raise msg
|
@@ -123,7 +134,7 @@ module Eco
|
|
123
134
|
msg = ""
|
124
135
|
unless success?(key)
|
125
136
|
i = to_index(key)
|
126
|
-
entry = queue[i]
|
137
|
+
entry = queue.to_a[i]
|
127
138
|
response = self[i]
|
128
139
|
msg = "Error #{response.status}: #{response.body}\n"
|
129
140
|
msg += "-- Failed to batch #{method} (entry #{i+1}). Person: #{person_ref(entry)}"
|
@@ -165,10 +176,15 @@ module Eco
|
|
165
176
|
private
|
166
177
|
|
167
178
|
def person_ref(entry)
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
179
|
+
"(id: '#{get_attr(entry, :id)}')'#{get_attr(entry, :name)}' ('#{get_attr(entry, :external_id)}': '#{get_attr(entry, :email)}')"
|
180
|
+
end
|
181
|
+
|
182
|
+
def get_attr(entry, attr)
|
183
|
+
if entry.respond_to?(attr.to_sym)
|
184
|
+
entry.public_send(attr.to_sym)
|
185
|
+
elsif entry.is_a?(Hash)
|
186
|
+
entry["#{attr}"]
|
187
|
+
end
|
172
188
|
end
|
173
189
|
|
174
190
|
def to_index(key)
|
@@ -24,24 +24,28 @@ module Eco
|
|
24
24
|
yield(self)
|
25
25
|
end
|
26
26
|
|
27
|
+
def cli
|
28
|
+
self["cli"] ||= Eco::CLI::Config.new
|
29
|
+
end
|
30
|
+
|
27
31
|
def apis
|
28
|
-
self["apis"]
|
32
|
+
self["apis"] ||= Eco::API::Session::Config::Apis.new(config: self)
|
29
33
|
end
|
30
34
|
|
31
35
|
def logger
|
32
|
-
self["logger"]
|
36
|
+
self["logger"] ||= Eco::API::Session::Config::Logger.new(config: self)
|
33
37
|
end
|
34
38
|
|
35
39
|
def s3storage
|
36
|
-
self["s3_storage"] ||= Session::Config::S3Storage.new(config: self)
|
40
|
+
self["s3_storage"] ||= Eco::API::Session::Config::S3Storage.new(config: self)
|
37
41
|
end
|
38
42
|
|
39
43
|
def files
|
40
|
-
self["files"]
|
44
|
+
self["files"] ||= Eco::API::Session::Config::Files.new(config: self)
|
41
45
|
end
|
42
46
|
|
43
47
|
def mailer
|
44
|
-
self["mailer"]
|
48
|
+
self["mailer"] ||= Eco::API::Session::Config::Mailer.new(config: self)
|
45
49
|
end
|
46
50
|
|
47
51
|
def org
|
@@ -49,7 +53,7 @@ module Eco
|
|
49
53
|
end
|
50
54
|
|
51
55
|
def people
|
52
|
-
self["people"]
|
56
|
+
self["people"] ||= Eco::API::Session::Config::People.new(config: self)
|
53
57
|
end
|
54
58
|
|
55
59
|
# LOGGER
|
@@ -163,9 +167,18 @@ module Eco
|
|
163
167
|
org["tagtree"] = file
|
164
168
|
end
|
165
169
|
|
170
|
+
def tagtree(enviro: nil)
|
171
|
+
return @tagtree if instance_variable_defined?(:@tagtree) && @tagtree.enviro == enviro
|
172
|
+
if tree_file = org["tagtree"]
|
173
|
+
tree = []
|
174
|
+
tree = file_manager.load_json(tree_file) unless !tree_file
|
175
|
+
@tagtree = Eco::API::Organization::TagTree.new(tree, enviro: enviro)
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
166
179
|
def policy_groups
|
167
180
|
return @policy_groups if instance_variable_defined?(:@policy_groups)
|
168
|
-
pgs
|
181
|
+
pgs = api&.policy_groups.to_a
|
169
182
|
@policy_groups = Eco::API::Organization::PolicyGroups.new(pgs)
|
170
183
|
end
|
171
184
|
|
@@ -6,8 +6,8 @@ module Eco
|
|
6
6
|
|
7
7
|
def process
|
8
8
|
@cases.define("change-email", type: :sync) do |entries, people, session, options|
|
9
|
-
remove
|
10
|
-
change
|
9
|
+
remove = session.job_group("main").new("remove account", type: :update, sets: :account)
|
10
|
+
change = session.job_group("main").new("change email", type: :update, sets: :core)
|
11
11
|
add_account = session.job_group("post").new("add account", type: :update, sets: :account)
|
12
12
|
|
13
13
|
strict_search = session.config.people.strict_search? && (!options[:search]&.key?(:strict) || options.dig(:search, :strict))
|
@@ -25,15 +25,11 @@ module Eco
|
|
25
25
|
|
26
26
|
new_email = entry.email
|
27
27
|
change.add(person) do |person|
|
28
|
-
person.sync
|
29
28
|
person.email = new_email
|
30
|
-
person
|
31
29
|
end
|
32
30
|
|
33
31
|
add_account.add(person) do |person|
|
34
|
-
person.sync
|
35
32
|
person.account = account
|
36
|
-
person
|
37
33
|
end
|
38
34
|
end
|
39
35
|
|
@@ -8,8 +8,9 @@ module Eco
|
|
8
8
|
@cases.define("refresh-presets", type: :transform) do |people, session|
|
9
9
|
job = session.job_group("main").new("update", type: :update, sets: :account)
|
10
10
|
|
11
|
-
|
12
|
-
people.
|
11
|
+
users = people.users
|
12
|
+
session.logger.warn("There are no people with account amoung your #{people.length} people")
|
13
|
+
users.each do |person|
|
13
14
|
person.account.permissions_custom = session.new_preset(person)
|
14
15
|
job.add(person)
|
15
16
|
end
|
@@ -10,9 +10,7 @@ module Eco
|
|
10
10
|
transform: [:people, :session],
|
11
11
|
export: [:people, :session, :options]
|
12
12
|
}
|
13
|
-
|
14
|
-
attr_reader :name, :type, :times_launched
|
15
|
-
|
13
|
+
|
16
14
|
class << self
|
17
15
|
def valid_type?(type)
|
18
16
|
TYPES.include?(type)
|
@@ -24,14 +22,16 @@ module Eco
|
|
24
22
|
end
|
25
23
|
end
|
26
24
|
|
27
|
-
|
25
|
+
attr_reader :name, :type, :times_launched
|
26
|
+
attr_reader :options
|
27
|
+
|
28
|
+
def initialize(name, type:, root:, &block)
|
28
29
|
raise "Undefined usecase type #{type}, when creating '#{name}'. Please, use any of #{TYPES}" unless self.class.valid_type?(type)
|
29
30
|
|
30
31
|
self.root = root
|
31
32
|
@case = block
|
32
33
|
@name = name
|
33
34
|
@type = type
|
34
|
-
@options = options
|
35
35
|
@times_launched = 0
|
36
36
|
end
|
37
37
|
|
@@ -41,6 +41,7 @@ module Eco
|
|
41
41
|
end
|
42
42
|
|
43
43
|
def launch(input: nil, people: nil, session:, options: {})
|
44
|
+
@options = options
|
44
45
|
data = UseCaseIO.new(usecase: self, input: input, people: people, session: session, options: options)
|
45
46
|
|
46
47
|
data.output = @case.call(data.params)
|
@@ -5,8 +5,8 @@ module Eco
|
|
5
5
|
MAX_CHAINS = 70
|
6
6
|
@@num_chains = 0
|
7
7
|
|
8
|
-
def initialize(name, type:, root:,
|
9
|
-
super(name, type: type, root: root,
|
8
|
+
def initialize(name, type:, root:, &block)
|
9
|
+
super(name, type: type, root: root, &block)
|
10
10
|
@chains = []
|
11
11
|
@resolved_chains = nil
|
12
12
|
end
|
@@ -17,7 +17,7 @@ module Eco
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def use(preserve_chains: false, recursive: false)
|
20
|
-
UseCase.new(@name, type: @type, root: @root,
|
20
|
+
UseCase.new(@name, type: @type, root: @root, &@case).tap do |newcase|
|
21
21
|
if preserve_chains
|
22
22
|
chain_use = {preserve_chains: recursive, recursive: recursive}
|
23
23
|
@chains = @chains.map do |usecase|
|
@@ -87,13 +87,13 @@ module Eco
|
|
87
87
|
when !session.is_a?(Eco::API::Session)
|
88
88
|
raise "A UseCase needs a Session object. Given: #{session}"
|
89
89
|
when input_required? && !input
|
90
|
-
raise "UseCase of type '#{
|
90
|
+
raise "UseCase of type '#{type}' requires a valid input. None given"
|
91
91
|
when people_required? && !people.is_a?(Eco::API::Organization::People)
|
92
|
-
raise "UseCase of type '#{
|
92
|
+
raise "UseCase of type '#{type}' requires a People object. Given: #{people}"
|
93
93
|
when !options || (options && !options.is_a?(Hash))
|
94
94
|
raise "To inject dependencies via ':options' it should be a Hash object. Given: #{options}"
|
95
95
|
when options_required? && !options
|
96
|
-
raise "UseCase of type '#{
|
96
|
+
raise "UseCase of type '#{type}' requires a Hash ':options' object."
|
97
97
|
end
|
98
98
|
true
|
99
99
|
end
|
data/lib/eco/assets.rb
CHANGED
data/lib/eco/cli.rb
CHANGED
@@ -0,0 +1,23 @@
|
|
1
|
+
require_relative 'scripting/args_helpers'
|
2
|
+
require_relative 'scripting/argument'
|
3
|
+
require_relative 'scripting/arguments'
|
4
|
+
|
5
|
+
module Eco
|
6
|
+
class CLI
|
7
|
+
class Scripting
|
8
|
+
include Scripting::ArgsHelpers
|
9
|
+
|
10
|
+
def args_contain?(*values)
|
11
|
+
match?(ARGV, patterns, [:any, :or, :insensitive, :pattern])
|
12
|
+
end
|
13
|
+
|
14
|
+
def modifiers(*values)
|
15
|
+
values.select { |arg| is_modifier?(arg) }
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
SCR = Eco::CLI::Scripting.new
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module Eco
|
2
|
+
class CLI
|
3
|
+
class Scripting
|
4
|
+
module ArgsHelpers
|
5
|
+
|
6
|
+
def is_modifier?(value)
|
7
|
+
value&.start_with?("-")
|
8
|
+
end
|
9
|
+
|
10
|
+
def arguments
|
11
|
+
@arguments ||= Arguments.new
|
12
|
+
end
|
13
|
+
|
14
|
+
def stop_on_unknown!(exclude: [])
|
15
|
+
if arguments.any_unkown?(exclude: exclude)
|
16
|
+
raise "There are unknown options in your command line arguments: #{arguments.unknown(exclude: exclude)}"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def get_arg(key, with_param: false, valid: true)
|
21
|
+
# track what a known option looks like
|
22
|
+
arguments.add(key, with_param: with_param)
|
23
|
+
return nil if !ARGV.include?(key)
|
24
|
+
value = true
|
25
|
+
if with_param
|
26
|
+
next_i = ARGV.index(key) + 1
|
27
|
+
value = ARGV[next_i]
|
28
|
+
#puts "modifier argument: #{value}"
|
29
|
+
value = nil if valid && is_modifier?(value)
|
30
|
+
end
|
31
|
+
return value
|
32
|
+
end
|
33
|
+
|
34
|
+
def get_file(key, required: false, should_exist: true)
|
35
|
+
filename = get_arg(key, with_param: true)
|
36
|
+
if !filename
|
37
|
+
if required
|
38
|
+
puts "you need to specify a file '#{key} file'"
|
39
|
+
exit
|
40
|
+
end
|
41
|
+
elsif !(File.exists?(filename) || File.exists?(File.expand_path(filename)))
|
42
|
+
if should_exist && required
|
43
|
+
puts "file doesn't exist #{filename}"
|
44
|
+
exit
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
filename = File.expand_path(filename) if filename && should_exist
|
49
|
+
filename
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|