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



376
377
378
379
380
381
382
383
384
# File 'lib/eco/api/session/config.rb', line 376

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.



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

def (name)
  people. = name
end

#default_schema=(name) ⇒ Object

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



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

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.



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

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



412
413
414
415
# File 'lib/eco/api/session/config.rb', line 412

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



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

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.



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

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



387
388
389
390
391
392
393
394
395
# File 'lib/eco/api/session/config.rb', line 387

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



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

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:



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

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



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

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

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

The location node classifications of the organization



243
244
245
# File 'lib/eco/api/session/config.rb', line 243

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

#orgObject



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

def org
  self["org"]
end

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



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

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.



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

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

#person_fields_mapper=(file) ⇒ Object

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



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

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:



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

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

#policiesEco::API::Policies

Returns:



365
366
367
368
369
370
371
372
373
# File 'lib/eco/api/session/config.rb', line 365

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

#policy_groupsEco::API::Organization::PolicyGroups



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

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



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

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.



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

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



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

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:



252
253
254
255
256
257
# File 'lib/eco/api/session/config.rb', line 252

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:



349
350
351
352
353
354
355
356
357
# File 'lib/eco/api/session/config.rb', line 349

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

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



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

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