11from .future import DSSFuture
22import json
33
4+ class DSSConnectionInfo (dict ):
5+ """A class holding read-only information about a connection.
6+ This class should not be created directly. Instead, use :meth:`DSSConnection.get_info`
7+
8+ The main use case of this class is to retrieve the decrypted credentials for a connection,
9+ if allowed by the connection permissions.
10+
11+ Depending on the connection kind, the credential may be available using :meth:`get_basic_credential`
12+ or :meth:`get_aws_credential`
13+
14+ """
15+ def __init__ (self , data ):
16+ """Do not call this directly, use :meth:`DSSConnection.get_info`"""
17+ super (DSSConnectionInfo , self ).__init__ (data )
18+
19+ def get_type (self ):
20+ """Returns the type of the connection"""
21+ return self ["type" ]
22+
23+ def get_params (self ):
24+ """Returns the parameters of the connection, as a dict"""
25+ return self ["params" ]
26+
27+ def get_basic_credential (self ):
28+ """
29+ Returns the basic credential (user/password pair) for this connection, if available
30+
31+ :returns: the credential, as a dict containing "user" and "password"
32+ :rtype dict
33+ """
34+ if not "resolvedBasicCredential" in self :
35+ raise ValueError ("No basic credential available" )
36+ return self ["resolvedBasicCredential" ]
37+
38+ def get_aws_credential (self ):
39+ """
40+ Returns the AWS credential for this connection, if available.
41+ The AWS credential can either be a keypair or a STS token triplet
42+
43+ :returns: the credential, as a dict containing "accessKey", "secretKey", and "sessionToken" (only in the case of STS token)
44+ :rtype dict
45+ """
46+ if not "resolvedAWSCredential" in self :
47+ raise ValueError ("No AWS credential available" )
48+ return self ["resolvedAWSCredential" ]
49+
50+
51+
52+
53+
454class DSSConnection (object ):
555 """
656 A connection on the DSS instance
@@ -14,6 +64,10 @@ def __init__(self, client, name):
1464 ########################################################
1565
1666 def get_location_info (self ):
67+ """Deprecated, use get_info"""
68+ return self .get_info ()
69+
70+ def get_info (self ):
1771 """
1872 Gets information about this connection.
1973
@@ -22,10 +76,10 @@ def get_location_info(self):
2276 belongs to a group who has the rights to read connection
2377 details
2478
25- :returns: a dict containing connection information
79+ :returns: a :class:`DSSConnectionInfo` containing connection information
2680 """
27- return self .client ._perform_json (
28- "GET" , "/connections/%s/info" % self .name )
81+ return DSSConnectionInfo ( self .client ._perform_json (
82+ "GET" , "/connections/%s/info" % self .name ))
2983
3084 ########################################################
3185 # Connection deletion
0 commit comments