Merge pull request #24966 from garethgreenaway/2015_5_24862_gpg_import_key

Fixes to gpg.py in 2015.5
This commit is contained in:
Mike Place 2015-06-25 13:58:49 -06:00
commit a71c1b7c8b
2 changed files with 23 additions and 12 deletions

View File

@ -210,7 +210,6 @@ def list_keys(user=None):
salt '*' gpg.list_keys
'''
log.debug('GPG_1_3_1 {0}'.format(GPG_1_3_1))
_keys = []
for _key in _list_keys(user):
tmp = {}
@ -611,23 +610,35 @@ def import_key(user=None,
raise SaltInvocationError('filename does not exist.')
imported_data = gpg.import_keys(text)
log.debug('imported_data {0}'.format(imported_data.__dict__.keys()))
log.debug('imported_data {0}'.format(imported_data.counts))
if imported_data.counts:
if imported_data.counts['imported'] or imported_data.counts['imported_rsa']:
# include another check for Salt unit tests
gnupg_version = distutils.version.LooseVersion(gnupg.__version__)
if gnupg_version >= '1.3.1':
GPG_1_3_1 = True
if GPG_1_3_1:
counts = imported_data.counts
if counts.get('imported') or counts.get('imported_rsa'):
ret['message'] = 'Successfully imported key(s).'
elif imported_data.counts['unchanged']:
elif counts.get('unchanged'):
ret['message'] = 'Key(s) already exist in keychain.'
elif imported_data.counts['not_imported']:
elif counts.get('not_imported'):
ret['res'] = False
ret['message'] = 'Unable to import key.'
elif not imported_data.counts['count']:
elif not counts.get('count'):
ret['res'] = False
ret['message'] = 'Unable to import key.'
else:
ret['res'] = False
ret['message'] = 'Unable to import key.'
if imported_data.imported or imported_data.imported_rsa:
ret['message'] = 'Successfully imported key(s).'
elif imported_data.unchanged:
ret['message'] = 'Key(s) already exist in keychain.'
elif imported_data.not_imported:
ret['res'] = False
ret['message'] = 'Unable to import key.'
elif not imported_data.count:
ret['res'] = False
ret['message'] = 'Unable to import key.'
return ret

View File

@ -37,7 +37,7 @@ RET = [{'created': '2014-07-25',
class Mockgnupg(object):
'''
Mock smtplib class
Mock gnupg class
'''
__version__ = '1.3.1'
fingerprint = u'F321F'
@ -50,7 +50,7 @@ class Mockgnupg(object):
class GPG(object):
'''
Mock smtplib class
Mock gnupg class
'''
def __init__(self, gnupghome='/tmp/salt/.gnupg',
homedir='/tmp/salt/.gnupg'):