Debian Codegraph @

ansible_collections/community/general/plugins/modules/utm_ca_host_key_cert.py

raw
1 #!/usr/bin/python
2
3 # Copyright (c) 2018, Stephan Schwarz <[email protected]>
4 # GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
5 # SPDX-License-Identifier: GPL-3.0-or-later
6
7 from __future__ import annotations
8
9 DOCUMENTATION = r"""
10 module: utm_ca_host_key_cert
11
12 author:
13 - Stephan Schwarz (@stearz)
14
15 short_description: Create, update or destroy ca host_key_cert entry in Sophos UTM
16
17 description:
18 - Create, update or destroy a ca host_key_cert entry in SOPHOS UTM.
19 - This module needs to have the REST Ability of the UTM to be activated.
20 attributes:
21 check_mode:
22 support: none
23 diff_mode:
24 support: none
25
26 options:
27 name:
28 description:
29 - The name of the object that identifies the entry.
30 required: true
31 type: str
32 ca:
33 description:
34 - A reference to an existing utm_ca_signing_ca or utm_ca_verification_ca object.
35 required: true
36 type: str
37 meta:
38 description:
39 - A reference to an existing utm_ca_meta_x509 object.
40 required: true
41 type: str
42 certificate:
43 description:
44 - The certificate in PEM format.
45 required: true
46 type: str
47 comment:
48 description:
49 - Optional comment string.
50 type: str
51 encrypted:
52 description:
53 - Optionally enable encryption.
54 default: false
55 type: bool
56 key:
57 description:
58 - Optional private key in PEM format.
59 type: str
60
61 extends_documentation_fragment:
62 - community.general._utm
63 - community.general._attributes
64 """
65
66 EXAMPLES = r"""
67 - name: Create a ca_host_key_cert entry
68 community.general.utm_ca_host_key_cert:
69 utm_host: sophos.host.name
70 utm_token: abcdefghijklmno1234
71 name: TestHostKeyCertEntry
72 ca: REF_ca/signing_ca_OBJECT_STRING
73 meta: REF_ca/meta_x509_OBJECT_STRING
74 certificate: |
75 --- BEGIN CERTIFICATE ---
76 . . .
77 . . .
78 . . .
79 --- END CERTIFICATE ---
80 state: present
81
82 - name: Remove a ca_host_key_cert entry
83 community.general.utm_ca_host_key_cert:
84 utm_host: sophos.host.name
85 utm_token: abcdefghijklmno1234
86 name: TestHostKeyCertEntry
87 state: absent
88
89 - name: Read a ca_host_key_cert entry
90 community.general.utm_ca_host_key_cert:
91 utm_host: sophos.host.name
92 utm_token: abcdefghijklmno1234
93 name: TestHostKeyCertEntry
94 state: info
95 """
96
97 RETURN = r"""
98 result:
99 description: The utm object that was created.
100 returned: success
101 type: complex
102 contains:
103 _ref:
104 description: The reference name of the object.
105 type: str
106 _locked:
107 description: Whether or not the object is currently locked.
108 type: bool
109 _type:
110 description: The type of the object.
111 type: str
112 name:
113 description: The name of the object.
114 type: str
115 ca:
116 description: A reference to an existing utm_ca_signing_ca or utm_ca_verification_ca object.
117 type: str
118 meta:
119 description: A reference to an existing utm_ca_meta_x509 object.
120 type: str
121 certificate:
122 description: The certificate in PEM format.
123 type: str
124 comment:
125 description: Comment string (may be empty string).
126 type: str
127 encrypted:
128 description: If encryption is enabled.
129 type: bool
130 key:
131 description: Private key in PEM format (may be empty string).
132 type: str
133 """
134
135 from ansible_collections.community.general.plugins.module_utils._utm_utils import UTM, UTMModule
136
137
138 def main():
139 endpoint = "ca/host_key_cert"
140 key_to_check_for_changes = ["ca", "certificate", "comment", "encrypted", "key", "meta"]
141 module = UTMModule(
142 argument_spec=dict(
143 name=dict(type="str", required=True),
144 ca=dict(type="str", required=True),
145 meta=dict(type="str", required=True),
146 certificate=dict(type="str", required=True),
147 comment=dict(type="str"),
148 encrypted=dict(type="bool", default=False),
149 key=dict(type="str", no_log=True),
150 )
151 )
152 try:
153 # This is needed because the bool value only accepts int values in the backend
154 UTM(module, endpoint, key_to_check_for_changes).execute()
155 except Exception as e:
156 module.fail_json(msg=f"{e}")
157
158
159 if __name__ == "__main__":
160 main()