Connections

The API exposes DSS connections, which can be created, modified and deleted through the API. These operations are restricted to API keys with the “admin rights” flag.

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': [{'name': 'useSSL', 'value': 'true'}], 'user': 'admin'}
new_connection = client.create_connection('test_connection', type='MySql', params=new_connection_params, usable_by='ALLOWED', allowed_groups=['administrators','data_team'])
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()

Reference documentation

class dataikuapi.dss.admin.DSSConnection(client, name)

A connection on the DSS instance. Do not create this object directly, use dataikuapi.DSSClient.get_connection() instead.

get_location_info()

Deprecated, use get_info

get_info(contextual_project_key=None)

Gets information about this connection.

Note: this call requires permissions to read connection details

Parameters

contextual_project_key – optional project key use to resolve variables

Returns

a DSSConnectionInfo containing connection information

delete()

Delete the connection

get_definition()

Get the connection’s definition (type, name, params, usage restrictions)

Returns

The connection definition, as a dict.

The exact structure of the returned dict is not documented and depends on the connection type. Create connections using the DSS UI and call get_definition() to see the fields that are in it.

set_definition(description)

Set the connection’s definition.

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

:param dict the definition for the connection, as a dict.

sync_root_acls()

Resync root permissions on this connection path. This is only useful for HDFS connections when DSS has User Isolation activated with “DSS-managed HDFS ACL”

Returns

a DSSFuture handle to the task of resynchronizing the permissions

sync_datasets_acls()

Resync permissions on datasets in this connection path. This is only useful for HDFS connections when DSS has User Isolation activated with “DSS-managed HDFS ACL”

Returns

a DSSFuture handle to the task of resynchronizing the permissions

class dataikuapi.dss.admin.DSSConnectionInfo(data)

A class holding read-only information about a connection. Do not create this object directly, use DSSConnection.get_info() instead.

The main use case of this class is to retrieve the decrypted credentials for a connection, if allowed by the connection permissions.

Depending on the connection kind, the credential may be available using get_basic_credential() or get_aws_credential().

get_type()

Returns the type of the connection

get_params()

Returns the parameters of the connection, as a dict

get_basic_credential()

Returns the basic credential (user/password pair) for this connection, if available

Returns

the credential, as a dict containing “user” and “password”

:rtype dict

get_aws_credential()

Returns the AWS credential for this connection, if available. The AWS credential can either be a keypair or a STS token triplet

Returns

the credential, as a dict containing “accessKey”, “secretKey”, and “sessionToken” (only in the case of STS token)

:rtype dict