mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-04-17 01:11:28 +00:00
modules [jk]*: use f-strings (#10970)
* modules [jk]*: use f-strings * add changelog frag * Apply suggestions from code review * typing insanity
This commit is contained in:
parent
8120e9347e
commit
4a6a449fbd
46 changed files with 363 additions and 408 deletions
|
|
@ -105,12 +105,8 @@ def del_passphrase(module):
|
|||
return None
|
||||
except keyring.errors.KeyringLocked:
|
||||
delete_argument = (
|
||||
'echo "%s" | gnome-keyring-daemon --unlock\nkeyring del %s %s\n'
|
||||
% (
|
||||
quote(module.params["keyring_password"]),
|
||||
quote(module.params["service"]),
|
||||
quote(module.params["username"]),
|
||||
)
|
||||
f'echo "{quote(module.params["keyring_password"])}" | gnome-keyring-daemon --unlock\n'
|
||||
f'keyring del {quote(module.params["service"])} {quote(module.params["username"])}\n'
|
||||
)
|
||||
dummy, dummy, stderr = module.run_command(
|
||||
"dbus-run-session -- /bin/bash",
|
||||
|
|
@ -139,13 +135,8 @@ def set_passphrase(module):
|
|||
return None
|
||||
except keyring.errors.KeyringLocked:
|
||||
set_argument = (
|
||||
'echo "%s" | gnome-keyring-daemon --unlock\nkeyring set %s %s\n%s\n'
|
||||
% (
|
||||
quote(module.params["keyring_password"]),
|
||||
quote(module.params["service"]),
|
||||
quote(module.params["username"]),
|
||||
quote(module.params["user_password"]),
|
||||
)
|
||||
f'echo "{quote(module.params["keyring_password"])}" | gnome-keyring-daemon --unlock\n'
|
||||
f'keyring set {quote(module.params["service"])} {quote(module.params["username"])}\n{quote(module.params["user_password"])}\n'
|
||||
)
|
||||
dummy, dummy, stderr = module.run_command(
|
||||
"dbus-run-session -- /bin/bash",
|
||||
|
|
@ -173,10 +164,9 @@ def get_passphrase(module):
|
|||
pass
|
||||
except AttributeError:
|
||||
pass
|
||||
get_argument = 'echo "%s" | gnome-keyring-daemon --unlock\nkeyring get %s %s\n' % (
|
||||
quote(module.params["keyring_password"]),
|
||||
quote(module.params["service"]),
|
||||
quote(module.params["username"]),
|
||||
get_argument = (
|
||||
f'echo "{quote(module.params["keyring_password"])}" | gnome-keyring-daemon --unlock\n'
|
||||
f'keyring get {quote(module.params["service"])} {quote(module.params["username"])}\n'
|
||||
)
|
||||
dummy, stdout, dummy = module.run_command(
|
||||
"dbus-run-session -- /bin/bash",
|
||||
|
|
@ -220,45 +210,30 @@ def run_module():
|
|||
if module.params["state"] == "present":
|
||||
if passphrase is not None:
|
||||
if passphrase == module.params["user_password"]:
|
||||
result["msg"] = "Passphrase already set for %s@%s" % (
|
||||
module.params["service"],
|
||||
module.params["username"],
|
||||
)
|
||||
result["msg"] = f"Passphrase already set for {module.params['service']}@{module.params['username']}"
|
||||
if passphrase != module.params["user_password"]:
|
||||
set_result = set_passphrase(module)
|
||||
if set_result is None:
|
||||
result["changed"] = True
|
||||
result["msg"] = "Passphrase has been updated for %s@%s" % (
|
||||
module.params["service"],
|
||||
module.params["username"],
|
||||
)
|
||||
result["msg"] = f"Passphrase has been updated for {module.params['service']}@{module.params['username']}"
|
||||
if set_result is not None:
|
||||
module.fail_json(msg=set_result)
|
||||
if passphrase is None:
|
||||
set_result = set_passphrase(module)
|
||||
if set_result is None:
|
||||
result["changed"] = True
|
||||
result["msg"] = "Passphrase has been updated for %s@%s" % (
|
||||
module.params["service"],
|
||||
module.params["username"],
|
||||
)
|
||||
result["msg"] = f"Passphrase has been updated for {module.params['service']}@{module.params['username']}"
|
||||
if set_result is not None:
|
||||
module.fail_json(msg=set_result)
|
||||
|
||||
if module.params["state"] == "absent":
|
||||
if not passphrase:
|
||||
result["result"] = "Passphrase already absent for %s@%s" % (
|
||||
module.params["service"],
|
||||
module.params["username"],
|
||||
)
|
||||
result["result"] = f"Passphrase already absent for {module.params['service']}@{module.params['username']}"
|
||||
if passphrase:
|
||||
del_result = del_passphrase(module)
|
||||
if del_result is None:
|
||||
result["changed"] = True
|
||||
result["msg"] = "Passphrase has been removed for %s@%s" % (
|
||||
module.params["service"],
|
||||
module.params["username"],
|
||||
)
|
||||
result["msg"] = f"Passphrase has been removed for {module.params['service']}@{module.params['username']}"
|
||||
if del_result is not None:
|
||||
module.fail_json(msg=del_result)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue