1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2026-04-22 19:59:07 +00:00

Reformat everything.

This commit is contained in:
Felix Fontein 2025-11-01 12:08:41 +01:00
parent 3f2213791a
commit 340ff8586d
1008 changed files with 61301 additions and 58309 deletions

View file

@ -112,24 +112,24 @@ from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.urls import fetch_url
def post_twilio_api(module, account_sid, auth_token, msg, from_number,
to_number, media_url=None):
def post_twilio_api(module, account_sid, auth_token, msg, from_number, to_number, media_url=None):
URI = f"https://api.twilio.com/2010-04-01/Accounts/{account_sid}/Messages.json"
AGENT = "Ansible"
data = {'From': from_number, 'To': to_number, 'Body': msg}
data = {"From": from_number, "To": to_number, "Body": msg}
if media_url:
data['MediaUrl'] = media_url
data["MediaUrl"] = media_url
encoded_data = urlencode(data)
headers = {'User-Agent': AGENT,
'Content-type': 'application/x-www-form-urlencoded',
'Accept': 'application/json',
}
headers = {
"User-Agent": AGENT,
"Content-type": "application/x-www-form-urlencoded",
"Accept": "application/json",
}
# Hack module params to have the Basic auth params that fetch_url expects
module.params['url_username'] = account_sid.replace('\n', '')
module.params['url_password'] = auth_token.replace('\n', '')
module.params["url_username"] = account_sid.replace("\n", "")
module.params["url_password"] = auth_token.replace("\n", "")
return fetch_url(module, URI, data=encoded_data, headers=headers)
@ -138,39 +138,38 @@ def post_twilio_api(module, account_sid, auth_token, msg, from_number,
# Main
#
def main():
def main():
module = AnsibleModule(
argument_spec=dict(
account_sid=dict(required=True),
auth_token=dict(required=True, no_log=True),
msg=dict(required=True),
from_number=dict(required=True),
to_numbers=dict(required=True, aliases=['to_number'], type='list', elements='str'),
to_numbers=dict(required=True, aliases=["to_number"], type="list", elements="str"),
media_url=dict(),
),
supports_check_mode=True
supports_check_mode=True,
)
account_sid = module.params['account_sid']
auth_token = module.params['auth_token']
msg = module.params['msg']
from_number = module.params['from_number']
to_numbers = module.params['to_numbers']
media_url = module.params['media_url']
account_sid = module.params["account_sid"]
auth_token = module.params["auth_token"]
msg = module.params["msg"]
from_number = module.params["from_number"]
to_numbers = module.params["to_numbers"]
media_url = module.params["media_url"]
for number in to_numbers:
r, info = post_twilio_api(module, account_sid, auth_token, msg,
from_number, number, media_url)
if info['status'] not in [200, 201]:
r, info = post_twilio_api(module, account_sid, auth_token, msg, from_number, number, media_url)
if info["status"] not in [200, 201]:
body_message = "unknown error"
if 'body' in info:
body = module.from_json(info['body'])
body_message = body['message']
if "body" in info:
body = module.from_json(info["body"])
body_message = body["message"]
module.fail_json(msg=f"unable to send message to {number}: {body_message}")
module.exit_json(msg=msg, changed=False)
if __name__ == '__main__':
if __name__ == "__main__":
main()