magpie.cli.register_defaults¶
Magpie helpers for user and group registration.
Attributes¶
Functions¶
|
Defines argument parser options for logging operations. |
|
Uses argument parser options to setup logging level from specified flags. |
|
Search in order for matched value of |
|
Generate a string made of random characters. |
|
Retrieves the 'JSON' body of a response using the property/callable according to the response's implementation. |
|
Immediately sets the logger level to avoid duplicate log outputs from the root logger and this logger when |
|
Logs the requested message to the logger and optionally enforce printing to the console according to configuration |
|
Logs the provided message to the logger and raises the corresponding exception afterwards. |
|
Registers the user if missing and associate him to a group specified by name, also created if missing. |
|
Registers into the database the user and group matching configuration values of. |
|
Registers into the database the user and group matching configuration values of. |
|
Registers into database the group matching |
|
Registers into database every undefined default users and groups matching following variables: |
|
|
|
Module Contents¶
- magpie.cli.register_defaults.make_logging_options(parser: argparse.ArgumentParser) None[source]¶
Defines argument parser options for logging operations.
- magpie.cli.register_defaults.setup_logger_from_options(logger: logging.Logger, args: argparse.Namespace) None[source]¶
Uses argument parser options to setup logging level from specified flags.
Setup both the specific CLI logger that is provided and the generic magpie logger.
- magpie.cli.register_defaults.get_constant(constant_name: magpie.typedefs.Str, settings_container: magpie.typedefs.AnySettingsContainer | None = None, settings_name: magpie.typedefs.Str | None = None, default_value: magpie.typedefs.SettingValue | None = None, raise_not_set: bool = True, raise_missing: bool = True, print_missing: bool = False, empty_missing: bool = False) magpie.typedefs.SettingValue[source]¶
- Search in order for matched value of
constant_name: search in
MAGPIE_CONSTANTSsearch in settings if specified
search alternative setting names (see below)
search in
magpie.constantsdefinitionssearch in environment variables
Parameter
constant_nameis expected to have the formatMAGPIE_[VARIABLE_NAME]although any value can be passed to retrieve generic settings from all above-mentioned search locations.If
settings_nameis provided as alternative name, it is used as is to search for results ifconstant_namewas not found. Otherwise,magpie.[variable_name]is used for additional search when the formatMAGPIE_[VARIABLE_NAME]was used forconstant_name(i.e.:MAGPIE_ADMIN_USERwill also search formagpie.admin_userand so on for corresponding constants).- Parameters:
constant_name – key to search for a value
settings_container – WSGI application settings container (if not provided, uses found one in current thread)
settings_name – alternative name for settings if specified
default_value – default value to be returned if not found anywhere, and exception raises are disabled.
raise_not_set – raise an exception if the found key is
None, search until last case if others areNoneraise_missing – raise exception if key is not found anywhere
print_missing – print message if key is not found anywhere, return
Noneempty_missing – consider an empty value for an existing key as if it was missing (i.e.: as if not set).
- Returns:
found value or default_value
- Raises:
ValueError – if resulting value is invalid based on options (by default raise missing/empty/
Nonevalue)LookupError – if no appropriate value could be found from all search locations (according to options)
- Search in order for matched value of
- magpie.cli.register_defaults.pseudo_random_string(length: int = 8, allow_chars: magpie.typedefs.Str = string.ascii_letters + string.digits) magpie.typedefs.Str[source]¶
Generate a string made of random characters.
- magpie.cli.register_defaults.get_json(request_or_response: magpie.typedefs.AnyRequestType | magpie.typedefs.AnyResponseType) magpie.typedefs.JSON[source]¶
Retrieves the ‘JSON’ body of a response using the property/callable according to the response’s implementation.
- magpie.cli.register_defaults.get_logger(name: magpie.typedefs.Str, level: int | None = None, force_stdout: bool = None, message_format: magpie.typedefs.Str | None = None, datetime_format: magpie.typedefs.Str | None = None) logging.Logger[source]¶
Immediately sets the logger level to avoid duplicate log outputs from the root logger and this logger when level is
logging.NOTSET.
- magpie.cli.register_defaults.print_log(msg: magpie.typedefs.Str, logger: logging.Logger | None = None, level: int = logging.INFO, **kwargs: Any) None[source]¶
Logs the requested message to the logger and optionally enforce printing to the console according to configuration value defined by
MAGPIE_LOG_PRINT.
- magpie.cli.register_defaults.raise_log(msg: magpie.typedefs.Str, exception: Type[Exception] = Exception, logger: logging.Logger | None = None, level: int = logging.ERROR) NoReturn[source]¶
Logs the provided message to the logger and raises the corresponding exception afterwards.
- Raises:
exception – whichever exception provided is raised systematically after logging.
- magpie.cli.register_defaults.register_user_with_group(user_name: magpie.typedefs.Str, group_name: magpie.typedefs.Str, email: magpie.typedefs.Str, password: magpie.typedefs.Str | None, db_session: sqlalchemy.orm.session.Session) None[source]¶
Registers the user if missing and associate him to a group specified by name, also created if missing.
- Parameters:
user_name – name of the user to create (if missing) and to make part of the group (if specified)
group_name – name of the group to create (if missing and specified) and to make the user join (if not already)
email – email of the user to be created (if missing)
password – password of the user to be created (if missing), auto-generate if not provided (None).
db_session – database connexion to apply changes
Warning
Should be employed only for special users/groups in this module as other expected API behaviour and operations will not be applied (ex: create additional permissions or user-group references).
- magpie.cli.register_defaults.init_anonymous(db_session: sqlalchemy.orm.session.Session, settings: magpie.typedefs.AnySettingsContainer | None = None) None[source]¶
Registers into the database the user and group matching configuration values of.
magpie.constants.MAGPIE_ANONYMOUS_USERandmagpie.constants.MAGPIE_ANONYMOUS_GROUPrespectively if not defined.Afterwards, updates the group’s parameters to ensure integrity with Magpie settings.
- magpie.cli.register_defaults.init_admin(db_session: sqlalchemy.orm.session.Session, settings: magpie.typedefs.AnySettingsContainer | None = None) None[source]¶
Registers into the database the user and group matching configuration values of.
magpie.constants.MAGPIE_ADMIN_USERandmagpie.constants.MAGPIE_ADMIN_GROUPrespectively if not defined.Also associates the created admin user with the admin group and give it admin permissions. Finally, updates the group’s parameters to ensure integrity with Magpie settings.
- magpie.cli.register_defaults.init_users_group(db_session: sqlalchemy.orm.session.Session, settings: magpie.typedefs.AnySettingsContainer | None = None) None[source]¶
Registers into database the group matching
magpie.constants.MAGPIE_USERS_GROUPif not defined.
- magpie.cli.register_defaults.register_defaults(db_session: sqlalchemy.orm.session.Session | None = None, settings: magpie.typedefs.AnySettingsContainer | None = None, ini_file_path: magpie.typedefs.Str | None = None) None[source]¶
Registers into database every undefined default users and groups matching following variables: