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,
lib/eco/api/session/config/apis/one_off.rb,
lib/eco/api/session/config/apis/service_up.rb,
lib/eco/api/session/config/apis/enviro_spaces.rb,
lib/eco/api/session/config/apis/space_helpers.rb

Defined Under Namespace

Classes: Api, ApiDefChain, 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, space: nil) ⇒ Eco::API::Session::Config

Set the active api by name

Returns:

See Also:

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


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

def active_api(name, space: nil)
  apis.set_active_name(name, space: space)
  self
end

#active_enviroObject



143
144
145
# File 'lib/eco/api/session/config.rb', line 143

def active_enviro
  apis.active_root_name
end

#active_enviro_spaceObject

See Also:

  • Eco::API::Session::Config::Apis#active_space


148
149
150
# File 'lib/eco/api/session/config.rb', line 148

def active_enviro_space
  apis.active_space
end

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

Returns this configuration.

Returns:



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/eco/api/session/config.rb', line 109

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

  if block_given?
    params = kargs.merge({space: :sub_other})
    yield(ApiDefChain.new(self, name, params))
  end

  ApiDefChain.new(self, name, {space: :other}).tap do
    next unless kargs[:host].to_s.downcase == 'live.ecoportal.com'
    next unless kargs[:space].nil? || kargs[:space].to_sym == :default

    %w[
      beta.dev.ecoportal.com
      staging.dev.ecoportal.com
      pre.dev.ecoportal.com
    ].each do |env|
      spa = env.split('.', 2).first.to_sym
      next if apis.defined?(name, space: spa)

      apis.add(name, **kargs, host: env, space: spa)
    end
  end
end

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

Returns the currently active api.

Returns:

See Also:



154
155
156
# File 'lib/eco/api/session/config.rb', line 154

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

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



91
92
93
# File 'lib/eco/api/session/config.rb', line 91

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



96
97
98
# File 'lib/eco/api/session/config.rb', line 96

def apis?
  apis.apis?
end

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



437
438
439
440
441
442
443
444
445
446
# File 'lib/eco/api/session/config.rb', line 437

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
# File 'lib/eco/api/session/config.rb', line 15

def clone(name)
  keys.each_with_object(self.class.new(name)) do |key, cnf|
    cnf[key] = self[key].clone(config: cnf)
  rescue ArgumentError
    cnf[key] = self[key].clone
  end
end

#default_login_method=(name) ⇒ Object

Set the default login method that users should acquire.



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

def (name)
  people. = name
end

#default_schema=(name) ⇒ Object

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



389
390
391
# File 'lib/eco/api/session/config.rb', line 389

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.



364
365
366
# File 'lib/eco/api/session/config.rb', line 364

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



475
476
477
478
# File 'lib/eco/api/session/config.rb', line 475

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



469
470
471
472
# File 'lib/eco/api/session/config.rb', line 469

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.



369
370
371
# File 'lib/eco/api/session/config.rb', line 369

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



175
176
177
# File 'lib/eco/api/session/config.rb', line 175

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)


181
182
183
# File 'lib/eco/api/session/config.rb', line 181

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

#error_handlersEco::API::Error::Handlers



449
450
451
452
453
454
455
456
457
# File 'lib/eco/api/session/config.rb', line 449

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



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

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

#file_timestamp_pattern=(pattern) ⇒ Object



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

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

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



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

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

#live_tree(id: 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



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

def live_tree(id: nil, **kargs, &block)
  tagtree_config.live_tree(id: id, **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:



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

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

#location_codesObject Also known as: locations_map_file



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

def location_codes
  org['location_codes']
end

#location_codes=(file) ⇒ Object



245
246
247
# File 'lib/eco/api/session/config.rb', line 245

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

#locations_mapper(**kargs) ⇒ Eco::Data::Mapper, NilClass

Parameters:

  • internal (Symbol)

    either :first (default) or :last

  • insensitive (Boolean)

    default false. Whether lookups are case sensitive.

  • maps_file (String)

    the location maps file (default: locations_map_file).

    • Via file_manager it will try to spot the most recently changed.
    • The lookup to spot the path of the file, tries first as a relative path from env/config/.... If it fails, it tries it as an absolute path.

Returns:



262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
# File 'lib/eco/api/session/config.rb', line 262

def locations_mapper(**kargs)
  kargs = {
    internal:    :first,
    insensitive: false,
    maps_file:   nil
  }.merge(kargs)

  kargs[:maps_file] ||= locations_map_file
  kargs[:maps_file]   = file_manager.newest(kargs[:maps_file])

  return unless kargs[:maps_file]

  @locations_mapper ||= {}

  return @locations_mapper[kargs] if @locations_mapper.key?(kargs)

  @locations_mapper[kargs] = Eco::Data::Mapper.new(
    file_manager.load_json(kargs[:maps_file]),
    internal:    kargs[:internal],
    insensitive: kargs[:insensitive]
  )
end

#log_connection=(value) ⇒ Object



78
79
80
# File 'lib/eco/api/session/config.rb', line 78

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

#log_console_level=(value) ⇒ Object



62
63
64
# File 'lib/eco/api/session/config.rb', line 62

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

#log_file=(file) ⇒ Object



70
71
72
# File 'lib/eco/api/session/config.rb', line 70

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

#log_file_level=(value) ⇒ Object



66
67
68
# File 'lib/eco/api/session/config.rb', line 66

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

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



58
59
60
# File 'lib/eco/api/session/config.rb', line 58

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

#login_providersEco::API::Organization::LoginProviders



348
349
350
351
352
# File 'lib/eco/api/session/config.rb', line 348

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.



44
45
46
# File 'lib/eco/api/session/config.rb', line 44

def mailer
  self['mailer'] ||= Eco::API::Session::Config::Mailer.new(config: self)
end

#node_classifications(active: true) ⇒ Eco::API::Organization::NodeClassifications

The location node classifications of the organization



296
297
298
# File 'lib/eco/api/session/config.rb', line 296

def node_classifications(active: true)
  tagtree_config.node_classifications(active: active)
end

#orgObject



241
242
243
# File 'lib/eco/api/session/config.rb', line 241

def org
  self['org']
end

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



359
360
361
# File 'lib/eco/api/session/config.rb', line 359

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.



374
375
376
# File 'lib/eco/api/session/config.rb', line 374

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

#person_fields_mapper=(file) ⇒ Object

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



384
385
386
# File 'lib/eco/api/session/config.rb', line 384

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:



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

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

#policiesEco::API::Policies

Returns:



425
426
427
428
429
430
431
432
433
434
# File 'lib/eco/api/session/config.rb', line 425

def policies
  @policies = self['policies'] ||= Eco::API::Policies.new

  if block_given?
    yield(@policies)
    self
  else
    @policies
  end
end

#policy_groupsEco::API::Organization::PolicyGroups



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

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



420
421
422
# File 'lib/eco/api/session/config.rb', line 420

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

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

Yields:

  • (_self)

Yield Parameters:



23
24
25
# File 'lib/eco/api/session/config.rb', line 23

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.



379
380
381
# File 'lib/eco/api/session/config.rb', line 379

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

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



224
225
226
227
228
229
230
231
232
233
234
235
236
237
# File 'lib/eco/api/session/config.rb', line 224

def require(file = nil, match: nil)
  if match
    file_manager.dir.dir_files(pattern: match).each do |filename|
      require_relative File.expand_path(filename)
    end
  else
    target = File.expand_path(file_manager.dir.file(file))
    require_relative target
  end
rescue LoadError => err
  raise unless apis.active_api.one_off?

  pp err.to_s
end

#run_mode=(mode) ⇒ Object

Sets the mode of the active api



161
162
163
# File 'lib/eco/api/session/config.rb', line 161

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

#run_mode_local?Boolean

Returns:

  • (Boolean)


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

def run_mode_local?
  apis.active_api.local?
end

#run_mode_remote?Boolean

Returns:

  • (Boolean)


169
170
171
# File 'lib/eco/api/session/config.rb', line 169

def run_mode_remote?
  apis.active_api.remote?
end

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

Helper to upload files and folders to S3.



38
39
40
# File 'lib/eco/api/session/config.rb', line 38

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



341
342
343
344
345
# File 'lib/eco/api/session/config.rb', line 341

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:



86
87
88
# File 'lib/eco/api/session/config.rb', line 86

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

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

Helper to manage SFTP files and folders.



32
33
34
# File 'lib/eco/api/session/config.rb', line 32

def sftp
  self['sftp'] ||= Eco::API::Session::Config::SFTP.new(config: self)
end

#tagtree(include_archived: false, recache: 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.

  • used (recache)

    for re-caching

Returns:



306
307
308
309
310
311
312
313
314
315
316
317
# File 'lib/eco/api/session/config.rb', line 306

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

#tagtree=(file) ⇒ Object



285
286
287
# File 'lib/eco/api/session/config.rb', line 285

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

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

Helper scope reporting structures.



50
51
52
# File 'lib/eco/api/session/config.rb', line 50

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

#tagtree_id=(value) ⇒ Object Also known as: structure_id=



289
290
291
# File 'lib/eco/api/session/config.rb', line 289

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

#timestamp_console=(value) ⇒ Object



74
75
76
# File 'lib/eco/api/session/config.rb', line 74

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

#usecasesEco::API::UseCases

Returns:



409
410
411
412
413
414
415
416
417
# File 'lib/eco/api/session/config.rb', line 409

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

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



460
461
462
463
464
465
466
# File 'lib/eco/api/session/config.rb', line 460

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



198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
# File 'lib/eco/api/session/config.rb', line 198

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



194
195
196
# File 'lib/eco/api/session/config.rb', line 194

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