mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 00:55:19 +00:00
Correctly handle the situation when with the secret key or public key values are empty.
This commit is contained in:
parent
3fdb564346
commit
c314f5166b
@ -69,12 +69,15 @@ def _get_sk(**kwargs):
|
|||||||
Return sk
|
Return sk
|
||||||
'''
|
'''
|
||||||
config = _get_config(**kwargs)
|
config = _get_config(**kwargs)
|
||||||
|
key = None
|
||||||
|
if config['sk']:
|
||||||
key = salt.utils.stringutils.to_str(config['sk'])
|
key = salt.utils.stringutils.to_str(config['sk'])
|
||||||
sk_file = config['sk_file']
|
sk_file = config['sk_file']
|
||||||
if not key and sk_file:
|
if not key and sk_file:
|
||||||
|
try:
|
||||||
with salt.utils.files.fopen(sk_file, 'rb') as keyf:
|
with salt.utils.files.fopen(sk_file, 'rb') as keyf:
|
||||||
key = salt.utils.stringutils.to_unicode(keyf.read()).rstrip('\n')
|
key = salt.utils.stringutils.to_unicode(keyf.read()).rstrip('\n')
|
||||||
if key is None:
|
except (IOError, OSError):
|
||||||
raise Exception('no key or sk_file found')
|
raise Exception('no key or sk_file found')
|
||||||
return base64.b64decode(key)
|
return base64.b64decode(key)
|
||||||
|
|
||||||
@ -84,12 +87,15 @@ def _get_pk(**kwargs):
|
|||||||
Return pk
|
Return pk
|
||||||
'''
|
'''
|
||||||
config = _get_config(**kwargs)
|
config = _get_config(**kwargs)
|
||||||
|
pubkey = None
|
||||||
|
if config['pk']:
|
||||||
pubkey = salt.utils.stringutils.to_str(config['pk'])
|
pubkey = salt.utils.stringutils.to_str(config['pk'])
|
||||||
pk_file = config['pk_file']
|
pk_file = config['pk_file']
|
||||||
if not pubkey and pk_file:
|
if not pubkey and pk_file:
|
||||||
|
try:
|
||||||
with salt.utils.files.fopen(pk_file, 'rb') as keyf:
|
with salt.utils.files.fopen(pk_file, 'rb') as keyf:
|
||||||
pubkey = salt.utils.stringutils.to_unicode(keyf.read()).rstrip('\n')
|
pubkey = salt.utils.stringutils.to_unicode(keyf.read()).rstrip('\n')
|
||||||
if pubkey is None:
|
except (IOError, OSError):
|
||||||
raise Exception('no pubkey or pk_file found')
|
raise Exception('no pubkey or pk_file found')
|
||||||
pubkey = six.text_type(pubkey)
|
pubkey = six.text_type(pubkey)
|
||||||
return base64.b64decode(pubkey)
|
return base64.b64decode(pubkey)
|
||||||
|
Loading…
Reference in New Issue
Block a user