blob: 687f254736205c4e35e70740299ab7a752232569 [file] [log] [blame]
Jakub Josef60cc9d22017-01-18 12:02:14 +01001import logging
Dmitry Burmistrov8e416172018-08-30 16:33:27 +04002import json
Adam Tengler70763e02017-08-21 16:50:32 +00003
Jakub Josef60cc9d22017-01-18 12:02:14 +01004logger = logging.getLogger(__name__)
5
Ilya Kharin3d8bffe2017-06-22 17:40:31 +04006def __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 Tengler70763e02017-08-21 16:50:32 +000018def config(name, host, username, password, reply_to=None,
19 port=25, ssl=False, charset="UTF-8"):
Jakub Josef60cc9d22017-01-18 12:02:14 +010020 """
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 Burmistrov8e416172018-08-30 16:33:27 +040033
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 Josefdfb288c2017-04-27 17:29:00 +020052
53
54def 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 Burmistrov8e416172018-08-30 16:33:27 +040061
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')