Handle missing source file in ssh_auth.

Added one more condition to check if source file exsists. In case source is set
but source is not a file data and err variables are set to return a proper response.

Fixes #29654
This commit is contained in:
abednarik 2015-12-14 22:41:13 -03:00
parent fe0778dad5
commit fc024e3cf4

View file

@ -282,7 +282,13 @@ def present(
)
return ret
# Get only the path to the file without env referrences to check if exists
if source != '':
source_path = __salt__['cp.get_url'](source, None)
if source != '' and not source_path:
data = 'no key'
elif source != '' and source_path:
key = __salt__['cp.get_file_str'](
source,
saltenv=__env__)
@ -332,6 +338,10 @@ def present(
ret['changes'][name] = 'New'
ret['comment'] = ('The authorized host key {0} for user {1} was added'
.format(name, user))
elif data == 'no key':
ret['result'] = False
ret['comment'] = ('Failed to add the ssh key. Source file {0} is '
'missing'.format(source))
elif data == 'fail':
ret['result'] = False
err = sys.modules[