1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Use api v4 for airbrake deploy notices (#124)

* Use api v4 for airbrake deploy notices

* fix invalid deprecated version

changes 2.14 to 2.12

* revert

* ignore it
This commit is contained in:
Patrick Humpal 2020-05-17 00:42:08 -07:00 committed by GitHub
parent a7c830f49d
commit 196d3205ca
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 96 additions and 35 deletions

View file

@ -0,0 +1,8 @@
bugfixes:
- "airbrake_deployment - Allow deploy notifications for Airbrake compatible v2 api (e.g. Errbit)"
minor_changes:
- "airbrake_deployment - Allow passing ``project_id`` and ``project_key`` for v4 api deploy compatibility"
deprecated_features:
- "airbrake_deployment - Add deprecation notice for ``token`` parameter and v2 api deploys. This feature will be removed in Ansible 2.14"

View file

@ -11,36 +11,50 @@ __metaclass__ = type
DOCUMENTATION = ''' DOCUMENTATION = '''
--- ---
module: airbrake_deployment module: airbrake_deployment
author: "Bruce Pennypacker (@bpennypacker)" author:
- "Bruce Pennypacker (@bpennypacker)"
- "Patrick Humpal (@phumpal)"
short_description: Notify airbrake about app deployments short_description: Notify airbrake about app deployments
description: description:
- Notify airbrake about app deployments (see http://help.airbrake.io/kb/api-2/deploy-tracking) - Notify airbrake about app deployments (see U(https://airbrake.io/docs/api/#deploys-v4)).
- Parameter I(token) is deprecated in Ansible 2.10. Please remove entry.
options: options:
token: project_id:
description: description:
- API token. - Airbrake PROJECT_ID
required: true required: false
type: str
project_key:
description:
- Airbrake PROJECT_KEY.
required: false
type: str
environment: environment:
description: description:
- The airbrake environment name, typically 'production', 'staging', etc. - The airbrake environment name, typically 'production', 'staging', etc.
required: true required: true
type: str
user: user:
description: description:
- The username of the person doing the deployment - The username of the person doing the deployment
required: false required: false
type: str
repo: repo:
description: description:
- URL of the project repository - URL of the project repository
required: false required: false
type: str
revision: revision:
description: description:
- A hash, number, tag, or other identifier showing what revision was deployed - A hash, number, tag, or other identifier showing what revision was deployed
required: false required: false
type: str
url: url:
description: description:
- Optional URL to submit the notification to. Use to send notifications to Airbrake-compliant tools like Errbit. - Optional URL to submit the notification to. Use to send notifications to Airbrake-compliant tools like Errbit.
required: false required: false
default: "https://airbrake.io/deploys.txt" default: "https://api.airbrake.io/api/v4/projects/"
type: str
validate_certs: validate_certs:
description: description:
- If C(no), SSL certificates for the target url will not be validated. This should only be used - If C(no), SSL certificates for the target url will not be validated. This should only be used
@ -48,6 +62,11 @@ options:
required: false required: false
default: 'yes' default: 'yes'
type: bool type: bool
token:
description:
- This parameter (API token) has been deprecated in Ansible 2.10. Please remove it from your tasks.
required: false
type: str
requirements: [] requirements: []
''' '''
@ -55,7 +74,8 @@ requirements: []
EXAMPLES = ''' EXAMPLES = '''
- name: Notify airbrake about an app deployment - name: Notify airbrake about an app deployment
airbrake_deployment: airbrake_deployment:
token: AAAAAA project_id: '12345'
project_key: 'AAAAAA'
environment: staging environment: staging
user: ansible user: ansible
revision: '4.2' revision: '4.2'
@ -74,20 +94,29 @@ def main():
module = AnsibleModule( module = AnsibleModule(
argument_spec=dict( argument_spec=dict(
token=dict(required=True, no_log=True), token=dict(required=False, no_log=True),
project_id=dict(required=False, no_log=True),
project_key=dict(required=False, no_log=True),
environment=dict(required=True), environment=dict(required=True),
user=dict(required=False), user=dict(required=False),
repo=dict(required=False), repo=dict(required=False),
revision=dict(required=False), revision=dict(required=False),
url=dict(required=False, default='https://api.airbrake.io/deploys.txt'), url=dict(required=False, default='https://api.airbrake.io/api/v4/projects/'),
validate_certs=dict(default='yes', type='bool'), validate_certs=dict(default='yes', type='bool'),
), ),
supports_check_mode=True supports_check_mode=True,
required_together=[('project_id', 'project_key')],
mutually_exclusive=[('project_id', 'token')],
) )
# build list of params # Build list of params
params = {} params = {}
# If we're in check mode, just exit pretending like we succeeded
if module.check_mode:
module.exit_json(changed=True)
if module.params["token"]:
if module.params["environment"]: if module.params["environment"]:
params["deploy[rails_env]"] = module.params["environment"] params["deploy[rails_env]"] = module.params["environment"]
@ -100,18 +129,45 @@ def main():
if module.params["revision"]: if module.params["revision"]:
params["deploy[scm_revision]"] = module.params["revision"] params["deploy[scm_revision]"] = module.params["revision"]
module.deprecate("Parameter 'token' is deprecated in 2.10. Please remove it and use 'project_id' and 'project_key' instead", version='2.14')
params["api_key"] = module.params["token"] params["api_key"] = module.params["token"]
url = module.params.get('url') # Allow sending to Airbrake compliant v2 APIs
if module.params["url"] == 'https://api.airbrake.io/api/v4/projects/':
# If we're in check mode, just exit pretending like we succeeded url = 'https://api.airbrake.io/deploys.txt'
if module.check_mode: else:
module.exit_json(changed=True) url = module.params["url"]
# Send the data to airbrake # Send the data to airbrake
data = urlencode(params) data = urlencode(params)
response, info = fetch_url(module, url, data=data) response, info = fetch_url(module, url, data=data)
if info['status'] == 200:
if module.params["project_id"] and module.params["project_key"]:
if module.params["environment"]:
params["environment"] = module.params["environment"]
if module.params["user"]:
params["username"] = module.params["user"]
if module.params["repo"]:
params["repository"] = module.params["repo"]
if module.params["revision"]:
params["revision"] = module.params["revision"]
# Build deploy url
url = module.params.get('url') + module.params["project_id"] + '/deploys?key=' + module.params["project_key"]
json_body = module.jsonify(params)
# Build header
headers = {'Content-Type': 'application/json'}
# Notify Airbrake of deploy
response, info = fetch_url(module, url, data=json_body,
headers=headers, method='POST')
if info['status'] == 200 or info['status'] == 201:
module.exit_json(changed=True) module.exit_json(changed=True)
else: else:
module.fail_json(msg="HTTP result code: %d connecting to %s" % (info['status'], url)) module.fail_json(msg="HTTP result code: %d connecting to %s" % (info['status'], url))

View file

@ -998,8 +998,7 @@ plugins/modules/identity/onepassword_info.py pylint:collection-invalid-deprecate
plugins/modules/identity/onepassword_info.py validate-modules:parameter-list-no-elements plugins/modules/identity/onepassword_info.py validate-modules:parameter-list-no-elements
plugins/modules/identity/opendj/opendj_backendprop.py validate-modules:doc-missing-type plugins/modules/identity/opendj/opendj_backendprop.py validate-modules:doc-missing-type
plugins/modules/identity/opendj/opendj_backendprop.py validate-modules:parameter-type-not-in-doc plugins/modules/identity/opendj/opendj_backendprop.py validate-modules:parameter-type-not-in-doc
plugins/modules/monitoring/airbrake_deployment.py validate-modules:doc-default-does-not-match-spec plugins/modules/monitoring/airbrake_deployment.py pylint:collection-invalid-deprecated-version
plugins/modules/monitoring/airbrake_deployment.py validate-modules:doc-missing-type
plugins/modules/monitoring/bigpanda.py validate-modules:collection-invalid-version plugins/modules/monitoring/bigpanda.py validate-modules:collection-invalid-version
plugins/modules/monitoring/bigpanda.py validate-modules:doc-default-does-not-match-spec plugins/modules/monitoring/bigpanda.py validate-modules:doc-default-does-not-match-spec
plugins/modules/monitoring/bigpanda.py validate-modules:doc-missing-type plugins/modules/monitoring/bigpanda.py validate-modules:doc-missing-type

View file

@ -699,8 +699,6 @@ plugins/modules/identity/keycloak/keycloak_clienttemplate.py validate-modules:do
plugins/modules/identity/keycloak/keycloak_clienttemplate.py validate-modules:parameter-type-not-in-doc plugins/modules/identity/keycloak/keycloak_clienttemplate.py validate-modules:parameter-type-not-in-doc
plugins/modules/identity/opendj/opendj_backendprop.py validate-modules:doc-missing-type plugins/modules/identity/opendj/opendj_backendprop.py validate-modules:doc-missing-type
plugins/modules/identity/opendj/opendj_backendprop.py validate-modules:parameter-type-not-in-doc plugins/modules/identity/opendj/opendj_backendprop.py validate-modules:parameter-type-not-in-doc
plugins/modules/monitoring/airbrake_deployment.py validate-modules:doc-default-does-not-match-spec
plugins/modules/monitoring/airbrake_deployment.py validate-modules:doc-missing-type
plugins/modules/monitoring/bigpanda.py validate-modules:doc-default-does-not-match-spec plugins/modules/monitoring/bigpanda.py validate-modules:doc-default-does-not-match-spec
plugins/modules/monitoring/bigpanda.py validate-modules:doc-missing-type plugins/modules/monitoring/bigpanda.py validate-modules:doc-missing-type
plugins/modules/monitoring/bigpanda.py validate-modules:undocumented-parameter plugins/modules/monitoring/bigpanda.py validate-modules:undocumented-parameter