mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Merge pull request #38937 from HashBangDev/fix-smtp-ret-require-gnupg
Fix smtp ret require gnupg
This commit is contained in:
commit
0660cc3cf2
1 changed files with 14 additions and 14 deletions
|
@ -132,9 +132,7 @@ __virtualname__ = 'smtp'
|
|||
|
||||
|
||||
def __virtual__():
|
||||
if HAS_GNUPG:
|
||||
return __virtualname__
|
||||
return False, 'Could not import smtp returner; gnupg is not installed.'
|
||||
return __virtualname__
|
||||
|
||||
|
||||
def _get_options(ret=None):
|
||||
|
@ -219,18 +217,20 @@ def returner(ret):
|
|||
input_data=template,
|
||||
**ret)
|
||||
|
||||
if HAS_GNUPG and gpgowner:
|
||||
gpg = gnupg.GPG(gnupghome=os.path.expanduser('~{0}/.gnupg'.format(gpgowner)),
|
||||
options=['--trust-model always'])
|
||||
encrypted_data = gpg.encrypt(content, to_addrs)
|
||||
if encrypted_data.ok:
|
||||
log.debug('smtp_return: Encryption successful')
|
||||
content = str(encrypted_data)
|
||||
if gpgowner:
|
||||
if HAS_GNUPG:
|
||||
gpg = gnupg.GPG(gnupghome=os.path.expanduser('~{0}/.gnupg'.format(gpgowner)),
|
||||
options=['--trust-model always'])
|
||||
encrypted_data = gpg.encrypt(content, to_addrs)
|
||||
if encrypted_data.ok:
|
||||
log.debug('smtp_return: Encryption successful')
|
||||
content = str(encrypted_data)
|
||||
else:
|
||||
log.error('smtp_return: Encryption failed, only an error message will be sent')
|
||||
content = 'Encryption failed, the return data was not sent.\r\n\r\n{0}\r\n{1}'.format(
|
||||
encrypted_data.status, encrypted_data.stderr)
|
||||
else:
|
||||
log.error('smtp_return: Encryption failed, only an error message will be sent')
|
||||
content = 'Encryption failed, the return data was not sent.\r\n\r\n{0}\r\n{1}'.format(
|
||||
encrypted_data.status, encrypted_data.stderr)
|
||||
|
||||
log.error("gnupg python module is required in order to user gpgowner in smtp returner ; ignoring gpgowner configuration for now")
|
||||
if isinstance(content, six.moves.StringIO):
|
||||
content = content.read()
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue