Skip to content

Commit

Permalink
Merge pull request #55 from PagerDuty/v4.1.4-routing-key-in-body
Browse files Browse the repository at this point in the history
[V4.1.4] include the routing key in the body
  • Loading branch information
Deconstrained committed Mar 18, 2021
2 parents 09bd627 + faefcca commit 563e671
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 12 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.rst
@@ -1,3 +1,9 @@
**2021-03-18: Version 4.1.4**

* Fix regression in :attr:`EventsAPISession.post`
* Use case: explicitly-defined body (``json`` keyword argument) without a ``routing_key`` parameter
* This was previously possible (before version 4.1.3) with the ``X-Routing-Key`` header (an undocumented API feature)

**2021-03-10: Version 4.1.3**

* Use documented method for including the routing key in the request for API V2 (addresses `#53 <https://github.com/PagerDuty/pdpyras/issues/53>`_)
Expand Down
2 changes: 1 addition & 1 deletion docs/_static/documentation_options.js
@@ -1,6 +1,6 @@
var DOCUMENTATION_OPTIONS = {
URL_ROOT: document.getElementById("documentation_options").getAttribute('data-url_root'),
VERSION: '4.1.3',
VERSION: '4.1.4',
LANGUAGE: 'None',
COLLAPSE_INDEX: false,
BUILDER: 'html',
Expand Down
4 changes: 3 additions & 1 deletion docs/genindex.html
Expand Up @@ -5,7 +5,7 @@
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Index &#8212; PagerDuty Python REST API Sessions 4.1.3 documentation</title>
<title>Index &#8212; PagerDuty Python REST API Sessions 4.1.4 documentation</title>
<link rel="stylesheet" href="_static/alabaster.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<script id="documentation_options" data-url_root="./" src="_static/documentation_options.js"></script>
Expand Down Expand Up @@ -187,6 +187,8 @@ <h2 id="P">P</h2>
</li>
</ul></td>
<td style="width: 33%; vertical-align: top;"><ul>
<li><a href="index.html#pdpyras.EventsAPISession.post">post() (pdpyras.EventsAPISession method)</a>
</li>
<li><a href="index.html#pdpyras.APISession.postprocess">postprocess() (pdpyras.APISession method)</a>

<ul>
Expand Down
20 changes: 19 additions & 1 deletion docs/index.html
Expand Up @@ -5,7 +5,7 @@
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>PDPYRAS: PagerDuty Python REST API Sessions &#8212; PagerDuty Python REST API Sessions 4.1.3 documentation</title>
<title>PDPYRAS: PagerDuty Python REST API Sessions &#8212; PagerDuty Python REST API Sessions 4.1.4 documentation</title>
<link rel="stylesheet" href="_static/alabaster.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<script id="documentation_options" data-url_root="./" src="_static/documentation_options.js"></script>
Expand Down Expand Up @@ -1218,6 +1218,13 @@ <h3>Events API Client<a class="headerlink" href="#events-api-client" title="Perm
<dd><p>Generates the header with the API credential used for authentication.</p>
</dd></dl>

<dl class="py method">
<dt id="pdpyras.EventsAPISession.post">
<code class="sig-name descname">post</code><span class="sig-paren">(</span><em class="sig-param"><span class="o">*</span><span class="n">args</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kw</span></em><span class="sig-paren">)</span><a class="headerlink" href="#pdpyras.EventsAPISession.post" title="Permalink to this definition"></a></dt>
<dd><p>Override of <code class="docutils literal notranslate"><span class="pre">requests.Session.post</span></code></p>
<p>Adds the <code class="docutils literal notranslate"><span class="pre">routing_key</span></code> parameter to the body before sending.</p>
</dd></dl>

<dl class="py method">
<dt id="pdpyras.EventsAPISession.prepare_headers">
<code class="sig-name descname">prepare_headers</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">method</span></em><span class="sig-paren">)</span><a class="headerlink" href="#pdpyras.EventsAPISession.prepare_headers" title="Permalink to this definition"></a></dt>
Expand Down Expand Up @@ -1462,6 +1469,17 @@ <h3>Errors<a class="headerlink" href="#id2" title="Permalink to this headline">
</div>
<div class="section" id="changelog">
<h2>Changelog<a class="headerlink" href="#changelog" title="Permalink to this headline"></a></h2>
<p><strong>2021-03-18: Version 4.1.4</strong></p>
<ul class="simple">
<li><dl class="simple">
<dt>Fix regression in <a class="reference internal" href="#pdpyras.EventsAPISession.post" title="pdpyras.EventsAPISession.post"><code class="xref py py-attr docutils literal notranslate"><span class="pre">EventsAPISession.post</span></code></a></dt><dd><ul>
<li><p>Use case: explicitly-defined body (<code class="docutils literal notranslate"><span class="pre">json</span></code> keyword argument) without a <code class="docutils literal notranslate"><span class="pre">routing_key</span></code> parameter</p></li>
<li><p>This was previously possible (before version 4.1.3) with the <code class="docutils literal notranslate"><span class="pre">X-Routing-Key</span></code> header (an undocumented API feature)</p></li>
</ul>
</dd>
</dl>
</li>
</ul>
<p><strong>2021-03-10: Version 4.1.3</strong></p>
<ul class="simple">
<li><p>Use documented method for including the routing key in the request for API V2 (addresses <a class="reference external" href="https://github.com/PagerDuty/pdpyras/issues/53">#53</a>)</p></li>
Expand Down
Binary file modified docs/objects.inv
Binary file not shown.
2 changes: 1 addition & 1 deletion docs/py-modindex.html
Expand Up @@ -5,7 +5,7 @@
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Python Module Index &#8212; PagerDuty Python REST API Sessions 4.1.3 documentation</title>
<title>Python Module Index &#8212; PagerDuty Python REST API Sessions 4.1.4 documentation</title>
<link rel="stylesheet" href="_static/alabaster.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<script id="documentation_options" data-url_root="./" src="_static/documentation_options.js"></script>
Expand Down
2 changes: 1 addition & 1 deletion docs/search.html
Expand Up @@ -5,7 +5,7 @@
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Search &#8212; PagerDuty Python REST API Sessions 4.1.3 documentation</title>
<title>Search &#8212; PagerDuty Python REST API Sessions 4.1.4 documentation</title>
<link rel="stylesheet" href="_static/alabaster.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />

Expand Down
2 changes: 1 addition & 1 deletion docs/searchindex.js

Large diffs are not rendered by default.

17 changes: 12 additions & 5 deletions pdpyras.py
Expand Up @@ -20,7 +20,7 @@
warnings.warn('Module pdpyras will no longer support Python 2.7 as of '
'June 21, 2021.')

__version__ = '4.1.3'
__version__ = '4.1.4'

# These are API resource endpoints/methods for which multi-update is supported
VALID_MULTI_UPDATE_PATHS = [
Expand Down Expand Up @@ -697,10 +697,7 @@ def send_event(self, action, dedup_key=None, **properties):
if action not in actions:
raise ValueError("Event action must be one of: "+', '.join(actions))

event = {
'event_action':action,
'routing_key': self.api_key
}
event = {'event_action':action}

event.update(properties)
if isinstance(dedup_key, string_types):
Expand All @@ -716,6 +713,16 @@ def send_event(self, action, dedup_key=None, **properties):
"deduplication key.", response=response)
return response_body['dedup_key']

def post(self, *args, **kw):
"""
Override of ``requests.Session.post``
Adds the ``routing_key`` parameter to the body before sending.
"""
if 'json' in kw and hasattr(kw['json'], 'update'):
kw['json'].update({'routing_key': self.api_key})
return super(EventsAPISession, self).post(*args, **kw)

def trigger(self, summary, source, dedup_key=None, severity='critical',
payload=None, custom_details=None, images=None, links=None):
"""
Expand Down
2 changes: 1 addition & 1 deletion setup.py
@@ -1,6 +1,6 @@
from setuptools import setup, find_packages

__version__ = '4.1.3'
__version__ = '4.1.4'

if __name__ == '__main__':
setup(
Expand Down
20 changes: 20 additions & 0 deletions test_pdpyras.py
Expand Up @@ -127,6 +127,26 @@ def test_send_event(self):
},
parent.request.call_args[1]['json'])

def test_send_explicit_event(self):
# test sending an event by calling `post` directly as opposed to any of
# the methods written into the client for sending events
sess = pdpyras.EventsAPISession('routingkey')
parent = MagicMock()
parent.request = MagicMock()
parent.request.side_effect = [Response(202, '{"dedup_key":"abc123"}')]
with patch.object(sess, 'parent', new=parent):
response = sess.post('/v2/enqueue', json={
'payload': {
'summary': 'testing 123',
'source': 'pdpyras integration',
'severity': 'critical'
},
'event_action': 'trigger'
})
json_sent = parent.request.call_args[1]['json']
self.assertTrue('routing_key' in json_sent)
self.assertEqual(json_sent['routing_key'], 'routingkey')

class APISessionTest(SessionTest):

def debug(self, sess):
Expand Down

0 comments on commit 563e671

Please sign in to comment.