Class: Eco::API::Session::Config

Inherits:
Hash 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/tagtree.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, TagTree, Workflow

Instance Attribute Summary collapse

Config instance pure methods collapse

Additional resources collapse

Logger collapse

Session and API collapse

Files 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

#nameObject (readonly)

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

#active_api(name) ⇒ Eco::API::Session::Config

Set the active api by name

Returns:

See Also:

  • Eco::API::Session::Config::Apis#active_api=


112
113
114
115
# File 'lib/eco/api/session/config.rb', line 112

def active_api(name)
  apis.active_name = name
  self
end

#active_enviroObject



118
119
120
# File 'lib/eco/api/session/config.rb', line 118

def active_enviro
  apis.active_root_name
end

#add_api(name, **kargs) ⇒ Eco::API::Session::Config

Returns this configuration.

Returns:



104
105
106
107
# File 'lib/eco/api/session/config.rb', line 104

def add_api(name, **kargs)
  apis.add(name, **kargs)
  self
end

#api(logger = ::Logger.new(IO::NULL), version: nil) ⇒ Eco::API::Session::Config::Api

Returns the currently active api.

Returns:

See Also:



124
125
126
# File 'lib/eco/api/session/config.rb', line 124

def api(logger = ::Logger.new(IO::NULL), version: nil)
  apis.api(logger, version: version)
end

#apisEco::API::Session::Config::Apis



93
94
95
# File 'lib/eco/api/session/config.rb', line 93

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.

Returns:

  • (Boolean)

    true if there is any api configuration defined, false otherwise



98
99
100
# File 'lib/eco/api/session/config.rb', line 98

def apis?
  apis.apis?
end

#batch_policies(&block) ⇒ Eco::API::Session::Batch::Policies



370
371
372
373
374
375
376
377
378
# File 'lib/eco/api/session/config.rb', line 370

def batch_policies(&block)
  @batch_policies = self["batch_policies"] ||= Eco::API::Session::Batch::Policies.new("batch_policy")
  if block_given?
    @batch_policies.evaluate(@batch_policies, &block)
    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.



328
329
330
# File 'lib/eco/api/session/config.rb', line 328

def (name)
  people. = name
end

#default_schema=(name) ⇒ Object

Set the default schema this api org configuration should work on.



323
324
325
# File 'lib/eco/api/session/config.rb', line 323

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.



298
299
300
# File 'lib/eco/api/session/config.rb', line 298

def default_usergroup=(value)
  people.default_usergroup = value
end

#delay_between_job_groups(seconds = nil) ⇒ nil, Interger

Returns seconds between job groups.

Returns:

  • (nil, Interger)

    seconds between job groups



406
407
408
409
# File 'lib/eco/api/session/config.rb', line 406

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.

Returns:

  • (nil, Interger)

    seconds between jobs



400
401
402
403
# File 'lib/eco/api/session/config.rb', line 400

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.



303
304
305
# File 'lib/eco/api/session/config.rb', line 303

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



145
146
147
# File 'lib/eco/api/session/config.rb', line 145

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

Returns:

  • (Boolean)


151
152
153
# File 'lib/eco/api/session/config.rb', line 151

def dry_run?
  self["dry-run"]
end

#error_handlersEco::API::Error::Handlers



381
382
383
384
385
386
387
388
389
# File 'lib/eco/api/session/config.rb', line 381

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_managerObject



190
191
192
# File 'lib/eco/api/session/config.rb', line 190

def file_manager
  Eco::API::Common::Session::FileManager.new(self)
end

#file_timestamp_pattern=(pattern) ⇒ Object



186
187
188
# File 'lib/eco/api/session/config.rb', line 186

def file_timestamp_pattern=(pattern)
  files.timestamp_pattern = pattern
end

#filesEco::API::Session::Config::Files



159
160
161
# File 'lib/eco/api/session/config.rb', line 159

def files
  self["files"]      ||= Eco::API::Session::Config::Files.new(config: self)
end

#live_tree(id: nil, enviro: nil, **kargs, &block) ⇒ Eco::API::Organization::TagTree

Note:

it requires graphql connection configuration parameters

It obtains the first of the live tagtree in the org



256
257
258
# File 'lib/eco/api/session/config.rb', line 256

def live_tree(id: nil, enviro: nil, **kargs, &block)
  tagtree_config.live_tree(id: id, enviro: enviro, **kargs, &block)
end

#live_trees(**kargs, &block) ⇒ Array<Eco::API::Organization::TagTree>

Retrieves all the location structures of the organisation

Parameters:

  • include_archived (Boolean)

    whether or not to include archived nodes

Returns:



263
264
265
# File 'lib/eco/api/session/config.rb', line 263

def live_trees(**kargs, &block)
  tagtree_config.live_trees(**kargs, &block)
end

#location_codesObject



223
224
225
# File 'lib/eco/api/session/config.rb', line 223

def location_codes
  org["location_codes"]
end

#location_codes=(file) ⇒ Object



219
220
221
# File 'lib/eco/api/session/config.rb', line 219

def location_codes=(file)
  org["location_codes"] = file
end

#locations_mapperObject



227
228
229
230
231
# File 'lib/eco/api/session/config.rb', line 227

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



80
81
82
# File 'lib/eco/api/session/config.rb', line 80

def log_connection=(value)
  logger.log_connection = value
end

#log_console_level=(value) ⇒ Object



64
65
66
# File 'lib/eco/api/session/config.rb', line 64

def log_console_level=(value)
  logger.console_level= value
end

#log_file=(file) ⇒ Object



72
73
74
# File 'lib/eco/api/session/config.rb', line 72

def log_file=(file)
  logger.file = file
end

#log_file_level=(value) ⇒ Object



68
69
70
# File 'lib/eco/api/session/config.rb', line 68

def log_file_level=(value)
  logger.file_level = value
end

#loggerEco::API::Session::Config::Logger



60
61
62
# File 'lib/eco/api/session/config.rb', line 60

def logger
  self["logger"]     ||= Eco::API::Session::Config::Logger.new(config: self)
end

#login_providersEco::API::Organization::LoginProviders



282
283
284
285
286
# File 'lib/eco/api/session/config.rb', line 282

def 
  return @login_providers if instance_variable_defined?(:@login_providers)
  provs            = api&..to_a
  @login_providers = Eco::API::Organization::LoginProviders.new(provs)
end

#mailerEco::API::Session::Config::Mailer

Helper to send emails.



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

#orgObject



215
216
217
# File 'lib/eco/api/session/config.rb', line 215

def org
  self["org"]
end

#peopleEco::API::Session::Config::People



293
294
295
# File 'lib/eco/api/session/config.rb', line 293

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.



308
309
310
# File 'lib/eco/api/session/config.rb', line 308

def people_cache=(file)
  people.cache = file
end

#person_fields_mapper=(file) ⇒ Object

Specify the .json file name with the mappings [DataInputColumnName, internal-name].



318
319
320
# File 'lib/eco/api/session/config.rb', line 318

def person_fields_mapper=(file)
  people.fields_mapper = file
end

#person_parser(format: :csv, &block) ⇒ Eco::API::Common::People::PersonParser

Returns parser/serializer for the defined format.

Returns:

See Also:



335
336
337
# File 'lib/eco/api/session/config.rb', line 335

def person_parser(format: :csv, &block)
  people.parser(format: format, &block)
end

#policiesEco::API::Policies

Returns:



359
360
361
362
363
364
365
366
367
# File 'lib/eco/api/session/config.rb', line 359

def policies
  @policies = self["policies"] ||= Eco::API::Policies.new
  if block_given?
    yield(@policies)
    self
  else
    @policies
  end
end

#policy_groupsEco::API::Organization::PolicyGroups



268
269
270
271
272
# File 'lib/eco/api/session/config.rb', line 268

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

#post_launchEco::API::Session::Config::PostLaunch



354
355
356
# File 'lib/eco/api/session/config.rb', line 354

def post_launch
  self["post_launch"] ||= Eco::API::Session::Config::PostLaunch.new(config: self)
end

