facts: Simplify ssh key fetching

pull/11018/head
Till Maas 10 years ago
parent e7846343e5
commit 02d784598f

@ -471,36 +471,19 @@ class Facts(object):
pass pass
def get_public_ssh_host_keys(self): def get_public_ssh_host_keys(self):
dsa_filename = '/etc/ssh/ssh_host_dsa_key.pub' keytypes = ('dsa', 'rsa', 'ecdsa', 'ed25519')
rsa_filename = '/etc/ssh/ssh_host_rsa_key.pub'
ecdsa_filename = '/etc/ssh/ssh_host_ecdsa_key.pub'
ed25519_filename = '/etc/ssh/ssh_host_ed25519_key.pub'
if self.facts['system'] == 'Darwin': if self.facts['system'] == 'Darwin':
dsa_filename = '/etc/ssh_host_dsa_key.pub' keydir = '/etc'
rsa_filename = '/etc/ssh_host_rsa_key.pub'
ecdsa_filename = '/etc/ssh_host_ecdsa_key.pub'
ed25519_filename = '/etc/ssh_host_ed25519_key.pub'
dsa = get_file_content(dsa_filename)
rsa = get_file_content(rsa_filename)
ecdsa = get_file_content(ecdsa_filename)
ed25519 = get_file_content(ed25519_filename)
if dsa is None:
dsa = 'NA'
else: else:
self.facts['ssh_host_key_dsa_public'] = dsa.split()[1] keydir = '/etc/ssh'
if rsa is None:
rsa = 'NA' for type_ in keytypes:
else: key_filename = '%s/ssh_host_%s_key.pub' % (keydir, type_)
self.facts['ssh_host_key_rsa_public'] = rsa.split()[1] keydata = get_file_content(key_filename)
if ecdsa is None: if keydata is not None:
ecdsa = 'NA' factname = 'ssh_host_key_%s_public' % type_
else: self.facts[factname] = keydata.split()[1]
self.facts['ssh_host_key_ecdsa_public'] = ecdsa.split()[1]
if ed25519 is None:
ed25519 = 'NA'
else:
self.facts['ssh_host_key_ed25519_public'] = ed25519.split()[1]
def get_pkg_mgr_facts(self): def get_pkg_mgr_facts(self):
self.facts['pkg_mgr'] = 'unknown' self.facts['pkg_mgr'] = 'unknown'

Loading…
Cancel
Save