1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2026-04-15 08:21:31 +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

@ -134,46 +134,45 @@ except ImportError:
def get_token(name, nomad_client):
tokens = nomad_client.acl.get_tokens()
token = next((token for token in tokens
if token.get('Name') == name), None)
token = next((token for token in tokens if token.get("Name") == name), None)
return token
def transform_response(nomad_response):
transformed_response = {
"accessor_id": nomad_response['AccessorID'],
"create_index": nomad_response['CreateIndex'],
"create_time": nomad_response['CreateTime'],
"expiration_ttl": nomad_response['ExpirationTTL'],
"expiration_time": nomad_response['ExpirationTime'],
"global": nomad_response['Global'],
"hash": nomad_response['Hash'],
"modify_index": nomad_response['ModifyIndex'],
"name": nomad_response['Name'],
"policies": nomad_response['Policies'],
"roles": nomad_response['Roles'],
"secret_id": nomad_response['SecretID'],
"type": nomad_response['Type']
"accessor_id": nomad_response["AccessorID"],
"create_index": nomad_response["CreateIndex"],
"create_time": nomad_response["CreateTime"],
"expiration_ttl": nomad_response["ExpirationTTL"],
"expiration_time": nomad_response["ExpirationTime"],
"global": nomad_response["Global"],
"hash": nomad_response["Hash"],
"modify_index": nomad_response["ModifyIndex"],
"name": nomad_response["Name"],
"policies": nomad_response["Policies"],
"roles": nomad_response["Roles"],
"secret_id": nomad_response["SecretID"],
"type": nomad_response["Type"],
}
return transformed_response
argument_spec = dict(
host=dict(required=True, type='str'),
port=dict(type='int', default=4646),
state=dict(required=True, choices=['present', 'absent']),
use_ssl=dict(type='bool', default=True),
timeout=dict(type='int', default=5),
validate_certs=dict(type='bool', default=True),
client_cert=dict(type='path'),
client_key=dict(type='path'),
namespace=dict(type='str'),
token=dict(type='str', no_log=True),
name=dict(type='str'),
token_type=dict(choices=['client', 'management', 'bootstrap'], default='client'),
policies=dict(type='list', elements='str', default=[]),
global_replicated=dict(type='bool', default=False),
host=dict(required=True, type="str"),
port=dict(type="int", default=4646),
state=dict(required=True, choices=["present", "absent"]),
use_ssl=dict(type="bool", default=True),
timeout=dict(type="int", default=5),
validate_certs=dict(type="bool", default=True),
client_cert=dict(type="path"),
client_key=dict(type="path"),
namespace=dict(type="str"),
token=dict(type="str", no_log=True),
name=dict(type="str"),
token_type=dict(choices=["client", "management", "bootstrap"], default="client"),
policies=dict(type="list", elements="str", default=[]),
global_replicated=dict(type="bool", default=False),
)
@ -181,12 +180,10 @@ def setup_module_object():
module = AnsibleModule(
argument_spec=argument_spec,
supports_check_mode=False,
required_one_of=[
['name', 'token_type']
],
required_one_of=[["name", "token_type"]],
required_if=[
('token_type', 'client', ('name',)),
('token_type', 'management', ('name',)),
("token_type", "client", ("name",)),
("token_type", "management", ("name",)),
],
)
return module
@ -196,17 +193,17 @@ def setup_nomad_client(module):
if not import_nomad:
module.fail_json(msg=missing_required_lib("python-nomad"))
certificate_ssl = (module.params.get('client_cert'), module.params.get('client_key'))
certificate_ssl = (module.params.get("client_cert"), module.params.get("client_key"))
nomad_client = nomad.Nomad(
host=module.params.get('host'),
port=module.params.get('port'),
secure=module.params.get('use_ssl'),
timeout=module.params.get('timeout'),
verify=module.params.get('validate_certs'),
host=module.params.get("host"),
port=module.params.get("port"),
secure=module.params.get("use_ssl"),
timeout=module.params.get("timeout"),
verify=module.params.get("validate_certs"),
cert=certificate_ssl,
namespace=module.params.get('namespace'),
token=module.params.get('token')
namespace=module.params.get("namespace"),
token=module.params.get("token"),
)
return nomad_client
@ -218,11 +215,10 @@ def run(module):
msg = ""
result = {}
changed = False
if module.params.get('state') == "present":
if module.params.get('token_type') == 'bootstrap':
if module.params.get("state") == "present":
if module.params.get("token_type") == "bootstrap":
try:
current_token = get_token('Bootstrap Token', nomad_client)
current_token = get_token("Bootstrap Token", nomad_client)
if current_token:
msg = "ACL bootstrap already exist."
else:
@ -243,17 +239,17 @@ def run(module):
else:
try:
token_info = {
"Name": module.params.get('name'),
"Type": module.params.get('token_type'),
"Policies": module.params.get('policies'),
"Global": module.params.get('global_replicated')
"Name": module.params.get("name"),
"Type": module.params.get("token_type"),
"Policies": module.params.get("policies"),
"Global": module.params.get("global_replicated"),
}
current_token = get_token(token_info['Name'], nomad_client)
current_token = get_token(token_info["Name"], nomad_client)
if current_token:
token_info['AccessorID'] = current_token['AccessorID']
nomad_result = nomad_client.acl.update_token(current_token['AccessorID'], token_info)
token_info["AccessorID"] = current_token["AccessorID"]
nomad_result = nomad_client.acl.update_token(current_token["AccessorID"], token_info)
msg = "ACL token updated."
result = transform_response(nomad_result)
changed = True
@ -267,19 +263,18 @@ def run(module):
except Exception as e:
module.fail_json(msg=to_native(e))
if module.params.get('state') == "absent":
if not module.params.get('name'):
if module.params.get("state") == "absent":
if not module.params.get("name"):
module.fail_json(msg="name is needed to delete token.")
if module.params.get('token_type') == 'bootstrap' or module.params.get('name') == 'Bootstrap Token':
if module.params.get("token_type") == "bootstrap" or module.params.get("name") == "Bootstrap Token":
module.fail_json(msg="Delete ACL bootstrap token is not allowed.")
try:
token = get_token(module.params.get('name'), nomad_client)
token = get_token(module.params.get("name"), nomad_client)
if token:
nomad_client.acl.delete_token(token.get('AccessorID'))
msg = 'ACL token deleted.'
nomad_client.acl.delete_token(token.get("AccessorID"))
msg = "ACL token deleted."
changed = True
else:
msg = f"No token with name '{module.params['name']}' found"