Debian Codegraph @

ansible_collections/theforeman/foreman/plugins/modules/webhook.py

raw symbols SCIP
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3 # (c) 2023, Griffin Sullivan <[email protected]>
4 #
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 from __future__ import absolute_import, division, print_function
19 __metaclass__ = type
20
21
22 DOCUMENTATION = '''
23 ---
24 module: webhook
25 version_added: 4.0.0
26 short_description: Manage Webhooks
27 description:
28 - Manage Webhooks
29 author:
30 - "Griffin Sullivan (@Griffin-Sullivan)"
31 options:
32 name:
33 description:
34 - Name of the Webhook
35 required: true
36 type: str
37 target_url:
38 description:
39 - The URL to call when the webhook is triggered
40 - Required when creating a new webhook
41 type: str
42 http_method:
43 description:
44 - The HTTP method used in the webhook
45 choices:
46 - POST
47 - GET
48 - PUT
49 - DELETE
50 - PATCH
51 type: str
52 http_content_type:
53 description:
54 - The HTTP content type for the webhook
55 type: str
56 event:
57 description:
58 - Name of the event that shall trigger the webhook
59 - Required when creating a new webhook
60 type: str
61 webhook_template:
62 description:
63 - Name of the webhook template
64 type: str
65 enabled:
66 description:
67 - Enable or disable the webhook
68 type: bool
69 verify_ssl:
70 description:
71 - Verify SSL certs for the webhook
72 type: bool
73 ssl_ca_certs:
74 description:
75 - X509 Certification Authorities concatenated in PEM format
76 type: str
77 webhook_username:
78 description:
79 - Username for the webhook, if required
80 type: str
81 webhook_password:
82 description:
83 - Password for the webhook, if required
84 type: str
85 http_headers:
86 description:
87 - HTTP headers for the webhook
88 type: str
89 proxy_authorization:
90 description:
91 - Authorize with client certificate and validate CA from Settings
92 type: bool
93 extends_documentation_fragment:
94 - theforeman.foreman.foreman
95 - theforeman.foreman.foreman.entity_state
96 - theforeman.foreman.foreman.taxonomy
97 '''
98
99 EXAMPLES = '''
100 - name: 'Create Webhook'
101 theforeman.foreman.webhook:
102 username: 'admin'
103 password: 'secret_password'
104 server_url: 'https://foreman.example.com'
105 name: 'test-webhook'
106 target_url: 'https://google.com'
107 http_method: 'GET'
108 event: 'actions.katello.content_view.promote_succeeded'
109 enabled: true
110 organizations:
111 - 'MyOrg'
112 locations:
113 - 'DC1'
114
115 - name: 'Remove Webhook'
116 theforeman.foreman.webhook:
117 username: 'admin'
118 password: 'secret_password'
119 server_url: 'https://foreman.example.com'
120 name: 'test-webhook'
121 state: 'absent'
122 '''
123
124 RETURN = '''
125 entity:
126 description: Final state of the affected entities grouped by their type.
127 returned: success
128 type: dict
129 contains:
130 webhooks:
131 description: List of webhooks.
132 type: list
133 elements: dict
134 '''
135
136 from ansible_collections.theforeman.foreman.plugins.module_utils.foreman_helper import ForemanTaxonomicEntityAnsibleModule
137
138
139 class ForemanWebhookModule(ForemanTaxonomicEntityAnsibleModule):
140 pass
141
142
143 def main():
144 module = ForemanWebhookModule(
145 foreman_spec=dict(
146 name=dict(required=True),
147 target_url=dict(),
148 http_method=dict(choices=['POST', 'GET', 'PUT', 'DELETE', 'PATCH']),
149 http_content_type=dict(),
150 event=dict(),
151 webhook_template=dict(type='entity'),
152 verify_ssl=dict(type='bool'),
153 enabled=dict(type='bool'),
154 ssl_ca_certs=dict(),
155 webhook_username=dict(flat_name='user'),
156 webhook_password=dict(no_log=True, flat_name='password'),
157 http_headers=dict(),
158 proxy_authorization=dict(type='bool'),
159 ),
160 )
161
162 with module.api_connection():
163 module.run()
164
165
166 if __name__ == '__main__':
167 main()