magpie.cli.batch_update_users¶
Magpie helper to create or delete a list of users using a set of input parameters.
Useful for batch operations.
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 |
Loads all matched configurations. |
|
|
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 |
|
|
|
|
|
Creates the users using provided configuration. |
|
Deletes the specified users. |
|
Generates the output from obtained user creation/deletion results. |
|
|
|
Module Contents¶
- magpie.cli.batch_update_users.make_logging_options(parser: argparse.ArgumentParser) None[source]¶
Defines argument parser options for logging operations.
- magpie.cli.batch_update_users.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.batch_update_users.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.batch_update_users.get_all_configs(path_or_dict: magpie.typedefs.Str | magpie.typedefs.CombinedConfig, section: magpie.typedefs.Literal[groups], allow_missing: bool = False) magpie.typedefs.GroupsConfig[source]¶
- magpie.cli.batch_update_users.get_all_configs(path_or_dict: magpie.typedefs.Str | magpie.typedefs.CombinedConfig, section: magpie.typedefs.Literal[users], allow_missing: bool = False) magpie.typedefs.UsersConfig
- magpie.cli.batch_update_users.get_all_configs(path_or_dict: magpie.typedefs.Str | magpie.typedefs.CombinedConfig, section: magpie.typedefs.Literal[permissions], allow_missing: bool = False) magpie.typedefs.PermissionsConfig
- magpie.cli.batch_update_users.get_all_configs(path_or_dict: magpie.typedefs.Str | magpie.typedefs.CombinedConfig, section: magpie.typedefs.Literal[services], allow_missing: bool = False) magpie.typedefs.ServicesConfig
- magpie.cli.batch_update_users.get_all_configs(path_or_dict: 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
CONFIG_KNOWN_EXTENSIONS(if path) and that loaded (or passed) configurations contain the specifiedsectionname.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.
- Parameters:
path_or_dict – directory path, file path or literal dictionary.
section – section name that must be inside every matched configuration file to be loaded.
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.
- magpie.cli.batch_update_users.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.batch_update_users.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.batch_update_users.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.batch_update_users.get_login_session(magpie_url, username, password, return_response=False)[source]¶
- magpie.cli.batch_update_users.create_users(user_config: UserConfig, magpie_url: magpie.typedefs.Str, magpie_admin_username: magpie.typedefs.Str, magpie_admin_password: magpie.typedefs.Str, password_length: int | None = None) UserConfig[source]¶
Creates the users using provided configuration.
- Returns:
updated configuration with generated user-credentials.
- magpie.cli.batch_update_users.delete_users(user_config: UserConfig, magpie_url: magpie.typedefs.Str, magpie_admin_username: magpie.typedefs.Str, magpie_admin_password: magpie.typedefs.Str, **__: Any) UserConfig[source]¶
Deletes the specified users.
- Returns:
details about request success or failure for each user to be deleted.