Jakub Josef | 60cc9d2 | 2017-01-18 12:02:14 +0100 | [diff] [blame] | 1 | import logging |
Dmitry Burmistrov | 8e41617 | 2018-08-30 16:33:27 +0400 | [diff] [blame] | 2 | import json |
Adam Tengler | 70763e0 | 2017-08-21 16:50:32 +0000 | [diff] [blame] | 3 | |
Jakub Josef | 60cc9d2 | 2017-01-18 12:02:14 +0100 | [diff] [blame] | 4 | logger = logging.getLogger(__name__) |
| 5 | |
Ilya Kharin | 3d8bffe | 2017-06-22 17:40:31 +0400 | [diff] [blame] | 6 | def __virtual__(): |
| 7 | ''' |
| 8 | Only load if jenkins_common module exist. |
| 9 | ''' |
| 10 | if 'jenkins_common.call_groovy_script' not in __salt__: |
| 11 | return ( |
| 12 | False, |
| 13 | 'The jenkins_smtp state module cannot be loaded: ' |
| 14 | 'jenkins_common not found') |
| 15 | return True |
| 16 | |
| 17 | |
Adam Tengler | 70763e0 | 2017-08-21 16:50:32 +0000 | [diff] [blame] | 18 | def config(name, host, username, password, reply_to=None, |
| 19 | port=25, ssl=False, charset="UTF-8"): |
Jakub Josef | 60cc9d2 | 2017-01-18 12:02:14 +0100 | [diff] [blame] | 20 | """ |
| 21 | Jenkins SMTP server config state method |
| 22 | |
| 23 | :param name: configuration name |
| 24 | :param host: SMTP host |
| 25 | :param username: SMTP username |
| 26 | :param password: SMTP password |
| 27 | :param reply_to: sent emails ReplyTo header (optional) |
| 28 | :param port: SMTP port (optional, default 25) |
| 29 | :param ssl: use SSL for SMTP (optional, default False) |
| 30 | :param charset: SMTP charset (optional, default UTF-8) |
| 31 | :returns: salt-specified state dict |
| 32 | """ |
Dmitry Burmistrov | 8e41617 | 2018-08-30 16:33:27 +0400 | [diff] [blame] | 33 | |
| 34 | template = __salt__['jenkins_common.load_template']( |
| 35 | 'salt://jenkins/files/groovy/smtp.template', |
| 36 | __env__) |
| 37 | |
| 38 | return __salt__['jenkins_common.api_call'](name, template, |
| 39 | ['CHANGED', 'EXISTS'], |
| 40 | {'params': json.dumps({ |
| 41 | 'username': username, |
| 42 | 'password': password, |
| 43 | 'host': host, |
| 44 | 'useReplyTo': True if reply_to else False, |
| 45 | 'replyTo': reply_to, |
| 46 | 'port': port if port else 25, |
| 47 | 'ssl': True if ssl else False, |
| 48 | 'charset': charset if charset else 'UTF-8' |
| 49 | }) |
| 50 | }, |
| 51 | 'SMTP config') |
Jakub Josef | dfb288c | 2017-04-27 17:29:00 +0200 | [diff] [blame] | 52 | |
| 53 | |
| 54 | def admin_email(name, email): |
| 55 | """ |
| 56 | Jenkins Admin user email config state method |
| 57 | |
| 58 | :param name: jenkins admin email |
| 59 | :returns: salt-specified state dict |
| 60 | """ |
Dmitry Burmistrov | 8e41617 | 2018-08-30 16:33:27 +0400 | [diff] [blame] | 61 | |
| 62 | template = __salt__['jenkins_common.load_template']( |
| 63 | 'salt://jenkins/files/groovy/admin_email.template', |
| 64 | __env__) |
| 65 | |
| 66 | return __salt__['jenkins_common.api_call'](name, template, |
| 67 | ['CHANGED', 'EXISTS'], |
| 68 | {'email': email}, |
| 69 | 'Admin email config') |