lib/eco/api/session/config.rb in eco-helpers-1.5.1 vs lib/eco/api/session/config.rb in eco-helpers-1.5.2

- old
+ new

@@ -8,10 +8,12 @@ super(nil) @name = name self["org"] = {} end + # @!group Config instance pure methods + def clone(name) keys.each_with_object(self.class.new(name)) do |key, cnf| begin cnf[key] = self[key].clone(config: cnf) rescue ArgumentError @@ -21,44 +23,40 @@ end def reopen yield(self) end + # @!endgroup - def apis - self["apis"] ||= Eco::API::Session::Config::Apis.new(config: self) - end + # @!group Additional resources + # Helper to manage `SFTP` files and folders. + # @return [Eco::API::Session::Config::SFTP] def sftp self["sftp"] ||= Eco::API::Session::Config::SFTP.new(config: self) end - def logger - self["logger"] ||= Eco::API::Session::Config::Logger.new(config: self) - end - + # Helper to upload files and folders to `S3`. + # @return [Eco::API::Session::Config::S3Storage] def s3storage self["s3_storage"] ||= Eco::API::Session::Config::S3Storage.new(config: self) end - def files - self["files"] ||= Eco::API::Session::Config::Files.new(config: self) - end - + # Helper to send emails. + # @return [Eco::API::Session::Config::Mailer] def mailer self["mailer"] ||= Eco::API::Session::Config::Mailer.new(config: self) end + # @!endgroup - def org - self["org"] - end + # @!group Logger - def people - self["people"] ||= Eco::API::Session::Config::People.new(config: self) + # @return [Eco::API::Session::Config::Logger] + def logger + self["logger"] ||= Eco::API::Session::Config::Logger.new(config: self) end - # LOGGER def log_console_level=(value) logger.console_level= value end def log_file_level=(value) @@ -74,55 +72,90 @@ end def log_connection=(value) logger.log_connection = value end + # @!endgroup - # API - def dry_run! - self["dry-run"] = true - end + # @!group Session and API - def dry_run? - self["dry-run"] + # @return [Eco::API::Session] the `session` linked to this `config` + def session + @session ||= Eco::API::Session.new(self) end - def run_mode=(mode) - apis.active_api.mode = mode + # @return [Eco::API::Session::Config::Apis] + def apis + self["apis"] ||= Eco::API::Session::Config::Apis.new(config: self) end - def run_mode_local? - apis.active_api.local? - end - - def run_mode_remote? - apis.active_api.remote? - end - + # @return [Boolean] `true` if there is any api configuration defined, `false` otherwise def apis? apis.apis? end + # @param (see Eco::API::Session::Config::Apis#add) + # @return [Eco::API::Session::Config] this configuration def add_api(name, **kargs) apis.add(name, **kargs) self end + # Set the active api by `name` + # @see Eco::API::Session::Config::Apis#active_api= + # @return [Eco::API::Session::Config] this configuration def active_api(name) apis.active_name = name self end + # @see Eco::API::Session::Config::Apis#active_root_name def active_enviro apis.active_root_name end + # @see Eco::API::Session::Config::Apis#api def api(logger = ::Logger.new(IO::NULL), version: nil) apis.api(logger, version: version) end - # FILES + # Sets the `mode` of the active api + # @see Eco::API::Session::Config::Api#mode + # @param (see Eco::API::Session::Config::Api#mode) + def run_mode=(mode) + apis.active_api.mode = mode + end + + def run_mode_local? + apis.active_api.local? + end + + def run_mode_remote? + apis.active_api.remote? + end + + # @deprecated old helper to fix the dry-run mode + # @note this is now done via `options[:dry_run]`, parsed as an option + def dry_run! + self["dry-run"] = true + end + + # @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 + def dry_run? + self["dry-run"] + end + # @!endgroup + + # @!group Files + + # @return [Eco::API::Session::Config::Files] + def files + self["files"] ||= Eco::API::Session::Config::Files.new(config: self) + end + + # Defines in the base folder from where files are expected to be found when relative paths are used def working_directory=(path) files.working_directory = path end def working_directory(mode: nil) @@ -156,12 +189,16 @@ end else require_relative "#{File.expand_path(file_manager.dir.file(file))}" end end + # @!endgroup - # ORG + # @!group Organization related shortcuts + def org + self["org"] + end def location_codes=(file) org["location_codes"] = file end @@ -177,131 +214,156 @@ def tagtree=(file) org["tagtree"] = file end + # @return [Eco::API::Organization::TagTree] 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) end end + # @return [Eco::API::Organization::PolicyGroups] 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 + # @return pEco::API::Organization::PersonSchemas def schemas return @schemas if instance_variable_defined?(:@schemas) schs = api&.person_schemas.to_a @schemas = Eco::API::Organization::PersonSchemas.new(schs) end + # @return [Eco::API::Organization::LoginProviders] 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 - def session - @session ||= Eco::API::Session.new(self) + # @!endgroup + + # @!group People shortcuts + + # @return [Eco::API::Session::Config::People] + def people + self["people"] ||= Eco::API::Session::Config::People.new(config: self) end - # PEOPLE + # Define the default usergroup that should be given to people with no usergroups. def default_usergroup=(value) people.default_usergroup = value end + # Specify the file that holds the `csv` with people to be excluded from `API` updates. def discarded_people_file=(value) people.discarded_file = value end + # Set the base folder/name.ext name of the fieles where people will be cached. def people_cache=(file) people.cache = file end + # Set the base folder name where requests launched to the server will be saved for future reference. def requests_backup_folder=(folder) people.requests_folder = folder end - # PERSON FIELDS MAPPER + # Specify the `.json` file name with the mappings [`DataInputColumnName`, `internal-name`]. def person_fields_mapper=(file) people.fields_mapper = file end + # Set the **default schema** this `api` org configuration should work on. def default_schema=(name) people.default_schema = name end - # ACCOUNT PRESETS + # Specify the file with the account custom abilities presets def presets_custom=(file) people.presets_custom = file end + # Specify the file with the usergroup to custom presets mapping def presets_map=(file) people.presets_map = file end - # CUSTOM PERSON PARSERS + # @see Eco::API::Session::Config::People + # @param (see Eco::API::Session::Config::People) + # @return [Eco::API::Common::People::PersonParser] parser/serializer for the defined `format`. def person_parser(format: :csv, &block) people.parser(format: format, &block) end + # @!endgroup + # @!group Session workflow and batch job launces + + # @return [Eco::API::UseCases] def usecases @usecases = self["usecases"] ||= Eco::API::UseCases.new if block_given? yield(@usecases) self else @usecases end end + # @return [Eco::API::Session::Config::PostLaunch] def post_launch self["post_launch"] ||= Eco::API::Session::Config::PostLaunch.new(config: self) end + # @return [Eco::API::Policies] def policies @policies = self["policies"] ||= Eco::API::Policies.new if block_given? yield(@policies) self else @policies end end + # @return [Eco::API::Session::Batch::Policies] 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 + # @return [Eco::API::Error::Handlers] 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 + # @return [Eco::API::Session::Config::Workflow] def workflow @workflow = self["workflow"] ||= Eco::API::Session::Config::Workflow.new(config: self) @workflow.tap do |wf| yield(wf) if block_given? end end - + # @!endgroup end end end end