2929from ._common_util import (
3030 USER_AGENT ,
3131 append_response_error_content ,
32- InfiniteSession ,
3332 ClientSession ,
3433 CloudFoundryService ,
3534 CookieSession ,
@@ -68,6 +67,10 @@ class CouchDB(dict):
6867 `Requests library timeout argument
6968 <http://docs.python-requests.org/en/master/user/quickstart/#timeouts>`_.
7069 but will apply to every request made using this client.
70+ :param bool use_iam: Keyword argument, if set to True performs
71+ IAM authentication with server. Default is False.
72+ Use :func:`~cloudant.client.CouchDB.iam` to construct an IAM
73+ authenticated client.
7174 """
7275 _DATABASE_CLASS = CouchDatabase
7376
@@ -147,16 +150,8 @@ def session(self):
147150 """
148151 if self .admin_party :
149152 return None
150- < << << << HEAD
151- sess_url = '/' .join ((self .server_url , '_session' ))
152- resp = self .r_session .get (sess_url )
153- resp .raise_for_status ()
154- sess_data = resp .json ()
155- return sess_data
156- == == == =
157153
158154 return self .r_session .info ()
159- >> >> >> > Add IAM authentication support
160155
161156 def session_cookie (self ):
162157 """
@@ -175,21 +170,8 @@ def session_login(self):
175170 """
176171 if self .admin_party :
177172 return
178- < << << << HEAD
179- sess_url = '/' .join ((self .server_url , '_session' ))
180- resp = self .r_session .post (
181- sess_url ,
182- data = {
183- 'name' : user ,
184- 'password' : passwd
185- },
186- headers = {'Content-Type' : 'application/x-www-form-urlencoded' }
187- )
188- resp .raise_for_status ()
189- == == == =
190173
191174 self .r_session .login ()
192- >> >> >> > Add IAM authentication support
193175
194176 def session_logout (self ):
195177 """
@@ -198,14 +180,8 @@ def session_logout(self):
198180 """
199181 if self .admin_party :
200182 return
201- < << << << HEAD
202- sess_url = '/' .join ((self .server_url , '_session' ))
203- resp = self .r_session .delete (sess_url )
204- resp .raise_for_status ()
205- == == == =
206183
207184 self .r_session .logout ()
208- >> >> >> > Add IAM authentication support
209185
210186 def basic_auth_str (self ):
211187 """
@@ -805,3 +781,13 @@ def bluemix(cls, vcap_services, instance_name=None, **kwargs):
805781 service .password ,
806782 url = service .url ,
807783 ** kwargs )
784+
785+ @classmethod
786+ def iam (cls , account_name , api_key , ** kwargs ):
787+ """
788+ Create a Cloudant client that uses IAM authentication.
789+
790+ :param account_name: Cloudant account name.
791+ :param api_key: IAM authentication API key.
792+ """
793+ return cls (None , api_key , account = account_name , use_iam = True , ** kwargs )
0 commit comments