Class: Eco::API::Session::Config
- Inherits:
-
Hash
- Object
- Hash
- Eco::API::Session::Config
show all
- Defined in:
- lib/eco/api/session/config.rb,
lib/eco/api/session/config/api.rb,
lib/eco/api/session/config/apis.rb,
lib/eco/api/session/config/sftp.rb,
lib/eco/api/session/config/files.rb,
lib/eco/api/session/config/logger.rb,
lib/eco/api/session/config/mailer.rb,
lib/eco/api/session/config/people.rb,
lib/eco/api/session/config/workflow.rb,
lib/eco/api/session/config/s3_storage.rb,
lib/eco/api/session/config/base_config.rb,
lib/eco/api/session/config/post_launch.rb
Defined Under Namespace
Classes: Api, Apis, BaseConfig, Files, Logger, Mailer, People, PostLaunch, S3Storage, SFTP, Workflow
Instance Attribute Summary collapse
Config instance pure methods
collapse
Additional resources
collapse
Organization related shortcuts
collapse
People shortcuts
collapse
Session workflow and batch job launces
collapse
Instance Method Summary
collapse
Methods inherited from Hash
#deep_merge, #deep_merge!
Constructor Details
#initialize(name = :default) ⇒ Config
Returns a new instance of Config.
7
8
9
10
11
|
# File 'lib/eco/api/session/config.rb', line 7
def initialize(name = :default)
super(nil)
@name = name
self["org"] = {}
end
|
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
5
6
7
|
# File 'lib/eco/api/session/config.rb', line 5
def name
@name
end
|
Instance Method Details
Set the active api by name
106
107
108
109
|
# File 'lib/eco/api/session/config.rb', line 106
def active_api(name)
apis.active_name = name
self
end
|
#active_enviro ⇒ Object
112
113
114
|
# File 'lib/eco/api/session/config.rb', line 112
def active_enviro
apis.active_root_name
end
|
Returns this configuration.
98
99
100
101
|
# File 'lib/eco/api/session/config.rb', line 98
def add_api(name, **kargs)
apis.add(name, **kargs)
self
end
|
Returns the currently active api.
118
119
120
|
# File 'lib/eco/api/session/config.rb', line 118
def api(logger = ::Logger.new(IO::NULL), version: nil)
apis.api(logger, version: version)
end
|
87
88
89
|
# File 'lib/eco/api/session/config.rb', line 87
def apis
self["apis"] ||= Eco::API::Session::Config::Apis.new(config: self)
end
|
#apis? ⇒ Boolean
Returns true if there is any api configuration defined, false otherwise.
92
93
94
|
# File 'lib/eco/api/session/config.rb', line 92
def apis?
apis.apis?
end
|
362
363
364
365
366
367
368
369
370
|
# File 'lib/eco/api/session/config.rb', line 362
def batch_policies
@batch_policies = self["batch_policies"] ||= Eco::API::Session::Batch::Policies.new("batch_policy")
if block_given?
yield(@batch_policies)
self
else
@batch_policies
end
end
|
#clone(name) ⇒ Object
15
16
17
18
19
20
21
22
23
|
# File 'lib/eco/api/session/config.rb', line 15
def clone(name)
keys.each_with_object(self.class.new(name)) do |key, cnf|
begin
cnf[key] = self[key].clone(config: cnf)
rescue ArgumentError
cnf[key] = self[key].clone
end
end
end
|
#default_login_method=(name) ⇒ Object
Set the default login method that users should acquire.
320
321
322
|
# File 'lib/eco/api/session/config.rb', line 320
def default_login_method=(name)
people.default_login_method = name
end
|
#default_schema=(name) ⇒ Object
Set the default schema this api org configuration should work on.
315
316
317
|
# File 'lib/eco/api/session/config.rb', line 315
def default_schema=(name)
people.default_schema = name
end
|
#default_usergroup=(value) ⇒ Object
Define the default usergroup that should be given to people with no usergroups.
290
291
292
|
# File 'lib/eco/api/session/config.rb', line 290
def default_usergroup=(value)
people.default_usergroup = value
end
|
#delay_between_job_groups(seconds = nil) ⇒ nil, Interger
Returns seconds between job groups.
398
399
400
401
|
# File 'lib/eco/api/session/config.rb', line 398
def delay_between_job_groups(seconds = nil)
self["delay_between_job_groups"] = seconds if seconds
self["delay_between_job_groups"]
end
|
#delay_between_jobs(seconds = nil) ⇒ nil, Interger
Returns seconds between jobs.
392
393
394
395
|
# File 'lib/eco/api/session/config.rb', line 392
def delay_between_jobs(seconds = nil)
self["delay_between_jobs"] = seconds if seconds
self["delay_between_jobs"]
end
|
#discarded_people_file=(value) ⇒ Object
Specify the file that holds the csv with people to be excluded from API updates.
295
296
297
|
# File 'lib/eco/api/session/config.rb', line 295
def discarded_people_file=(value)
people.discarded_file = value
end
|
#dry_run! ⇒ Object
Deprecated. old helper to fix the dry-run mode
Note:
this is now done via options[:dry_run], parsed as an option
139
140
141
|
# File 'lib/eco/api/session/config.rb', line 139
def dry_run!
self["dry-run"] = true
end
|
#dry_run? ⇒ Boolean
Deprecated. old helper to check if we are in dry-run mode
Note:
this is now done via options[:dry_run], which is parsed as an option
145
146
147
|
# File 'lib/eco/api/session/config.rb', line 145
def dry_run?
self["dry-run"]
end
|
373
374
375
376
377
378
379
380
381
|
# File 'lib/eco/api/session/config.rb', line 373
def error_handlers
@error_handlers = self["error_handlers"] ||= Eco::API::Error::Handlers.new
if block_given?
yield(@error_handlers)
self
else
@error_handlers
end
end
|
#file_timestamp_pattern=(pattern) ⇒ Object
180
181
182
|
# File 'lib/eco/api/session/config.rb', line 180
def file_timestamp_pattern=(pattern)
files.timestamp_pattern = pattern
end
|
153
154
155
|
# File 'lib/eco/api/session/config.rb', line 153
def files
self["files"] ||= Eco::API::Session::Config::Files.new(config: self)
end
|
Note:
it requires graphql connection configuration parameters
It obtains the first of the live tagtree in the org
247
248
249
250
251
252
253
254
255
256
257
|
# File 'lib/eco/api/session/config.rb', line 247
def live_tree(enviro: nil)
return @live_tree if instance_variable_defined?(:@live_tree) && @live_tree.enviro == enviro
if apis.active_api.version_available?(:graphql)
graphql = apis.api(version: :graphql)
if tree = graphql.currentOrganization.tagTrees.to_a.first.treeify
@live_tree = Eco::API::Organization::TagTree.new(tree, enviro: enviro)
else
@live_tree = nil
end
end
end
|
#location_codes ⇒ Object
217
218
219
|
# File 'lib/eco/api/session/config.rb', line 217
def location_codes
org["location_codes"]
end
|
#location_codes=(file) ⇒ Object
213
214
215
|
# File 'lib/eco/api/session/config.rb', line 213
def location_codes=(file)
org["location_codes"] = file
end
|
#locations_mapper ⇒ Object
221
222
223
224
225
|
# File 'lib/eco/api/session/config.rb', line 221
def locations_mapper
return @locations_mapper if instance_variable_defined?(:@locations_mapper)
file = file_manager.newest(location_codes)
@locations_mapper = Eco::Data::Mapper.new(file_manager.load_json(file), internal: :first)
end
|
#log_connection=(value) ⇒ Object
74
75
76
|
# File 'lib/eco/api/session/config.rb', line 74
def log_connection=(value)
logger.log_connection = value
end
|
#log_console_level=(value) ⇒ Object
58
59
60
|
# File 'lib/eco/api/session/config.rb', line 58
def log_console_level=(value)
logger.console_level= value
end
|
#log_file=(file) ⇒ Object
66
67
68
|
# File 'lib/eco/api/session/config.rb', line 66
def log_file=(file)
logger.file = file
end
|
#log_file_level=(value) ⇒ Object
62
63
64
|
# File 'lib/eco/api/session/config.rb', line 62
def log_file_level=(value)
logger.file_level = value
end
|
54
55
56
|
# File 'lib/eco/api/session/config.rb', line 54
def logger
self["logger"] ||= Eco::API::Session::Config::Logger.new(config: self)
end
|
274
275
276
277
278
|
# File 'lib/eco/api/session/config.rb', line 274
def login_providers
return @login_providers if instance_variable_defined?(:@login_providers)
provs = api&.login_providers.to_a
@login_providers = Eco::API::Organization::LoginProviders.new(provs)
end
|
46
47
48
|
# File 'lib/eco/api/session/config.rb', line 46
def mailer
self["mailer"] ||= Eco::API::Session::Config::Mailer.new(config: self)
end
|
#org ⇒ Object
209
210
211
|
# File 'lib/eco/api/session/config.rb', line 209
def org
self["org"]
end
|
285
286
287
|
# File 'lib/eco/api/session/config.rb', line 285
def people
self["people"] ||= Eco::API::Session::Config::People.new(config: self)
end
|
#people_cache=(file) ⇒ Object
Set the base folder/name.ext name of the fieles where people will be cached.
300
301
302
|
# File 'lib/eco/api/session/config.rb', line 300
def people_cache=(file)
people.cache = file
end
|
#person_fields_mapper=(file) ⇒ Object
Specify the .json file name with the mappings [DataInputColumnName, internal-name].
310
311
312
|
# File 'lib/eco/api/session/config.rb', line 310
def person_fields_mapper=(file)
people.fields_mapper = file
end
|
Returns parser/serializer for the defined format.
327
328
329
|
# File 'lib/eco/api/session/config.rb', line 327
def person_parser(format: :csv, &block)
people.parser(format: format, &block)
end
|
351
352
353
354
355
356
357
358
359
|
# File 'lib/eco/api/session/config.rb', line 351
def policies
@policies = self["policies"] ||= Eco::API::Policies.new
if block_given?
yield(@policies)
self
else
@policies
end
end
|
260
261
262
263
264
|
# File 'lib/eco/api/session/config.rb', line 260
def policy_groups
return @policy_groups if instance_variable_defined?(:@policy_groups)
pgs = api&.policy_groups.to_a
@policy_groups = Eco::API::Organization::PolicyGroups.new(pgs)
end
|
346
347
348
|
# File 'lib/eco/api/session/config.rb', line 346
def post_launch
self["post_launch"] ||= Eco::API::Session::Config::PostLaunch.new(config: self)
end
|
#reopen {|_self| ... } ⇒ Object
25
26
27
|
# File 'lib/eco/api/session/config.rb', line 25
def reopen
yield(self)
end
|
#requests_backup_folder=(folder) ⇒ Object
Set the base folder name where requests launched to the server will be saved for future reference.
305
306
307
|
# File 'lib/eco/api/session/config.rb', line 305
def requests_backup_folder=(folder)
people.requests_folder = folder
end
|
#require(file = nil, match: nil) ⇒ Object
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
|
# File 'lib/eco/api/session/config.rb', line 188
def require(file = nil, match: nil)
begin
if match
file_manager.dir.dir_files(pattern: match).each do |file|
require_relative File.expand_path(file)
end
else
target = File.expand_path(file_manager.dir.file(file))
require_relative target
end
rescue LoadError => e
if apis.active_api.one_off?
pp e.to_s
else
raise
end
end
end
|
#run_mode=(mode) ⇒ Object
Sets the mode of the active api
125
126
127
|
# File 'lib/eco/api/session/config.rb', line 125
def run_mode=(mode)
apis.active_api.mode = mode
end
|
#run_mode_local? ⇒ Boolean
129
130
131
|
# File 'lib/eco/api/session/config.rb', line 129
def run_mode_local?
apis.active_api.local?
end
|
#run_mode_remote? ⇒ Boolean
133
134
135
|
# File 'lib/eco/api/session/config.rb', line 133
def run_mode_remote?
apis.active_api.remote?
end
|
Helper to upload files and folders to S3.
#schemas ⇒ Object
Returns pEco::API::Organization::PersonSchemas.
267
268
269
270
271
|
# File 'lib/eco/api/session/config.rb', line 267
def schemas
return @schemas if instance_variable_defined?(:@schemas)
schs = api&.person_schemas.to_a
@schemas = Eco::API::Organization::PersonSchemas.new(schs)
end
|
Returns the session linked to this config.
82
83
84
|
# File 'lib/eco/api/session/config.rb', line 82
def session
@session ||= Eco::API::Session.new(self)
end
|
Helper to manage SFTP files and folders.
34
35
36
|
# File 'lib/eco/api/session/config.rb', line 34
def sftp
self["sftp"] ||= Eco::API::Session::Config::SFTP.new(config: self)
end
|
It uses the tagtree.json file and in its absence, if graphql enabled, the life_tagtree
233
234
235
236
237
238
239
240
241
242
|
# File 'lib/eco/api/session/config.rb', line 233
def tagtree(enviro: nil)
return @tagtree if instance_variable_defined?(:@tagtree) && @tagtree.enviro == enviro
if tree_file = org["tagtree"]
tree = []
tree = file_manager.load_json(tree_file) unless !tree_file
@tagtree = Eco::API::Organization::TagTree.new(tree, enviro: enviro)
else
@tagtree = live_tree(enviro: enviro)
end
end
|
#tagtree=(file) ⇒ Object
227
228
229
|
# File 'lib/eco/api/session/config.rb', line 227
def tagtree=(file)
org["tagtree"] = file
end
|
#timestamp_console=(value) ⇒ Object
70
71
72
|
# File 'lib/eco/api/session/config.rb', line 70
def timestamp_console=(value)
logger.timestamp_console = value
end
|
335
336
337
338
339
340
341
342
343
|
# File 'lib/eco/api/session/config.rb', line 335
def usecases
@usecases = self["usecases"] ||= Eco::API::UseCases.new
if block_given?
yield(@usecases)
self
else
@usecases
end
end
|
384
385
386
387
388
389
|
# File 'lib/eco/api/session/config.rb', line 384
def workflow
@workflow = self["workflow"] ||= Eco::API::Session::Config::Workflow.new(config: self)
@workflow.tap do |wf|
yield(wf) if block_given?
end
end
|
#working_directory(mode: nil) ⇒ Object
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
|
# File 'lib/eco/api/session/config.rb', line 162
def working_directory(mode: nil)
return files.working_directory if apis.active_api&.one_off?
unless mode
wd = files.working_directory
return wd unless wd.to_s.strip.empty?
end
mode ||= :active_api
if mode == :active_api
apis.active_root_name
elsif mode == :raw_api_name
apis.active_name
else
files.working_directory
end
end
|
#working_directory=(path) ⇒ Object
Defines in the base folder from where files are expected to be found when relative paths are used
158
159
160
|
# File 'lib/eco/api/session/config.rb', line 158
def working_directory=(path)
files.working_directory = path
end
|