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=


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

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

#active_enviroObject



129
130
131
# File 'lib/eco/api/session/config.rb', line 129

def active_enviro
  apis.active_root_name
end

#active_enviro_spaceObject

See Also:

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


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

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
# 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})
end

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

Returns the currently active api.

Returns:

See Also:



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

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



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

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.



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

def (name)
  people. = name
end

#default_schema=(name) ⇒ Object

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



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

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.



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

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



432
433
434
435
# File 'lib/eco/api/session/config.rb', line 432

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



426
427
428
429
# File 'lib/eco/api/session/config.rb', line 426

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.



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

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



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

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)


167
168
169
# File 'lib/eco/api/session/config.rb', line 167

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

#error_handlersEco::API::Error::Handlers



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

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



206
207
208
# File 'lib/eco/api/session/config.rb', line 206

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

#file_timestamp_pattern=(pattern) ⇒ Object



202
203
204
# File 'lib/eco/api/session/config.rb', line 202

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

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



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

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



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

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:



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

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

#location_codesObject



235
236
237
# File 'lib/eco/api/session/config.rb', line 235

def location_codes
  org["location_codes"]
end

#location_codes=(file) ⇒ Object



231
232
233
# File 'lib/eco/api/session/config.rb', line 231

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

#locations_mapperObject



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

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



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



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

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



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

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

#orgObject



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

def org
  self["org"]
end

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



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

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.



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

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

#person_fields_mapper=(file) ⇒ Object

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



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

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:



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

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

#policiesEco::API::Policies

Returns:



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

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

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

#policy_groupsEco::API::Organization::PolicyGroups



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

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



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

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.



338
339
340
# File 'lib/eco/api/session/config.rb', line 338

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

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



210
211
212
213
214
215
216
217
218
219
220
221
222
223
# File 'lib/eco/api/session/config.rb', line 210

def require(file = nil, match: nil)
  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 => err
  raise unless apis.active_api.one_off?

  pp err.to_s
end

#run_mode=(mode) ⇒ Object

Sets the mode of the active api



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

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

#run_mode_local?Boolean

Returns:

  • (Boolean)


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

def run_mode_local?
  apis.active_api.local?
end

#run_mode_remote?Boolean

Returns:

  • (Boolean)


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

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



300
301
302
303
304
# File 'lib/eco/api/session/config.rb', line 300

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:



265
266
267
268
269
270
271
272
273
274
275
276
# File 'lib/eco/api/session/config.rb', line 265

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



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

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



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

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:



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

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

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



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

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



184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
# File 'lib/eco/api/session/config.rb', line 184

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



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

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