Managing users and groups

The API exposes key parts of the DSS access control management: users and groups. All these can be created, modified and deleted through the API. These operations are restricted to API keys with the “admin rights” flag.

Managing users

A list of the users can by obtained with the list_users method:

client = DSSClient(host, apiKey)
dss_users = client.list_users()
prettyprinter.pprint(dss_users)

outputs

[   {   'activeWebSocketSesssions': 0,
        'codeAllowed': True,
        'displayName': 'Administrator',
        'groups': ['administrators', 'data_scientists'],
        'login': 'admin',
        'objectImgHash': 0,
        'sourceType': 'LOCAL'},
    ...
]

Users can be added:

new_user = client.create_user('test_login', 'test_password', display_name='a test user', source_type='LOCAL', groups=['data_scientists'])
prettyprinter.pprint(client.list_users())

outputs

[   {   'activeWebSocketSesssions': 0,
        'codeAllowed': True,
        'displayName': 'a test user',
        'groups': ['data_scientists'],
        'login': 'test_login',
        'objectImgHash': 0,
        'sourceType': 'LOCAL'},
    ...
]

To modify a user, it is advised to first retrieve the user definition with a get_definition call, alter the definition, and set it back into DSS:

user_definition = new_user.get_definition()
user_definition['displayName'] = 'a better name'
user_definition['password'] = 'a different password'
new_user.set_definition(user_definition)
prettyprinter.pprint(new_user.get_definition())

outputs

{'msg': 'Edited user test_login'}
{   'activeWebSocketSesssions': 0,
    'codeAllowed': True,
    'displayName': 'a better name',
    'groups': ['data_scientists'],
    'login': 'test_login',
    'objectImgHash': 0,
    'sourceType': 'LOCAL'}

Users can be deleted through their handle:

user = client.get_user('test_login')
user.delete()

Managing groups

A list of the groups can by obtained with the list_groups method:

client = DSSClient(host, apiKey)
dss_groups = client.list_groups()
prettyprinter.pprint(dss_groups)

outputs

[   {   'admin': True,
        'description': 'DSS administrators',
        'name': 'administrators',
        'sourceType': 'LOCAL'},
    {   'admin': False,
        'description': 'Read-write access to projects',
        'name': 'data_scientists',
        'sourceType': 'LOCAL'},
    {   'admin': False,
        'description': 'Read-only access to projects',
        'name': 'readers',
        'sourceType': 'LOCAL'}]

Groups can be added:

new_group = client.create_group('test_group', description='test group', source_type='LOCAL')
prettyprinter.pprint(client.list_groups())

outputs

    [       {   'admin': False,
            'description': 'test group',
            'name': 'test_group',
            'sourceType': 'LOCAL'},
    ...
]

To modify a group, it is advised to first retrieve the group definition with a get_definition call, alter the definition, and set it back into DSS:

group_definition = new_group.get_definition()
group_definition['admin'] = True
group_definition['ldapGroupNames'] = 'group1,group2'
new_group.set_definition(group_definition)
prettyprinter.pprint(new_group.get_definition())

outputs

{'msg': 'Modified group group_name'}
{   'admin': True,
    'description': 'test group',
    'name': 'test_group',
    'sourceType': 'LOCAL'}

Users can be deleted through their handle:

group = client.get_group('test_group')
group.delete()

Reference documentation

class dataikuapi.dss.admin.DSSUser(client, login)

A handle for a user on the DSS instance. Do not create this directly, use dataikuapi.DSSClient.get_user()

delete()

Deletes the user Note: this call requires an API key with admin rights

get_definition()

Get the user’s definition (login, type, display name, permissions, …) Note: this call requires an API key with admin rights

Returns:the user’s definition, as a dict
set_definition(definition)

Set the user’s definition. Note: this call requires an API key with admin rights

You should only set_definition() using an object that you obtained through get_definition(), not create a new dict.

The fields that may be changed in a user definition are:

  • email
  • displayName
  • groups
  • userProfile
  • password
Parameters:definition (dict) – the definition for the user, as a dict
class dataikuapi.dss.admin.DSSGroup(client, name)

A group on the DSS instance. Do not create this directly, use dataikuapi.DSSClient.get_group()

delete()

Deletes the group Note: this call requires an API key with admin rights

get_definition()

Get the group’s definition (name, description, admin abilities, type, ldap name mapping) Note: this call requires an API key with admin rights

Returns:the group’s definition, as a dict
set_definition(definition)

Set the group’s definition. Note: this call requires an API key with admin rights

You should only set_definition() using an object that you obtained through get_definition(), not create a new dict.

Args:
definition: the definition for the group, as a dict