Add hash_type argument to wheel fingerprint functions

This commit is contained in:
Adam Mendlik 2016-12-28 09:26:24 -07:00
parent e558ddcb18
commit d0f4c300b7
2 changed files with 22 additions and 10 deletions

View file

@ -338,11 +338,11 @@ class MultiKeyCLI(KeyCLI):
def print_all(self):
self._call_all('print_all')
def finger(self, match):
self._call_all('finger', match)
def finger(self, match, hash_type):
self._call_all('finger', match, hash_type)
def finger_all(self):
self._call_all('finger_all')
self._call_all('finger_all', hash_type)
def prep_signature(self):
self._call_all('prep_signature')
@ -895,10 +895,13 @@ class Key(object):
salt.crypt.dropfile(self.opts['cachedir'], self.opts['user'])
return self.list_keys()
def finger(self, match):
def finger(self, match, hash_type=None):
'''
Return the fingerprint for a specified key
'''
if hash_type is None:
hash_type = __opts__['hash_type']
matches = self.name_match(match, True)
ret = {}
for status, keys in six.iteritems(matches):
@ -908,13 +911,16 @@ class Key(object):
path = os.path.join(self.opts['pki_dir'], key)
else:
path = os.path.join(self.opts['pki_dir'], status, key)
ret[status][key] = salt.utils.pem_finger(path, sum_type=self.opts['hash_type'])
ret[status][key] = salt.utils.pem_finger(path, sum_type=hash_type)
return ret
def finger_all(self):
def finger_all(self, hash_type=None):
'''
Return fingerprints for all keys
'''
if hash_type is None:
hash_type = __opts__['hash_type']
ret = {}
for status, keys in six.iteritems(self.all_keys()):
ret[status] = {}
@ -923,7 +929,7 @@ class Key(object):
path = os.path.join(self.opts['pki_dir'], key)
else:
path = os.path.join(self.opts['pki_dir'], status, key)
ret[status][key] = salt.utils.pem_finger(path, sum_type=self.opts['hash_type'])
ret[status][key] = salt.utils.pem_finger(path, sum_type=hash_type)
return ret

View file

@ -274,21 +274,27 @@ def key_str(match):
return skey.key_str(match)
def finger(match):
def finger(match, hash_type=None):
'''
Return the matching key fingerprints. Returns a dictionary.
match
The key for with to retrieve the fingerprint.
hash_type
The hash algorithm used to calculate the fingerprint
.. code-block:: python
>>> wheel.cmd('key.finger', ['minion1'])
{'minions': {'minion1': '5d:f6:79:43:5e:d4:42:3f:57:b8:45:a8:7e:a4:6e:ca'}}
'''
if hash_type is None:
hash_type = __opts__['hash_type']
skey = get_key(__opts__)
return skey.finger(match)
return skey.finger(match, hash_type)
def finger_master(hash_type=None):
@ -308,7 +314,7 @@ def finger_master(hash_type=None):
hash_type = __opts__['hash_type']
fingerprint = salt.utils.pem_finger(
os.path.join(__opts__['pki_dir'], keyname), hash_type)
os.path.join(__opts__['pki_dir'], keyname), sum_type=hash_type)
return {'local': {keyname: fingerprint}}