#reopen {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



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.



313
314
315
# File 'lib/eco/api/session/config.rb', line 313

def requests_backup_folder=(folder)
  people.requests_folder = folder
end

#require(file = nil, match: nil) ⇒ Object



194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
# File 'lib/eco/api/session/config.rb', line 194

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



131
132
133
# File 'lib/eco/api/session/config.rb', line 131

def run_mode=(mode)
  apis.active_api.mode = mode
end

#run_mode_local?Boolean

Returns:

  • (Boolean)


135
136
137
# File 'lib/eco/api/session/config.rb', line 135

def run_mode_local?
  apis.active_api.local?
end

#run_mode_remote?Boolean

Returns:

  • (Boolean)


139
140
141
# File 'lib/eco/api/session/config.rb', line 139

def run_mode_remote?
  apis.active_api.remote?
end

#s3storageEco::API::Session::Config::S3Storage

Helper to upload files and folders to S3.



40
41
42
# File 'lib/eco/api/session/config.rb', line 40

def s3storage
  self["s3_storage"] ||= Eco::API::Session::Config::S3Storage.new(config: self)
end

#schemasObject

Returns pEco::API::Organization::PersonSchemas.

Returns:

  • pEco::API::Organization::PersonSchemas



275
276
277
278
279
# File 'lib/eco/api/session/config.rb', line 275

def schemas
  return @schemas if instance_variable_defined?(:@schemas)
  schs     = api&.person_schemas.to_a
  @schemas = Eco::API::Organization::PersonSchemas.new(schs)
end

#sessionEco::API::Session

Returns the session linked to this config.

Returns:



88
89
90
# File 'lib/eco/api/session/config.rb', line 88

def session
  @session     ||= Eco::API::Session.new(self)
end

#sftpEco::API::Session::Config::SFTP

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

#tagtree(enviro: nil, include_archived: false, raise_on_missing: true) ⇒ Eco::API::Organization::TagTree

Note:

it does NOT include archived nodes by default.

  • This is for legacy (most usecases don't)

It uses the tagtree.json file and in its absence, if graphql enabled, the largest life_tagtree

Parameters:

  • include_archived (Boolean) (defaults to: false)

    whether or not it should include archived nodes.

Returns:



246
247
248
249
250
251
# File 'lib/eco/api/session/config.rb', line 246

def tagtree(enviro: nil, include_archived: false, raise_on_missing: true)
  kargs = {
    enviro: enviro, include_archived: include_archived, raise_on_missing: raise_on_missing
  }
  @tagtree ||= tagtree_config.scope_tree(**kargs)
end

#tagtree=(file) ⇒ Object



233
234
235
# File 'lib/eco/api/session/config.rb', line 233

def tagtree=(file)
  tagtree_config.file = file
end

#tagtree_configEco::API::Session::Config::TagTree

Helper scope reporting structures.



52
53
54
# File 'lib/eco/api/session/config.rb', line 52

def tagtree_config
  org["tagtree_config"] ||= Eco::API::Session::Config::TagTree.new(config: self)
end

#tagtree_id=(value) ⇒ Object



237
238
239
# File 'lib/eco/api/session/config.rb', line 237

def tagtree_id=(value)
  tagtree_config.structure_id = value
end

#timestamp_console=(value) ⇒ Object



76
77
78
# File 'lib/eco/api/session/config.rb', line 76

def timestamp_console=(value)
  logger.timestamp_console = value
end

#usecasesEco::API::UseCases

Returns:



343
344
345
346
347
348
349
350
351
# File 'lib/eco/api/session/config.rb', line 343

def usecases
  @usecases = self["usecases"] ||= Eco::API::UseCases.new
  if block_given?
    yield(@usecases)
    self
  else
    @usecases
  end
end

#workflowEco::API::Session::Config::Workflow



392
393
394
395
396
397
# File 'lib/eco/api/session/config.rb', line 392

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



168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# File 'lib/eco/api/session/config.rb', line 168

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



164
165
166
# File 'lib/eco/api/session/config.rb', line 164

def working_directory=(path)
  files.working_directory = path
end