Users#

class saagieapi.users.Users(saagie_api)#

Bases: object

create(user_name: str, password: str, platforms: List[str] | None = None, roles: List[str] | None = None, groups: List[str] | None = None, verify_ssl: bool | None = None) bool#

Create a given user

Note

You can only use this function if you have the admin role on the platform

Parameters:
  • user_name (str) – User name

  • password (str) – User password

  • platforms (List[str], optional) – List of platforms

  • roles (List[str], optional) – List of roles By default, using ROLE_READER to have read access on the platform

  • groups (List[str], optional) – List of groups

  • verify_ssl (bool, optional) – Enable or disable verification of SSL certification By default, refers to saagie_api.verify_ssl

Returns:

True if user is created Error otherwise

Return type:

bool

Examples

>>> saagieapi.users.create(
...     user_name="user_reader",
...     password="A123456#a",
...     roles=["ROLE_READER"],
...     groups=["reader_group"]
... )
True
delete(user_name, verify_ssl: bool | None = None) bool#

Delete a given user

Note

You can only use this function if you have the admin role on the platform

Parameters:
  • user_name (str) – User name

  • verify_ssl (bool, optional) – Enable or disable verification of SSL certification By default, refers to saagie_api.verify_ssl

Returns:

True if user is deleted Error otherwise

Return type:

bool

Examples

>>> saagieapi.users.delete(user_name="user_reader")
True
edit_password(user_name, previous_pwd, new_pwd, verify_ssl: bool | None = None)#

Edit a given user’s password

Note

You can only use this function if you have the admin role on the platform

Parameters:
  • user_name (str) – User name

  • previous_pwd (str) – Previous user password

  • new_pwd (str) – New user password

  • verify_ssl (bool, optional) – Enable or disable verification of SSL certification By default, refers to saagie_api.verify_ssl

Returns:

True if user’s password is successfully edited Error otherwise

Return type:

bool

Examples

>>> saagieapi.users.edit_password(
...     user_name="test_user",
...     previous_pwd="A123456#a",
...     new_pwd="NewPwd123!"
... )
True
export(output_folder: str, verify_ssl: bool | None = None) bool#

Export users in a file

Note

You can only use this function if you have the admin role on the platform

Parameters:
  • output_folder (str, optional) – Path to store the exported users

  • verify_ssl (bool, optional) – Enable or disable verification of SSL certification By default, refers to saagie_api.verify_ssl

Returns:

True if users are exported False otherwise

Return type:

bool

Examples

>>> saagieapi.users.export(output_folder="./output/users/")
True
get_info(user_name: str, verify_ssl: bool | None = None) Dict#

Get info of a specific user

Note

You can only get user’s information if you have the admin role on the platform.

Parameters:
  • user_name (str) – User’s name

  • verify_ssl (bool, optional) – Enable or disable verification of SSL certification By default, refers to saagie_api.verify_ssl

Returns:

Dict of user’s information on the platform, the dict have the following structure: {‘login’: ‘str’, ‘roles’: [‘str’], ‘platforms’: [], ‘groups’: [‘str’], ‘protected’: bool}

Return type:

Dict

Examples

>>> saagieapi.users.get_info(user_name="test_user")
{
    "login": "test_user",
    "roles": [
        "ROLE_READER"
    ],
    "platforms": [],
    "groups": [
        "test_group"
    ],
    "protected": False
}
import_from_json(json_file: str, temp_pwd: str, error_folder: str | None = '', verify_ssl: bool | None = None) bool#

Import users from JSON format file

Note

You can only use this function if you have the admin role on the platform All protected (created at platform installation) users will not be imported.

Parameters:
  • json_file (str) – Path to json file that contains users

  • temp_pwd (str) – Password to all user that you want to import. At the first connection, each user has to change the password

  • error_folder (str, optional) – Path to store the failed imported user in case of error. If not set, failed imported users not write

  • verify_ssl (bool, optional) – Enable or disable verification of SSL certification By default, refers to saagie_api.verify_ssl

Returns:

True if users are all imported or already existed False otherwise

Return type:

bool

Examples

>>> saagieapi.users.import_from_json(
...     json_file="/path/to/the/json/file.json",
...     temp_pwd="NewPwd123!",
...     error_folder="/path/to/the/error/folder"
... )
True
list(verify_ssl: bool | None = None) List[Dict]#

Get users

Note

You can only list users if you have the admin role on the platform

Parameters:

verify_ssl (bool, optional) – Enable or disable verification of SSL certification By default, refers to saagie_api.verify_ssl

Returns:

List of users on the platform, each dict have the following structure: {‘login’: ‘str’, ‘roles’: [‘str’], ‘platforms’: [], ‘groups’: [‘str’], ‘protected’: bool}

Return type:

List[Dict]

Examples

>>> saagieapi.users.list()
[
    {
        "login": "test_user",
        "roles": [
            "ROLE_READER"
        ],
        "platforms": [],
        "groups": [
            "test_group"
        ],
        "protected": False
    },
    {
        "login": "customer_admin",
        "roles": [
            "ROLE_ADMIN"
        ],
        "platforms": [],
        "groups": [
            "administrators"
        ],
        "protected": True
    }
]