mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-04-24 04:39:15 +00:00
Reformat everything.
This commit is contained in:
parent
3f2213791a
commit
340ff8586d
1008 changed files with 61301 additions and 58309 deletions
|
|
@ -99,19 +99,20 @@ from ansible.module_utils.basic import AnsibleModule
|
|||
|
||||
|
||||
class AlertaInterface:
|
||||
|
||||
def __init__(self, module):
|
||||
self.module = module
|
||||
self.state = module.params['state']
|
||||
self.customer = module.params['customer']
|
||||
self.match = module.params['match']
|
||||
self.alerta_url = module.params['alerta_url']
|
||||
self.state = module.params["state"]
|
||||
self.customer = module.params["customer"]
|
||||
self.match = module.params["match"]
|
||||
self.alerta_url = module.params["alerta_url"]
|
||||
self.headers = {"Content-Type": "application/json"}
|
||||
|
||||
if module.params.get('api_key', None):
|
||||
if module.params.get("api_key", None):
|
||||
self.headers["Authorization"] = f"Key {module.params['api_key']}"
|
||||
else:
|
||||
self.headers["Authorization"] = basic_auth_header(module.params['api_username'], module.params['api_password'])
|
||||
self.headers["Authorization"] = basic_auth_header(
|
||||
module.params["api_username"], module.params["api_password"]
|
||||
)
|
||||
|
||||
def send_request(self, url, data=None, method="GET"):
|
||||
response, info = fetch_url(self.module, url, data=data, headers=self.headers, method=method)
|
||||
|
|
@ -142,46 +143,46 @@ class AlertaInterface:
|
|||
url = f"{self.alerta_url}/api/customer"
|
||||
|
||||
payload = {
|
||||
'customer': self.customer,
|
||||
'match': self.match,
|
||||
"customer": self.customer,
|
||||
"match": self.match,
|
||||
}
|
||||
|
||||
payload = self.module.jsonify(payload)
|
||||
response = self.send_request(url, payload, 'POST')
|
||||
response = self.send_request(url, payload, "POST")
|
||||
return response
|
||||
|
||||
def delete_customer(self, id):
|
||||
url = f"{self.alerta_url}/api/customer/{id}"
|
||||
|
||||
response = self.send_request(url, None, 'DELETE')
|
||||
response = self.send_request(url, None, "DELETE")
|
||||
return response
|
||||
|
||||
def find_customer_id(self, customer):
|
||||
for i in customer['customers']:
|
||||
if self.customer == i['customer'] and self.match == i['match']:
|
||||
return i['id']
|
||||
for i in customer["customers"]:
|
||||
if self.customer == i["customer"] and self.match == i["match"]:
|
||||
return i["id"]
|
||||
return None
|
||||
|
||||
|
||||
def main():
|
||||
module = AnsibleModule(
|
||||
argument_spec=dict(
|
||||
state=dict(choices=['present', 'absent'], default='present'),
|
||||
customer=dict(type='str', required=True),
|
||||
match=dict(type='str', required=True),
|
||||
alerta_url=dict(type='str', required=True),
|
||||
api_username=dict(type='str'),
|
||||
api_password=dict(type='str', no_log=True),
|
||||
api_key=dict(type='str', no_log=True),
|
||||
state=dict(choices=["present", "absent"], default="present"),
|
||||
customer=dict(type="str", required=True),
|
||||
match=dict(type="str", required=True),
|
||||
alerta_url=dict(type="str", required=True),
|
||||
api_username=dict(type="str"),
|
||||
api_password=dict(type="str", no_log=True),
|
||||
api_key=dict(type="str", no_log=True),
|
||||
),
|
||||
required_together=[['api_username', 'api_password']],
|
||||
mutually_exclusive=[['api_username', 'api_key']],
|
||||
supports_check_mode=True
|
||||
required_together=[["api_username", "api_password"]],
|
||||
mutually_exclusive=[["api_username", "api_key"]],
|
||||
supports_check_mode=True,
|
||||
)
|
||||
|
||||
alerta_iface = AlertaInterface(module)
|
||||
|
||||
if alerta_iface.state == 'present':
|
||||
if alerta_iface.state == "present":
|
||||
response = alerta_iface.get_customers()
|
||||
if alerta_iface.find_customer_id(response):
|
||||
module.exit_json(changed=False, response=response, msg=f"Customer {alerta_iface.customer} already exists")
|
||||
|
|
@ -195,7 +196,9 @@ def main():
|
|||
if id:
|
||||
if not module.check_mode:
|
||||
alerta_iface.delete_customer(id)
|
||||
module.exit_json(changed=True, response=response, msg=f"Customer {alerta_iface.customer} with id {id} deleted")
|
||||
module.exit_json(
|
||||
changed=True, response=response, msg=f"Customer {alerta_iface.customer} with id {id} deleted"
|
||||
)
|
||||
else:
|
||||
module.exit_json(changed=False, response=response, msg=f"Customer {alerta_iface.customer} does not exists")
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue