mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-04-18 01:41:35 +00:00
Reformat everything.
This commit is contained in:
parent
3f2213791a
commit
340ff8586d
1008 changed files with 61301 additions and 58309 deletions
|
|
@ -26,8 +26,7 @@ HASHED_KEY_MAGIC = "|1|"
|
|||
|
||||
|
||||
def is_ssh_url(url):
|
||||
|
||||
""" check if url is ssh """
|
||||
"""check if url is ssh"""
|
||||
|
||||
if "@" in url and "://" not in url:
|
||||
return True
|
||||
|
|
@ -38,12 +37,11 @@ def is_ssh_url(url):
|
|||
|
||||
|
||||
def get_fqdn_and_port(repo_url):
|
||||
|
||||
""" chop the hostname and port out of a url """
|
||||
"""chop the hostname and port out of a url"""
|
||||
|
||||
fqdn = None
|
||||
port = None
|
||||
ipv6_re = re.compile(r'(\[[^]]*\])(?::([0-9]+))?')
|
||||
ipv6_re = re.compile(r"(\[[^]]*\])(?::([0-9]+))?")
|
||||
if "@" in repo_url and "://" not in repo_url:
|
||||
# most likely an user@host:path or user@host/path type URL
|
||||
repo_url = repo_url.split("@", 1)[1]
|
||||
|
|
@ -76,9 +74,9 @@ def check_hostkey(module, fqdn):
|
|||
# this is a variant of code found in connection_plugins/paramiko.py and we should modify
|
||||
# the paramiko code to import and use this.
|
||||
|
||||
def not_in_host_file(self, host):
|
||||
|
||||
if 'USER' in os.environ:
|
||||
def not_in_host_file(self, host):
|
||||
if "USER" in os.environ:
|
||||
user_host_file = os.path.expandvars("~${USER}/.ssh/known_hosts")
|
||||
else:
|
||||
user_host_file = "~/.ssh/known_hosts"
|
||||
|
|
@ -111,10 +109,10 @@ def not_in_host_file(self, host):
|
|||
if tokens[0].find(HASHED_KEY_MAGIC) == 0:
|
||||
# this is a hashed known host entry
|
||||
try:
|
||||
(kn_salt, kn_host) = tokens[0][len(HASHED_KEY_MAGIC):].split("|", 2)
|
||||
hash = hmac.new(kn_salt.decode('base64'), digestmod=sha1)
|
||||
(kn_salt, kn_host) = tokens[0][len(HASHED_KEY_MAGIC) :].split("|", 2)
|
||||
hash = hmac.new(kn_salt.decode("base64"), digestmod=sha1)
|
||||
hash.update(host)
|
||||
if hash.digest() == kn_host.decode('base64'):
|
||||
if hash.digest() == kn_host.decode("base64"):
|
||||
return False
|
||||
except Exception:
|
||||
# invalid hashed host key, skip it
|
||||
|
|
@ -128,12 +126,11 @@ def not_in_host_file(self, host):
|
|||
|
||||
|
||||
def add_host_key(module, fqdn, port=22, key_type="rsa", create_dir=False):
|
||||
"""use ssh-keyscan to add the hostkey"""
|
||||
|
||||
""" use ssh-keyscan to add the hostkey """
|
||||
keyscan_cmd = module.get_bin_path("ssh-keyscan", True)
|
||||
|
||||
keyscan_cmd = module.get_bin_path('ssh-keyscan', True)
|
||||
|
||||
if 'USER' in os.environ:
|
||||
if "USER" in os.environ:
|
||||
user_ssh_dir = os.path.expandvars("~${USER}/.ssh/")
|
||||
user_host_file = os.path.expandvars("~${USER}/.ssh/known_hosts")
|
||||
else:
|
||||
|
|
@ -144,7 +141,7 @@ def add_host_key(module, fqdn, port=22, key_type="rsa", create_dir=False):
|
|||
if not os.path.exists(user_ssh_dir):
|
||||
if create_dir:
|
||||
try:
|
||||
os.makedirs(user_ssh_dir, int('700', 8))
|
||||
os.makedirs(user_ssh_dir, int("700", 8))
|
||||
except Exception:
|
||||
module.fail_json(msg=f"failed to create host key directory: {user_ssh_dir}")
|
||||
else:
|
||||
|
|
@ -160,14 +157,14 @@ def add_host_key(module, fqdn, port=22, key_type="rsa", create_dir=False):
|
|||
rc, out, err = module.run_command(this_cmd)
|
||||
# ssh-keyscan gives a 0 exit code and prints nothing on timeout
|
||||
if rc != 0 or not out:
|
||||
msg = 'failed to retrieve hostkey'
|
||||
msg = "failed to retrieve hostkey"
|
||||
if not out:
|
||||
msg += f'. "{this_cmd}" returned no matches.'
|
||||
else:
|
||||
msg += f' using command "{this_cmd}". [stdout]: {out}'
|
||||
|
||||
if err:
|
||||
msg += f' [stderr]: {err}'
|
||||
msg += f" [stderr]: {err}"
|
||||
|
||||
module.fail_json(msg=msg)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue