Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Application Deployment Support #46

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Currently Supported Resources

* Alert Policies (:doc:`API Reference <ref/alert_policies>`)
* Applications (:doc:`API Reference <ref/applications>`)
* Application Deployments (:doc:`API Reference <ref/application_deployments>`)
* Application Hosts (:doc:`API Reference <ref/application_hosts>`)
* Application Instances (:doc:`API Reference <ref/application_instances>`)
* Browser Applications (:doc:`API Reference <ref/browser_applications>`)
Expand Down
14 changes: 14 additions & 0 deletions docs/ref/application_deployments.rst
Original file line number Diff line number Diff line change
@@ -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__
6 changes: 6 additions & 0 deletions docs/release_notes.rst
Original file line number Diff line number Diff line change
@@ -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
------

Expand Down
1 change: 1 addition & 0 deletions docs/toc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
171 changes: 171 additions & 0 deletions newrelic_api/application_deployments.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
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
)
2 changes: 1 addition & 1 deletion newrelic_api/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.0.6'
__version__ = '1.0.7'