diff --git a/examples/users/add_user.py b/examples/users/add_user.py new file mode 100644 index 0000000..424bbf5 --- /dev/null +++ b/examples/users/add_user.py @@ -0,0 +1,33 @@ +#!/usr/bin/env python3 +""" +Caracara Examples Collection. + +add_user.py + +This example will use the API credentials configured in your config.yml file to +add a user in the Falcon tenant. +""" +import logging + +from examples.common import caracara_example, pretty_print + +from caracara import Client + + + +@caracara_example +def add_user(first_name, last_name, email_address, **kwargs): + """Add User Example.""" + client: Client = kwargs["client"] + logger: logging.Logger = kwargs["logger"] + + logger.info("Adding a user in the Falcon tenant") + new_user_data = client.users.add_user(first_name, last_name, email_address) + logger.info(pretty_print(new_user_data)) + + +if __name__ == "__main__": + FIRST_NAME = "sampleName" + LAST_NAME = "sampleLastName" + EMAIL_ADDRESS = "sample.email@example.com" + add_user(FIRST_NAME, LAST_NAME, EMAIL_ADDRESS) diff --git a/examples/users/delete_user.py b/examples/users/delete_user.py new file mode 100644 index 0000000..a4f5122 --- /dev/null +++ b/examples/users/delete_user.py @@ -0,0 +1,44 @@ +#!/usr/bin/env python3 +""" +Caracara Examples Collection. + +delete_user.py + +This example will use the API credentials configured in your config.yml file to +delete a user in the Falcon tenant. +""" +import logging + +from examples.common import caracara_example, pretty_print + +from caracara import Client + + +@caracara_example +def delete_user(uuid, **kwargs): + """Delete Users Example.""" + client: Client = kwargs["client"] + logger: logging.Logger = kwargs["logger"] + + logger.info("Deleting a user in the Falcon tenant") + deleted_user_data = client.users.add_user(uuid) + logger.info(pretty_print(deleted_user_data)) + + +@caracara_example +def get_uuid(email_address, **kwargs): + """Get UUID for Delete Users Example.""" + client: Client = kwargs["client"] + logger: logging.Logger = kwargs["logger"] + + logger.info("Retrieving UUID for a user in the Falcon tenant") + uuid_data = client.users.get_uuid_by_email(email_address) + return uuid_data + + +if __name__ == "__main__": + # delete_user requires a uuid, a string of characters + # you can find this via get_uuid_by_email (from caracara) if needed + EMAIL = "sample_email" + fetched_uuid = get_uuid(EMAIL) + delete_user(fetched_uuid)