Administering the DSS instance

The API exposes key parts of the DSS access control management: users, groups, and connections. 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()

Managing connections

A list of the connections can by obtained with the list_connections method:

client = DSSClient(host, apiKey)
dss_connections = client.list_connections()
prettyprinter.pprint(dss_connections)

outputs

{   'filesystem_managed': {   'allowManagedDatasets': True,
                               'allowMirror': False,
                               'allowWrite': True,
                               'allowedGroups': [],
                               'maxActivities': 0,
                               'name': 'filesystem_managed',
                               'params': {   'root': '${dip.home}/managed_datasets'},
                               'type': 'Filesystem',
                               'usableBy': 'ALL',
                               'useGlobalProxy': True},
    'hdfs_root': {   'allowManagedDatasets': True,
                      'allowMirror': False,
                      'allowWrite': True,
                      'allowedGroups': [],
                      'maxActivities': 0,
                      'name': 'hdfs_root',
                      'params': {   'database': 'dataik', 'root': '/'},
                      'type': 'HDFS',
                      'usableBy': 'ALL',
                      'useGlobalProxy': False},
    'local_postgress': {   'allowManagedDatasets': True,
                            'allowMirror': False,
                            'allowWrite': True,
                            'allowedGroups': [],
                            'maxActivities': 0,
                            'name': 'local_postgress',
                            'params': {   'db': 'testdb',
                                           'host': 'localhost',
                                           'password': 'admin',
                                           'port': '5432',
                                           'properties': {   },
                                           'user': 'admin'},
                            'type': 'PostgreSQL',
                            'usableBy': 'ALL',
                            'useGlobalProxy': False},
    ...
}

Connections can be added:

new_connection_params = {'db':'mysql_test', 'host': 'localhost', 'password': 'admin', 'properties': {   }, 'user': 'admin'}
new_connection = client.create_connection('test_connection', type='MySql', params=new_connection_params, usable_by='ALLOWED', allowed_groups=['data_scientists'])
prettyprinter.pprint(client.list_connections()['test_connection'])

outputs

{   'allowManagedDatasets': True,
    'allowMirror': True,
    'allowWrite': True,
    'allowedGroups': ['data_scientists'],
    'maxActivities': 0,
    'name': 'test_connection',
    'params': {   'db': 'mysql_test',
                   'host': 'localhost',
                   'password': 'admin',
                   'properties': {   },
                   'user': 'admin'},
    'type': 'MySql',
    'usableBy': 'ALLOWED',
    'useGlobalProxy': True}

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

connection_definition = new_connection.get_definition()
connection_definition['usableBy'] = 'ALL'
connection_definition['allowWrite'] = False
new_connection.set_definition(connection_definition)
prettyprinter.pprint(new_connection.get_definition())

outputs

{   'allowManagedDatasets': True,
    'allowMirror': True,
    'allowWrite': False,
    'allowedGroups': ['data_scientists'],
    'maxActivities': 0,
    'name': 'test_connection',
    'params': {   'db': 'mysql_test',
                   'host': 'localhost',
                   'password': 'admin',
                   'properties': {   },
                   'user': 'admin'},
    'type': 'MySql',
    'usableBy': 'ALL',
    'useGlobalProxy': True}

Connections can be deleted through their handle:

connection = client.get_connection('test_connection')
connection.delete()