mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-04-12 06:55:05 +00:00
Reformat everything.
This commit is contained in:
parent
3f2213791a
commit
340ff8586d
1008 changed files with 61301 additions and 58309 deletions
|
|
@ -22,6 +22,7 @@ from ansible_collections.community.general.plugins.module_utils.datetime import
|
|||
SCALEWAY_SECRET_IMP_ERR: str | None = None
|
||||
try:
|
||||
from passlib.hash import argon2
|
||||
|
||||
HAS_SCALEWAY_SECRET_PACKAGE = True
|
||||
except Exception:
|
||||
SCALEWAY_SECRET_IMP_ERR = traceback.format_exc()
|
||||
|
|
@ -30,12 +31,18 @@ except Exception:
|
|||
|
||||
def scaleway_argument_spec():
|
||||
return dict(
|
||||
api_token=dict(required=True, fallback=(env_fallback, ['SCW_TOKEN', 'SCW_API_KEY', 'SCW_OAUTH_TOKEN', 'SCW_API_TOKEN']),
|
||||
no_log=True, aliases=['oauth_token']),
|
||||
api_url=dict(fallback=(env_fallback, ['SCW_API_URL']), default='https://api.scaleway.com', aliases=['base_url']),
|
||||
api_timeout=dict(type='int', default=30, aliases=['timeout']),
|
||||
query_parameters=dict(type='dict', default={}),
|
||||
validate_certs=dict(default=True, type='bool'),
|
||||
api_token=dict(
|
||||
required=True,
|
||||
fallback=(env_fallback, ["SCW_TOKEN", "SCW_API_KEY", "SCW_OAUTH_TOKEN", "SCW_API_TOKEN"]),
|
||||
no_log=True,
|
||||
aliases=["oauth_token"],
|
||||
),
|
||||
api_url=dict(
|
||||
fallback=(env_fallback, ["SCW_API_URL"]), default="https://api.scaleway.com", aliases=["base_url"]
|
||||
),
|
||||
api_timeout=dict(type="int", default=30, aliases=["timeout"]),
|
||||
query_parameters=dict(type="dict", default={}),
|
||||
validate_certs=dict(default=True, type="bool"),
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -48,47 +55,42 @@ def scaleway_waitable_resource_argument_spec():
|
|||
|
||||
|
||||
def payload_from_object(scw_object):
|
||||
return {
|
||||
k: v
|
||||
for k, v in scw_object.items()
|
||||
if k != 'id' and v is not None
|
||||
}
|
||||
return {k: v for k, v in scw_object.items() if k != "id" and v is not None}
|
||||
|
||||
|
||||
class ScalewayException(Exception):
|
||||
|
||||
def __init__(self, message):
|
||||
self.message = message
|
||||
|
||||
|
||||
# Specify a complete Link header, for validation purposes
|
||||
R_LINK_HEADER = r'''<[^>]+>;\srel="(first|previous|next|last)"
|
||||
(,<[^>]+>;\srel="(first|previous|next|last)")*'''
|
||||
R_LINK_HEADER = r"""<[^>]+>;\srel="(first|previous|next|last)"
|
||||
(,<[^>]+>;\srel="(first|previous|next|last)")*"""
|
||||
# Specify a single relation, for iteration and string extraction purposes
|
||||
R_RELATION = r'</?(?P<target_IRI>[^>]+)>; rel="(?P<relation>first|previous|next|last)"'
|
||||
|
||||
|
||||
def parse_pagination_link(header):
|
||||
if not re.match(R_LINK_HEADER, header, re.VERBOSE):
|
||||
raise ScalewayException('Scaleway API answered with an invalid Link pagination header')
|
||||
raise ScalewayException("Scaleway API answered with an invalid Link pagination header")
|
||||
else:
|
||||
relations = header.split(',')
|
||||
relations = header.split(",")
|
||||
parsed_relations = {}
|
||||
rc_relation = re.compile(R_RELATION)
|
||||
for relation in relations:
|
||||
match = rc_relation.match(relation)
|
||||
if not match:
|
||||
raise ScalewayException('Scaleway API answered with an invalid relation in the Link pagination header')
|
||||
raise ScalewayException("Scaleway API answered with an invalid relation in the Link pagination header")
|
||||
data = match.groupdict()
|
||||
parsed_relations[data['relation']] = data['target_IRI']
|
||||
parsed_relations[data["relation"]] = data["target_IRI"]
|
||||
return parsed_relations
|
||||
|
||||
|
||||
def filter_sensitive_attributes(container, attributes):
|
||||
'''
|
||||
"""
|
||||
WARNING: This function is effectively private, **do not use it**!
|
||||
It will be removed or renamed once changing its name no longer triggers a pylint bug.
|
||||
'''
|
||||
"""
|
||||
for attr in attributes:
|
||||
container[attr] = "SENSITIVE_VALUE"
|
||||
|
||||
|
|
@ -100,8 +102,8 @@ class SecretVariables:
|
|||
def ensure_scaleway_secret_package(module):
|
||||
if not HAS_SCALEWAY_SECRET_PACKAGE:
|
||||
module.fail_json(
|
||||
msg=missing_required_lib("passlib[argon2]", url='https://passlib.readthedocs.io/en/stable/'),
|
||||
exception=SCALEWAY_SECRET_IMP_ERR
|
||||
msg=missing_required_lib("passlib[argon2]", url="https://passlib.readthedocs.io/en/stable/"),
|
||||
exception=SCALEWAY_SECRET_IMP_ERR,
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
|
|
@ -110,8 +112,8 @@ class SecretVariables:
|
|||
|
||||
@staticmethod
|
||||
def list_to_dict(source_list, hashed=False):
|
||||
key_value = 'hashed_value' if hashed else 'value'
|
||||
return {var['key']: var[key_value] for var in source_list}
|
||||
key_value = "hashed_value" if hashed else "value"
|
||||
return {var["key"]: var[key_value] for var in source_list}
|
||||
|
||||
@classmethod
|
||||
def decode(cls, secrets_list, values_list):
|
||||
|
|
@ -140,7 +142,6 @@ def resource_attributes_should_be_changed(target, wished, verifiable_mutable_att
|
|||
|
||||
|
||||
class Response:
|
||||
|
||||
def __init__(self, resp, info):
|
||||
self.body = None
|
||||
if resp:
|
||||
|
|
@ -168,32 +169,32 @@ class Response:
|
|||
|
||||
|
||||
class Scaleway:
|
||||
|
||||
def __init__(self, module):
|
||||
self.module = module
|
||||
self.headers = {
|
||||
'X-Auth-Token': self.module.params.get('api_token'),
|
||||
'User-Agent': self.get_user_agent_string(module),
|
||||
'Content-Type': 'application/json',
|
||||
"X-Auth-Token": self.module.params.get("api_token"),
|
||||
"User-Agent": self.get_user_agent_string(module),
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
self.name = None
|
||||
|
||||
def get_resources(self):
|
||||
results = self.get(f'/{self.name}')
|
||||
results = self.get(f"/{self.name}")
|
||||
|
||||
if not results.ok:
|
||||
raise ScalewayException(
|
||||
f"Error fetching {self.name} ({self.module.params.get('api_url')}/{self.name}) [{results.status_code}: {results.json['message']}]")
|
||||
f"Error fetching {self.name} ({self.module.params.get('api_url')}/{self.name}) [{results.status_code}: {results.json['message']}]"
|
||||
)
|
||||
|
||||
return results.json.get(self.name)
|
||||
|
||||
def _url_builder(self, path, params):
|
||||
d = self.module.params.get('query_parameters')
|
||||
d = self.module.params.get("query_parameters")
|
||||
if params is not None:
|
||||
d.update(params)
|
||||
query_string = urlencode(d, doseq=True)
|
||||
|
||||
if path[0] == '/':
|
||||
if path[0] == "/":
|
||||
path = path[1:]
|
||||
return f"{self.module.params.get('api_url')}/{path}?{query_string}"
|
||||
|
||||
|
|
@ -204,17 +205,21 @@ class Scaleway:
|
|||
if headers is not None:
|
||||
self.headers.update(headers)
|
||||
|
||||
if self.headers['Content-Type'] == "application/json":
|
||||
if self.headers["Content-Type"] == "application/json":
|
||||
data = self.module.jsonify(data)
|
||||
|
||||
resp, info = fetch_url(
|
||||
self.module, url, data=data, headers=self.headers, method=method,
|
||||
timeout=self.module.params.get('api_timeout')
|
||||
self.module,
|
||||
url,
|
||||
data=data,
|
||||
headers=self.headers,
|
||||
method=method,
|
||||
timeout=self.module.params.get("api_timeout"),
|
||||
)
|
||||
|
||||
# Exceptions in fetch_url may result in a status -1, the ensures a proper error to the user in all cases
|
||||
if info['status'] == -1:
|
||||
self.module.fail_json(msg=info['msg'])
|
||||
if info["status"] == -1:
|
||||
self.module.fail_json(msg=info["msg"])
|
||||
|
||||
return Response(resp, info)
|
||||
|
||||
|
|
@ -223,16 +228,16 @@ class Scaleway:
|
|||
return f"ansible {module.ansible_version} Python {sys.version.split(' ', 1)[0]}"
|
||||
|
||||
def get(self, path, data=None, headers=None, params=None):
|
||||
return self.send(method='GET', path=path, data=data, headers=headers, params=params)
|
||||
return self.send(method="GET", path=path, data=data, headers=headers, params=params)
|
||||
|
||||
def put(self, path, data=None, headers=None, params=None):
|
||||
return self.send(method='PUT', path=path, data=data, headers=headers, params=params)
|
||||
return self.send(method="PUT", path=path, data=data, headers=headers, params=params)
|
||||
|
||||
def post(self, path, data=None, headers=None, params=None):
|
||||
return self.send(method='POST', path=path, data=data, headers=headers, params=params)
|
||||
return self.send(method="POST", path=path, data=data, headers=headers, params=params)
|
||||
|
||||
def delete(self, path, data=None, headers=None, params=None):
|
||||
return self.send(method='DELETE', path=path, data=data, headers=headers, params=params)
|
||||
return self.send(method="DELETE", path=path, data=data, headers=headers, params=params)
|
||||
|
||||
def patch(self, path, data=None, headers=None, params=None):
|
||||
return self.send(method="PATCH", path=path, data=data, headers=headers, params=params)
|
||||
|
|
@ -251,7 +256,7 @@ class Scaleway:
|
|||
return "absent"
|
||||
|
||||
if not response.ok:
|
||||
msg = f'Error during state fetching: ({response.status_code}) {response.json}'
|
||||
msg = f"Error during state fetching: ({response.status_code}) {response.json}"
|
||||
self.module.fail_json(msg=msg)
|
||||
|
||||
try:
|
||||
|
|
@ -261,13 +266,13 @@ class Scaleway:
|
|||
self.module.fail_json(msg=f"Could not fetch state in {response.json}")
|
||||
|
||||
def fetch_paginated_resources(self, resource_key, **pagination_kwargs):
|
||||
response = self.get(
|
||||
path=self.api_path,
|
||||
params=pagination_kwargs)
|
||||
response = self.get(path=self.api_path, params=pagination_kwargs)
|
||||
|
||||
status_code = response.status_code
|
||||
if not response.ok:
|
||||
self.module.fail_json(msg=f"Error getting {resource_key} [{response.status_code}: {response.json['message']}]")
|
||||
self.module.fail_json(
|
||||
msg=f"Error getting {resource_key} [{response.status_code}: {response.json['message']}]"
|
||||
)
|
||||
|
||||
return response.json[resource_key]
|
||||
|
||||
|
|
@ -278,10 +283,10 @@ class Scaleway:
|
|||
while len(result) != 0:
|
||||
result = self.fetch_paginated_resources(resource_key, **pagination_kwargs)
|
||||
resources += result
|
||||
if 'page' in pagination_kwargs:
|
||||
pagination_kwargs['page'] += 1
|
||||
if "page" in pagination_kwargs:
|
||||
pagination_kwargs["page"] += 1
|
||||
else:
|
||||
pagination_kwargs['page'] = 2
|
||||
pagination_kwargs["page"] = 2
|
||||
|
||||
return resources
|
||||
|
||||
|
|
@ -315,95 +320,83 @@ class Scaleway:
|
|||
|
||||
|
||||
SCALEWAY_LOCATION = {
|
||||
'par1': {
|
||||
'name': 'Paris 1',
|
||||
'country': 'FR',
|
||||
'api_endpoint': 'https://api.scaleway.com/instance/v1/zones/fr-par-1',
|
||||
'api_endpoint_vpc': 'https://api.scaleway.com/vpc/v1/zones/fr-par-1'
|
||||
"par1": {
|
||||
"name": "Paris 1",
|
||||
"country": "FR",
|
||||
"api_endpoint": "https://api.scaleway.com/instance/v1/zones/fr-par-1",
|
||||
"api_endpoint_vpc": "https://api.scaleway.com/vpc/v1/zones/fr-par-1",
|
||||
},
|
||||
|
||||
'EMEA-FR-PAR1': {
|
||||
'name': 'Paris 1',
|
||||
'country': 'FR',
|
||||
'api_endpoint': 'https://api.scaleway.com/instance/v1/zones/fr-par-1',
|
||||
'api_endpoint_vpc': 'https://api.scaleway.com/vpc/v1/zones/fr-par-1'
|
||||
"EMEA-FR-PAR1": {
|
||||
"name": "Paris 1",
|
||||
"country": "FR",
|
||||
"api_endpoint": "https://api.scaleway.com/instance/v1/zones/fr-par-1",
|
||||
"api_endpoint_vpc": "https://api.scaleway.com/vpc/v1/zones/fr-par-1",
|
||||
},
|
||||
|
||||
'par2': {
|
||||
'name': 'Paris 2',
|
||||
'country': 'FR',
|
||||
'api_endpoint': 'https://api.scaleway.com/instance/v1/zones/fr-par-2',
|
||||
'api_endpoint_vpc': 'https://api.scaleway.com/vpc/v1/zones/fr-par-2'
|
||||
"par2": {
|
||||
"name": "Paris 2",
|
||||
"country": "FR",
|
||||
"api_endpoint": "https://api.scaleway.com/instance/v1/zones/fr-par-2",
|
||||
"api_endpoint_vpc": "https://api.scaleway.com/vpc/v1/zones/fr-par-2",
|
||||
},
|
||||
|
||||
'EMEA-FR-PAR2': {
|
||||
'name': 'Paris 2',
|
||||
'country': 'FR',
|
||||
'api_endpoint': 'https://api.scaleway.com/instance/v1/zones/fr-par-2',
|
||||
'api_endpoint_vpc': 'https://api.scaleway.com/vpc/v1/zones/fr-par-2'
|
||||
"EMEA-FR-PAR2": {
|
||||
"name": "Paris 2",
|
||||
"country": "FR",
|
||||
"api_endpoint": "https://api.scaleway.com/instance/v1/zones/fr-par-2",
|
||||
"api_endpoint_vpc": "https://api.scaleway.com/vpc/v1/zones/fr-par-2",
|
||||
},
|
||||
|
||||
'par3': {
|
||||
'name': 'Paris 3',
|
||||
'country': 'FR',
|
||||
'api_endpoint': 'https://api.scaleway.com/instance/v1/zones/fr-par-3',
|
||||
'api_endpoint_vpc': 'https://api.scaleway.com/vpc/v1/zones/fr-par-3'
|
||||
"par3": {
|
||||
"name": "Paris 3",
|
||||
"country": "FR",
|
||||
"api_endpoint": "https://api.scaleway.com/instance/v1/zones/fr-par-3",
|
||||
"api_endpoint_vpc": "https://api.scaleway.com/vpc/v1/zones/fr-par-3",
|
||||
},
|
||||
|
||||
'ams1': {
|
||||
'name': 'Amsterdam 1',
|
||||
'country': 'NL',
|
||||
'api_endpoint': 'https://api.scaleway.com/instance/v1/zones/nl-ams-1',
|
||||
'api_endpoint_vpc': 'https://api.scaleway.com/vpc/v1/zones/nl-ams-1'
|
||||
"ams1": {
|
||||
"name": "Amsterdam 1",
|
||||
"country": "NL",
|
||||
"api_endpoint": "https://api.scaleway.com/instance/v1/zones/nl-ams-1",
|
||||
"api_endpoint_vpc": "https://api.scaleway.com/vpc/v1/zones/nl-ams-1",
|
||||
},
|
||||
|
||||
'EMEA-NL-EVS': {
|
||||
'name': 'Amsterdam 1',
|
||||
'country': 'NL',
|
||||
'api_endpoint': 'https://api.scaleway.com/instance/v1/zones/nl-ams-1',
|
||||
'api_endpoint_vpc': 'https://api.scaleway.com/vpc/v1/zones/nl-ams-1'
|
||||
"EMEA-NL-EVS": {
|
||||
"name": "Amsterdam 1",
|
||||
"country": "NL",
|
||||
"api_endpoint": "https://api.scaleway.com/instance/v1/zones/nl-ams-1",
|
||||
"api_endpoint_vpc": "https://api.scaleway.com/vpc/v1/zones/nl-ams-1",
|
||||
},
|
||||
|
||||
'ams2': {
|
||||
'name': 'Amsterdam 2',
|
||||
'country': 'NL',
|
||||
'api_endpoint': 'https://api.scaleway.com/instance/v1/zones/nl-ams-2',
|
||||
'api_endpoint_vpc': 'https://api.scaleway.com/vpc/v1/zones/nl-ams-2'
|
||||
"ams2": {
|
||||
"name": "Amsterdam 2",
|
||||
"country": "NL",
|
||||
"api_endpoint": "https://api.scaleway.com/instance/v1/zones/nl-ams-2",
|
||||
"api_endpoint_vpc": "https://api.scaleway.com/vpc/v1/zones/nl-ams-2",
|
||||
},
|
||||
|
||||
'ams3': {
|
||||
'name': 'Amsterdam 3',
|
||||
'country': 'NL',
|
||||
'api_endpoint': 'https://api.scaleway.com/instance/v1/zones/nl-ams-3',
|
||||
'api_endpoint_vpc': 'https://api.scaleway.com/vpc/v1/zones/nl-ams-3'
|
||||
"ams3": {
|
||||
"name": "Amsterdam 3",
|
||||
"country": "NL",
|
||||
"api_endpoint": "https://api.scaleway.com/instance/v1/zones/nl-ams-3",
|
||||
"api_endpoint_vpc": "https://api.scaleway.com/vpc/v1/zones/nl-ams-3",
|
||||
},
|
||||
|
||||
'waw1': {
|
||||
'name': 'Warsaw 1',
|
||||
'country': 'PL',
|
||||
'api_endpoint': 'https://api.scaleway.com/instance/v1/zones/pl-waw-1',
|
||||
'api_endpoint_vpc': 'https://api.scaleway.com/vpc/v1/zones/pl-waw-1'
|
||||
"waw1": {
|
||||
"name": "Warsaw 1",
|
||||
"country": "PL",
|
||||
"api_endpoint": "https://api.scaleway.com/instance/v1/zones/pl-waw-1",
|
||||
"api_endpoint_vpc": "https://api.scaleway.com/vpc/v1/zones/pl-waw-1",
|
||||
},
|
||||
|
||||
'EMEA-PL-WAW1': {
|
||||
'name': 'Warsaw 1',
|
||||
'country': 'PL',
|
||||
'api_endpoint': 'https://api.scaleway.com/instance/v1/zones/pl-waw-1',
|
||||
'api_endpoint_vpc': 'https://api.scaleway.com/vpc/v1/zones/pl-waw-1'
|
||||
"EMEA-PL-WAW1": {
|
||||
"name": "Warsaw 1",
|
||||
"country": "PL",
|
||||
"api_endpoint": "https://api.scaleway.com/instance/v1/zones/pl-waw-1",
|
||||
"api_endpoint_vpc": "https://api.scaleway.com/vpc/v1/zones/pl-waw-1",
|
||||
},
|
||||
|
||||
'waw2': {
|
||||
'name': 'Warsaw 2',
|
||||
'country': 'PL',
|
||||
'api_endpoint': 'https://api.scaleway.com/instance/v1/zones/pl-waw-2',
|
||||
'api_endpoint_vpc': 'https://api.scaleway.com/vpc/v1/zones/pl-waw-2'
|
||||
"waw2": {
|
||||
"name": "Warsaw 2",
|
||||
"country": "PL",
|
||||
"api_endpoint": "https://api.scaleway.com/instance/v1/zones/pl-waw-2",
|
||||
"api_endpoint_vpc": "https://api.scaleway.com/vpc/v1/zones/pl-waw-2",
|
||||
},
|
||||
|
||||
'waw3': {
|
||||
'name': 'Warsaw 3',
|
||||
'country': 'PL',
|
||||
'api_endpoint': 'https://api.scaleway.com/instance/v1/zones/pl-waw-3',
|
||||
'api_endpoint_vpc': 'https://api.scaleway.com/vpc/v1/zones/pl-waw-3'
|
||||
"waw3": {
|
||||
"name": "Warsaw 3",
|
||||
"country": "PL",
|
||||
"api_endpoint": "https://api.scaleway.com/instance/v1/zones/pl-waw-3",
|
||||
"api_endpoint_vpc": "https://api.scaleway.com/vpc/v1/zones/pl-waw-3",
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue