blob: c162a75ccdaed91cd99f8bfeffb1b03d0327413d [file] [log] [blame]
Ilya Kharin28ffe0c2017-06-08 03:29:42 +04001import logging
2
3LOG = logging.getLogger(__name__)
4
5
6def __virtual__():
7 if 'rundeck.get_project' not in __salt__:
8 return (
9 False,
10 'The rundeck_project state module cannot be loaded: rundeck is '
11 'unavailable',
12 )
13 return True
14
15
16def present(name, type, content):
17 result = {
18 'name': name,
19 'changes': {},
20 'result': False,
21 'comment': '',
22 'pchanges': {},
23 }
24 if __opts__['test'] == True:
25 result['comment'] = 'Nothing to create in the test mode.'
26 result['result'] = None
27 return result
28 ok, secret = __salt__['rundeck.get_secret_metadata'](name)
29 if ok:
30 do_update = secret is not None
31 ok, msg = __salt__['rundeck.upload_secret'](name, type, content,
32 update=do_update)
33 if ok:
34 result['changes'][name] = 'UPLOADED'
35 result['comment'] = (
36 "The {} secret key with the {} type was successfully uploaded."
37 .format(name, type))
38 result['result'] = True
39 else:
40 result['comment'] = msg
41 else:
42 result['comment'] = secret
43 return result
44
45
46def absent(name):
47 result = {
48 'name': name,
49 'changes': {},
50 'result': False,
51 'comment': '',
52 'pchanges': {},
53 }
54 if __opts__['test'] == True:
55 result['comment'] = 'Nothing to remove in the test mode.'
56 result['result'] = None
57 return result
58 ok, secret = __salt__['rundeck.get_secret_metadata'](name)
59 if ok:
60 if not secret:
61 result['result'] = True
62 return result
63 ok, msg = __salt__['rundeck.delete_secret'](name)
64 if ok:
65 result['changes'][name] = 'DELETED'
66 result['comment'] = "Secret key {} was removed.".format(name)
67 result['result'] = True
68 else:
69 result['comment'] = msg
70 else:
71 result['comment'] = secret
72 return result