magpie.register¶
Module Contents¶
-
exception
magpie.register.RegistrationError[source]¶ Bases:
RuntimeErrorGeneric error during registration operation.
-
exception
magpie.register.RegistrationValueError[source]¶ Bases:
magpie.register.RegistrationError,ValueErrorRegistration error caused by an invalid value precondition.
-
exception
magpie.register.RegistrationLoginError[source]¶ Bases:
magpie.register.RegistrationErrorRegistration error caused by a failure to complete required login operation.
-
exception
magpie.register.RegistrationConfigurationError[source]¶ Bases:
magpie.register.RegistrationValueErrorRegistration error caused by an invalid configuration entry or definition.
-
magpie.register._request_curl(url, cookie_jar=None, cookies=None, form_params=None, msg='Response') → Tuple[int, int][source]¶ Executes a request using cURL.
Returns: tuple of the returned system command code and the response http code
-
magpie.register.phoenix_login_check(cookies)[source]¶ Since Phoenix always return 200, even on invalid login, ‘hack’ check unauthorized access.
Parameters: cookies – temporary cookies file storage used for login with phoenix_login. Returns: status indicating if login access was granted with defined credentials.
-
magpie.register.phoenix_remove_services() → bool[source]¶ Removes the Phoenix services using temporary cookies retrieved from login with defined PHOENIX constants.
Returns: success status of the procedure.
-
magpie.register._register_services(where, services_dict, cookies, message='Register response') → Tuple[bool, Dict[Str, int]][source]¶ Registers services on desired location using provided configurations and access cookies.
Returns: tuple of overall success and individual http response of each service registration.
-
magpie.register.sync_services_phoenix(services_object_dict, services_as_dicts=False)[source]¶ Syncs Magpie services by pushing updates to Phoenix. Services must be one of types specified in SERVICES_PHOENIX_ALLOWED.
Parameters: - services_object_dict – dictionary of {svc-name: models.Service} objects containing each service’s information
- services_as_dicts – alternatively specify services_object_dict as dict of {svc-name: {service-info}}
where {service-info} = {‘public_url’: <url>, ‘service_name’: <name>, ‘service_type’: <type>}
-
magpie.register.magpie_add_register_services_perms(services, statuses, curl_cookies, request_cookies, disable_getcapabilities)[source]¶
-
magpie.register.magpie_update_services_conflict(conflict_services, services_dict, request_cookies) → Dict[Str, int][source]¶ Resolve conflicting services by name during registration by updating them only if pointing to different URL.
-
magpie.register.magpie_register_services_with_requests(services_dict, push_to_phoenix, username, password, provider, force_update=False, disable_getcapabilities=False) → bool[source]¶ Registers magpie services using the provided services configuration.
Parameters: - services_dict – services configuration definition.
- push_to_phoenix – push registered Magpie services to Phoenix for synced configurations.
- username – login username to use to obtain permissions for services registration.
- password – login password to use to obtain permissions for services registration.
- provider – login provider to use to obtain permissions for services registration.
- force_update – override existing services matched by name
- disable_getcapabilities – do not execute ‘GetCapabilities’ validation for applicable services.
Returns: successful operation status
-
magpie.register.magpie_register_services_with_db_session(services_dict, db_session, push_to_phoenix=False, force_update=False, update_getcapabilities_permissions=False)[source]¶
-
magpie.register._load_config(path_or_dict, section) → ConfigDict[source]¶ Loads a file path or dictionary as YAML/JSON configuration.
-
magpie.register._get_all_configs(path_or_dict, section) → List[ConfigDict][source]¶ Loads all configuration files specified by the path (if a directory), a single configuration (if a file) or directly returns the specified dictionary section (if a configuration dictionary).
Returns: list of configurations loaded if input was a directory path list of single configuration if input was a file path list of single configuration if input was a JSON dict empty list if none of the other cases where matched Note
Order of file loading will be resolved by alphabetically sorted filename if specifying a directory path.
-
magpie.register._expand_all(config) → ConfigDict[source]¶ Applies environment variable expansion recursively to all applicable fields of a configuration definition.
-
magpie.register.magpie_register_services_from_config(service_config_path, push_to_phoenix=False, force_update=False, disable_getcapabilities=False, db_session=None) → None[source]¶ Registers Magpie services from one or many providers.cfg file.
Uses the provided DB session to directly update service definitions, or uses API request routes as admin. Optionally pushes updates to Phoenix.
-
magpie.register._log_permission(message, permission_index, trail=', skipping...', detail=None, permission=None, level=logging.WARN) → None[source]¶ Logs a message related to a ‘permission’ entry.
Log message format is as follows:
{message} [permission: #{permission_index}] [{permission}]{trail} Detail: [{detail}]
Such that the following logging entry is generated (omitting any additional logging formatters):
>> log_permission("test", 1, " skip test...", "just a test", "fake") test [permission: #1] [fake] skip test... Detail: [just a test]
Parameters: - message – base message to log
- permission_index – index of the permission in the configuration list for traceability
- trail – trailing message appended after the base message
- detail – additional details appended after the trailing message after moving to another line.
- permission – permission name to log just before the trailing message.
- level – logging level (default:
logging.WARN)
See also
magpie/config/permissions.cfg
-
magpie.register._parse_resource_path(permission_config_entry, entry_index, service_info, cookies_or_session=None, magpie_url=None) → Tuple[Optional[int], bool][source]¶ Parses the resource field of a permission config entry and retrieves the final resource id. Creates missing resources as necessary if they can be automatically resolved.
If cookies are provided, uses requests to a running Magpie instance (with
magpie_url) to apply permission. If session to db is provided, uses direct db connection instead to apply permission.Returns: tuple of found id (if any, Noneotherwise), and success status of the parsing operation (error)
-
magpie.register._apply_permission_entry(permission_config_entry, entry_index, resource_id, cookies_or_session, magpie_url) → None[source]¶ Applies the single permission entry retrieved from the permission configuration.
Assumes that permissions fields where pre-validated. Permission is applied for the user/group/resource using request or db session accordingly to arguments.
-
magpie.register.magpie_register_permissions_from_config(permissions_config, magpie_url=None, db_session=None) → None[source]¶ Applies permissions specified in configuration(s) defined as file, directory with files or literal configuration.
Parameters: - permissions_config – file/dir path to permissions config or JSON/YAML equivalent pre-loaded.
- magpie_url – URL to magpie instance (when using requests; default: magpie.url from this app’s config).
- db_session – db session to use instead of requests to directly create/remove permissions with config.
See also
magpie/config/permissions.cfg for specific parameters and operational details.