magpie.cli.batch_update_users ============================= .. py:module:: magpie.cli.batch_update_users .. autoapi-nested-parse:: Magpie helper to create or delete a list of users using a set of input parameters. Useful for batch operations. Attributes ---------- .. autoapisummary:: magpie.cli.batch_update_users.UserConfig magpie.cli.batch_update_users.LOGGER magpie.cli.batch_update_users.ERROR_PARAMS magpie.cli.batch_update_users.ERROR_EXEC Functions --------- .. autoapisummary:: magpie.cli.batch_update_users.make_logging_options magpie.cli.batch_update_users.setup_logger_from_options magpie.cli.batch_update_users.get_constant magpie.cli.batch_update_users.get_all_configs magpie.cli.batch_update_users.pseudo_random_string magpie.cli.batch_update_users.get_json magpie.cli.batch_update_users.get_logger magpie.cli.batch_update_users.format_response magpie.cli.batch_update_users.get_login_session magpie.cli.batch_update_users.create_users magpie.cli.batch_update_users.delete_users magpie.cli.batch_update_users.make_output magpie.cli.batch_update_users.make_parser magpie.cli.batch_update_users.main Module Contents --------------- .. py:function:: make_logging_options(parser: argparse.ArgumentParser) -> None Defines argument parser options for logging operations. .. py:function:: setup_logger_from_options(logger: logging.Logger, args: argparse.Namespace) -> None 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. .. py:function:: get_constant(constant_name: magpie.typedefs.Str, settings_container: Optional[magpie.typedefs.AnySettingsContainer] = None, settings_name: Optional[magpie.typedefs.Str] = None, default_value: Optional[magpie.typedefs.SettingValue] = None, raise_not_set: bool = True, raise_missing: bool = True, print_missing: bool = False, empty_missing: bool = False) -> magpie.typedefs.SettingValue Search in order for matched value of :paramref:`constant_name`: 1. search in :py:data:`MAGPIE_CONSTANTS` 2. search in settings if specified 3. search alternative setting names (see below) 4. search in :mod:`magpie.constants` definitions 5. search in environment variables Parameter :paramref:`constant_name` is expected to have the format ``MAGPIE_[VARIABLE_NAME]`` although any value can be passed to retrieve generic settings from all above-mentioned search locations. If :paramref:`settings_name` is provided as alternative name, it is used as is to search for results if :paramref:`constant_name` was not found. Otherwise, ``magpie.[variable_name]`` is used for additional search when the format ``MAGPIE_[VARIABLE_NAME]`` was used for :paramref:`constant_name` (i.e.: ``MAGPIE_ADMIN_USER`` will also search for ``magpie.admin_user`` and so on for corresponding constants). :param constant_name: key to search for a value :param settings_container: WSGI application settings container (if not provided, uses found one in current thread) :param settings_name: alternative name for `settings` if specified :param default_value: default value to be returned if not found anywhere, and exception raises are disabled. :param raise_not_set: raise an exception if the found key is ``None``, search until last case if others are ``None`` :param raise_missing: raise exception if key is not found anywhere :param print_missing: print message if key is not found anywhere, return ``None`` :param empty_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/``None`` value) :raises LookupError: if no appropriate value could be found from all search locations (according to options) .. py:function:: get_all_configs(path_or_dict: Union[magpie.typedefs.Str, magpie.typedefs.CombinedConfig], section: magpie.typedefs.Literal[groups], allow_missing: bool = False) -> magpie.typedefs.GroupsConfig get_all_configs(path_or_dict: Union[magpie.typedefs.Str, magpie.typedefs.CombinedConfig], section: magpie.typedefs.Literal[users], allow_missing: bool = False) -> magpie.typedefs.UsersConfig get_all_configs(path_or_dict: Union[magpie.typedefs.Str, magpie.typedefs.CombinedConfig], section: magpie.typedefs.Literal[permissions], allow_missing: bool = False) -> magpie.typedefs.PermissionsConfig get_all_configs(path_or_dict: Union[magpie.typedefs.Str, magpie.typedefs.CombinedConfig], section: magpie.typedefs.Literal[services], allow_missing: bool = False) -> magpie.typedefs.ServicesConfig get_all_configs(path_or_dict: Union[magpie.typedefs.Str, magpie.typedefs.CombinedConfig], section: magpie.typedefs.Literal[webhooks], allow_missing: bool = False) -> magpie.typedefs.WebhooksConfig Loads all matched configurations. Configurations are considered a valid match if they have one of the :py:data:`CONFIG_KNOWN_EXTENSIONS` (if path) and that loaded (or passed) configurations contain the specified :paramref:`section` name. If the input is a directory path, loads any number of files contained in it that fulfill matching conditions. If it is a path pointing to a single valid configuration file, loads it by itself. If a dictionary is passed, returns it directly if it fulfills validation. :param path_or_dict: directory path, file path or literal dictionary. :param section: section name that must be inside every matched configuration file to be loaded. :param allow_missing: allow to have no valid configuration after all are resolved, otherwise raises. :raises RegistrationError: when no valid configuration can be found and empty one is not allowed. :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. .. py:function:: pseudo_random_string(length: int = 8, allow_chars: magpie.typedefs.Str = string.ascii_letters + string.digits) -> magpie.typedefs.Str Generate a string made of random characters. .. py:function:: get_json(request_or_response: Union[magpie.typedefs.AnyRequestType, magpie.typedefs.AnyResponseType]) -> magpie.typedefs.JSON Retrieves the 'JSON' body of a response using the property/callable according to the response's implementation. .. py:function:: get_logger(name: magpie.typedefs.Str, level: Optional[int] = None, force_stdout: bool = None, message_format: Optional[magpie.typedefs.Str] = None, datetime_format: Optional[magpie.typedefs.Str] = None) -> logging.Logger Immediately sets the logger level to avoid duplicate log outputs from the `root logger` and `this logger` when `level` is ``logging.NOTSET``. .. py:data:: UserConfig .. py:data:: LOGGER .. py:data:: ERROR_PARAMS :value: 2 .. py:data:: ERROR_EXEC :value: 1 .. py:function:: format_response(response) .. py:function:: get_login_session(magpie_url, username, password, return_response=False) .. py:function:: create_users(user_config: UserConfig, magpie_url: magpie.typedefs.Str, magpie_admin_username: magpie.typedefs.Str, magpie_admin_password: magpie.typedefs.Str, password_length: Optional[int] = None) -> UserConfig Creates the users using provided configuration. :returns: updated configuration with generated user-credentials. .. py:function:: delete_users(user_config: UserConfig, magpie_url: magpie.typedefs.Str, magpie_admin_username: magpie.typedefs.Str, magpie_admin_password: magpie.typedefs.Str, **__: Any) -> UserConfig Deletes the specified users. :returns: details about request success or failure for each user to be deleted. .. py:function:: make_output(user_results: UserConfig, is_delete: bool, output_location: Optional[magpie.typedefs.Str] = None) -> None Generates the output from obtained user creation/deletion results. .. py:function:: make_parser() -> argparse.ArgumentParser .. py:function:: main(args: Optional[Sequence[magpie.typedefs.Str]] = None, parser: Optional[argparse.ArgumentParser] = None, namespace: Optional[argparse.Namespace] = None) -> Any