From 1448f7d0cca33a21b0b4190e4926bfb18b26a3ab Mon Sep 17 00:00:00 2001 From: Karl Keppner Date: Fri, 22 May 2020 23:03:28 -0600 Subject: [PATCH 1/2] added application deployments support, tests, and documentation --- docs/ref/application_deployments.rst | 14 ++ docs/release_notes.rst | 6 + docs/toc.rst | 1 + newrelic_api/application_deployments.py | 176 ++++++++++++++++++++++++ newrelic_api/version.py | 2 +- 5 files changed, 198 insertions(+), 1 deletion(-) create mode 100644 docs/ref/application_deployments.rst create mode 100644 newrelic_api/application_deployments.py diff --git a/docs/ref/application_deployments.rst b/docs/ref/application_deployments.rst new file mode 100644 index 0000000..38bf471 --- /dev/null +++ b/docs/ref/application_deployments.rst @@ -0,0 +1,14 @@ +.. _ref-application_deployments: + +Application Deployments +======================= + +newrelic_api.application_deployments +------------------------------------ + +.. automodule:: newrelic_api.application_deployments +.. autoclass:: newrelic_api.application_deployments.ApplicationDeployments + :members: + :undoc-members: + + .. automethod:: __init__ diff --git a/docs/release_notes.rst b/docs/release_notes.rst index c86a330..d497992 100644 --- a/docs/release_notes.rst +++ b/docs/release_notes.rst @@ -1,6 +1,12 @@ Release Notes ============= +v1.0.7 +------ + +* Adds support for Application Deployment Markers +* Changed version of Sphinx in docs requirements + v1.0.6 ------ diff --git a/docs/toc.rst b/docs/toc.rst index ce22380..06166dd 100644 --- a/docs/toc.rst +++ b/docs/toc.rst @@ -10,6 +10,7 @@ Table of Contents examples ref/alert_policies ref/applications + ref/application_deployments ref/application_hosts ref/application_instances ref/browser_applications diff --git a/newrelic_api/application_deployments.py b/newrelic_api/application_deployments.py new file mode 100644 index 0000000..f5cd685 --- /dev/null +++ b/newrelic_api/application_deployments.py @@ -0,0 +1,176 @@ +from .base import Resource + + +class ApplicationDeployments(Resource): + """ + An interface for interacting with the New Relic Application Deployments API. + """ + def list(self, application_id, page=None): + """ + This API endpoint returns a paginated list of the deployments associated + with a given application. + + :type application_id: int + :param application_id: Application ID + + :type page: int + :param page: Pagination index + + :rtype: dict + :return: The JSON response of the API, with an additional 'pages' key + if there are paginated results + + :: + + { + "deployment": { + "id": "integer", + "revision": "string", + "changelog": "string", + "description": "string", + "user": "string", + "timestamp": "datetime", + "links": { + "application": "integer" + } + } + } + + """ + + filters = [ + f'page={page}' if page else None + ] + print(filters) + return self._get( + url=f'{self.URL}applications/{application_id}/deployments.json', + headers=self.headers, + params=self.build_param_string(filters) + ) + + def create(self, application_id, revision, changelog=None, description=None, user=None, timestamp=None): + """ + This API endpoint creates a deployment record for a given application. + Deployment records are created with the following attributes: + + Required: + - Application ID + - Revision, such as a git SHA + + Optional: + - Changelog + - Description + - User posting the deployment + - Timestamp of the deployment + + Note that the optional timestamp of the deployment must be provided in + UTC and in ISO8601 format. For example, ‘2019-10-08T00:15:36Z’” If + you have not provided a timestamp, the time of your deployment will + be recorded as the current time in UTC. + + :type revision: str + :param revision: A unique ID for this deployment, visible in the + Overview page and on the Deployments page. Can be any string, + but is usually a version number or a Git checksum, 127 character maximum + + :type changelog: str + :param changelog: A summary of what changed in this deployment, visible + in the Deployments page when you select (selected deployment) + > Change log, 65535 character maximum + + :type description: str + :param description: A high-level description of this deployment, visible + in the Overview page and on the Deployments page when you select an + individual deployment, 65535 character maximum + + :type user: str + :param user: A username to associate with the deployment, visible in + the Overview page and on the Deployments page, 31 character maximum + + :type timestamp: str + :param timestamp: When the deployment occurred, down to the second. + If not specified, the deployment will be recorded at the time + when the API call was received. + + Timestamp requirements: + + Must be in UTC time. + + Must be after the most recent deployment timestamp. + + Cannot be in the future. + + Must be in ISO8601 format; for example, "2019-10-08T00:15:36Z" + + :rtype: dict + :return: The JSON response of the API + + :: + + { + "deployment": { + "id": "integer", + "revision": "string", + "changelog": "string", + "description": "string", + "user": "string", + "timestamp": "datetime", + "links": { + "application": "integer" + } + } + } + + """ + + data = { + "deployment": { + "revision": revision, + "changelog": changelog, + "description": description, + "user": user + } + } + + return self._post( + url=f'{self.URL}applications/{application_id}/deployments.json', + headers=self.headers, + data=data + ) + + def delete(self, application_id, deployment_id=None): + """ + This API endpoint deletes the specified deployment record. + + Note: Admin User’s API Key is required. + + :type application_id: int + :param application_id: Application ID + + :type id: int + :param id: Deployment ID + + :rtype: dict + :return: The JSON response of the API + + :: + + { + "deployment": { + "id": "integer", + "revision": "string", + "changelog": "string", + "description": "string", + "user": "string", + "timestamp": "datetime", + "links": { + "application": "integer" + } + } + } + + """ + return self._delete( + url=f'{self.URL}applications/{application_id}/deployments/{deployment_id}.json', + headers=self.headers + ) diff --git a/newrelic_api/version.py b/newrelic_api/version.py index da2182f..887a342 100644 --- a/newrelic_api/version.py +++ b/newrelic_api/version.py @@ -1 +1 @@ -__version__ = '1.0.6' +__version__ = '1.0.7' From f5f9102ec85ccb53de07f5e76744d8b78d8809d0 Mon Sep 17 00:00:00 2001 From: Karl Keppner Date: Fri, 22 May 2020 23:07:25 -0600 Subject: [PATCH 2/2] tweak docs --- docs/index.rst | 1 + newrelic_api/application_deployments.py | 11 +++-------- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/docs/index.rst b/docs/index.rst index 6c7804c..8adeb4c 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -12,6 +12,7 @@ Currently Supported Resources * Alert Policies (:doc:`API Reference `) * Applications (:doc:`API Reference `) +* Application Deployments (:doc:`API Reference `) * Application Hosts (:doc:`API Reference `) * Application Instances (:doc:`API Reference `) * Browser Applications (:doc:`API Reference `) diff --git a/newrelic_api/application_deployments.py b/newrelic_api/application_deployments.py index f5cd685..631f677 100644 --- a/newrelic_api/application_deployments.py +++ b/newrelic_api/application_deployments.py @@ -91,15 +91,10 @@ def create(self, application_id, revision, changelog=None, description=None, use :param timestamp: When the deployment occurred, down to the second. If not specified, the deployment will be recorded at the time when the API call was received. - Timestamp requirements: - - Must be in UTC time. - - Must be after the most recent deployment timestamp. - - Cannot be in the future. - + Must be in UTC time, + Must be after the most recent deployment timestamp, + Cannot be in the future, Must be in ISO8601 format; for example, "2019-10-08T00:15:36Z" :rtype: dict