From bb7e742da81ca8b39d040b98b6ae2a12857550a3 Mon Sep 17 00:00:00 2001 From: Paolo Sechi Date: Wed, 22 Feb 2017 20:58:04 +0100 Subject: [PATCH 1/4] Implement multi user authentication --- pingdom/connection.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pingdom/connection.py b/pingdom/connection.py index 13a056a..64f1135 100644 --- a/pingdom/connection.py +++ b/pingdom/connection.py @@ -39,7 +39,9 @@ def __init__(self, connection, resource, post_data=None, method=None, :type connection: :class:`PingdomConnection` :param connection: Pingdom connection object populated with a username, - password and base URL + password and base URL. + Additional email can be provided for multi user authentication: + https://www.pingdom.com/resources/api#multi-user+authentication :type resource: string :param resource: Pingdom resource to query (in all lowercase) @@ -60,6 +62,8 @@ def __init__(self, connection, resource, post_data=None, method=None, self.method = self._method(method, post_data) self.auth = HTTPBasicAuth(connection.username, connection.password) self.headers = {'App-Key': connection.apikey} + if 'email' in connection: + self.headers['Account-Email'] = connection['email'] # TODO ensure this still works # # Enable gzip @@ -198,7 +202,7 @@ def get_summary_average(self, check_id, from_time=0, to_time=0, (check_id, from_time, to_time, include_uptime) response = PingdomRequest(self, rs).fetch() return response.content['summary'] - + def get_actions(self, limit): """Get a list of Pingdom actions/alerts""" response = PingdomRequest(self, 'actions/?limit=%s' % limit).fetch() From 45c76276be1d1ec2366065e4a22a265c5ba1b9e5 Mon Sep 17 00:00:00 2001 From: Paolo Sechi Date: Wed, 22 Feb 2017 21:10:45 +0100 Subject: [PATCH 2/4] fix missing parameter --- pingdom/connection.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pingdom/connection.py b/pingdom/connection.py index 64f1135..b11d7dd 100644 --- a/pingdom/connection.py +++ b/pingdom/connection.py @@ -102,13 +102,14 @@ def __repr__(self): class PingdomConnection(object): def __init__(self, username, password, apikey='', - base_url=BASE_URL + BASE_VERSION): + base_url=BASE_URL + BASE_VERSION, email=''): """Interface to the Pingdom API.""" self.username = username self.password = password self.apikey = apikey self.base_url = base_url + self.email = email def __repr__(self): return "Connection:%s" % self.base_url From 19c238b3337b0f49ae550e250a3000e981fc9632 Mon Sep 17 00:00:00 2001 From: Paolo Sechi Date: Wed, 22 Feb 2017 21:13:40 +0100 Subject: [PATCH 3/4] fix missing parameter --- pingdom/connection.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pingdom/connection.py b/pingdom/connection.py index b11d7dd..fa0740e 100644 --- a/pingdom/connection.py +++ b/pingdom/connection.py @@ -62,8 +62,8 @@ def __init__(self, connection, resource, post_data=None, method=None, self.method = self._method(method, post_data) self.auth = HTTPBasicAuth(connection.username, connection.password) self.headers = {'App-Key': connection.apikey} - if 'email' in connection: - self.headers['Account-Email'] = connection['email'] + if connection.email: + self.headers['Account-Email'] = connection.email # TODO ensure this still works # # Enable gzip From bd2eb34c08913012cd5b16ff2cf337ae3a996fdd Mon Sep 17 00:00:00 2001 From: Paolo Sechi Date: Wed, 22 Feb 2017 22:19:34 +0100 Subject: [PATCH 4/4] multi user aut docs --- docs/usage.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/usage.rst b/docs/usage.rst index 9f5c3bf..ad146ad 100644 --- a/docs/usage.rst +++ b/docs/usage.rst @@ -4,7 +4,7 @@ Library Usage Set up a Pingdom connection: >>> import pingdom - >>> c = pingdom.PingdomConnection(PINGDOM_USERNAME, PINGDOM_PASSWORD, API_KEY) # Same credentials you use for the Pingdom website + >>> c = pingdom.PingdomConnection(PINGDOM_USERNAME, PINGDOM_PASSWORD, API_KEY) # Same credentials you use for the Pingdom website. (email=EMAIL is required for multi users accounts) Create a new Pingdom check: