Skip to content

Commit

Permalink
module_utils: use f-strings
Browse files Browse the repository at this point in the history
  • Loading branch information
flowerysong committed Jun 10, 2024
1 parent f560b29 commit c815527
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions plugins/module_utils/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def __init__(self, params, module=None):
self.params['token'] = f.read().strip()

def _open_url(self, path, method, data=None, fatal=True):
url = '{0}/v1/{1}'.format(self.params['vault_addr'], path)
url = f'{self.params["vault_addr"]}/v1/{path}'

headers = {}
if self.params.get('token'):
Expand Down Expand Up @@ -178,7 +178,7 @@ def _open_url(self, path, method, data=None, fatal=True):

except HTTPError as e:
if fatal and self._module:
msg = 'Failed to {0} {1}: {2} (HTTP {3})'.format(method, path, e.reason, e.code)
msg = f'Failed to {method} {path}: {e.reason} (HTTP {e.code})'
result = {}
try:
result = json.loads(e.read())
Expand All @@ -194,7 +194,7 @@ def _open_url(self, path, method, data=None, fatal=True):

except URLError as e:
if fatal and self._module:
self._module.fail_json(msg='Failed to {0} {1}: {2}'.format(method, path, e.reason))
self._module.fail_json(msg=f'Failed to {method} {path}: {e.reason}')
raise

def get(self, path, fatal=True):
Expand All @@ -216,6 +216,6 @@ def delete(self, path, fatal=True):
if getattr(e, 'code', 0) == 404:
return False
if fatal and self._module:
self._module.fail_json(msg='Failed to DELETE {0}: {1}'.format(path, e.reason))
self._module.fail_json(msg=f'Failed to DELETE {path}: {e.reason}')
raise
return True
8 changes: 4 additions & 4 deletions plugins/module_utils/mount.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def run(self):
self.module.exit_json(changed=False)

if not self.module.check_mode:
self.client.delete('{0}/{1}'.format(self.base_path, path))
self.client.delete(f'{self.base_path}/{path}')
self.module.exit_json(changed=True, mount=mount)

changed = False
Expand All @@ -96,7 +96,7 @@ def run(self):
for key, val in self.params['options'].items():
payload['options'][key] = str(val)

mount_path = '{0}/{1}'.format(self.base_path, path)
mount_path = f'{self.base_path}/{path}'
if not mount:
changed = True
if not self.module.check_mode:
Expand All @@ -110,7 +110,7 @@ def run(self):
if not self.module.check_mode:
if mount['type'] != payload['type']:
if not self.params['force']:
self.module.fail_json('Existing mount at {0} is {1} and force is false'.format(mount_path, mount['type']))
self.module.fail_json(f'Existing mount at {mount_path} is {mount["type"]} and force is false')
self.client.delete(mount_path)
self.client.post(mount_path, data=payload)
else:
Expand All @@ -123,7 +123,7 @@ def run(self):
if key not in payload:
payload[key] = None

self.client.post('{0}/{1}/tune'.format(self.base_path, path), data=payload)
self.client.post(f'{self.base_path}/{path}/tune', data=payload)
mount = self._get_mount(path)

self.module.exit_json(changed=changed, mount=mount, diff=diff)

0 comments on commit c815527

Please sign in to comment.