Debian Codegraph @

ansible_collections/community/crypto/plugins/modules/acme_ari_info.py

raw
1 #!/usr/bin/python
2 # Copyright (c) 2018 Felix Fontein <[email protected]>
3 # GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
4 # SPDX-License-Identifier: GPL-3.0-or-later
5
6 from __future__ import annotations
7
8 DOCUMENTATION = r"""
9 module: acme_ari_info
10 author: "Felix Fontein (@felixfontein)"
11 version_added: 2.20.0
12 short_description: Retrieves ACME Renewal Information (ARI) for a certificate
13 description:
14 - Allows to retrieve renewal information on a certificate obtained with the L(ACME protocol,https://tools.ietf.org/html/rfc8555).
15 - This module only works with the ACME v2 protocol, and requires the ACME server to support the ARI extension
16 (L(RFC 9773, https://www.rfc-editor.org/rfc/rfc9773.html)).
17 extends_documentation_fragment:
18 - community.crypto._acme.basic
19 - community.crypto._acme.no_account
20 - community.crypto._attributes
21 - community.crypto._attributes.info_module
22 - community.crypto._attributes.idempotent_not_modify_state
23 options:
24 certificate_path:
25 description:
26 - A path to the X.509 certificate to request information for.
27 - Exactly one of O(certificate_path) and O(certificate_content) must be provided.
28 type: path
29 certificate_content:
30 description:
31 - The content of the X.509 certificate to request information for.
32 - Exactly one of O(certificate_path) and O(certificate_content) must be provided.
33 type: str
34 seealso:
35 - module: community.crypto.acme_certificate
36 description: Allows to obtain a certificate using the ACME protocol.
37 - module: community.crypto.acme_certificate_revoke
38 description: Allows to revoke a certificate using the ACME protocol.
39 """
40
41 EXAMPLES = r"""
42 ---
43 - name: Retrieve renewal information for a certificate
44 community.crypto.acme_ari_info:
45 certificate_path: /etc/httpd/ssl/sample.com.crt
46 register: cert_data
47
48 - name: Show the certificate renewal information
49 ansible.builtin.debug:
50 var: cert_data.renewal_info
51 """
52
53 RETURN = r"""
54 renewal_info:
55 description: The ARI renewal info object (U(https://www.rfc-editor.org/rfc/rfc9773.html#section-4.2)).
56 returned: success
57 type: dict
58 contains:
59 suggestedWindow:
60 description:
61 - Describes the window during which the certificate should be renewed.
62 type: dict
63 returned: always
64 contains:
65 start:
66 description:
67 - The start of the window during which the certificate should be renewed.
68 - The format is specified in L(RFC 3339,https://www.rfc-editor.org/info/rfc3339).
69 returned: always
70 type: str
71 sample: '2021-01-03T00:00:00Z'
72 end:
73 description:
74 - The end of the window during which the certificate should be renewed.
75 - The format is specified in L(RFC 3339,https://www.rfc-editor.org/info/rfc3339).
76 returned: always
77 type: str
78 sample: '2021-01-03T00:00:00Z'
79 explanationURL:
80 description:
81 - A URL pointing to a page which may explain why the suggested renewal window is what it is.
82 - For example, it may be a page explaining the CA's dynamic load-balancing strategy, or a page documenting which certificates
83 are affected by a mass revocation event. Should be shown to the user.
84 returned: depends on the ACME server
85 type: str
86 sample: https://example.com/docs/ari
87 retryAfter:
88 description:
89 - A timestamp before the next retry to ask for this information should not be made.
90 returned: depends on the ACME server
91 type: str
92 sample: '2024-04-29T01:17:10.236921+00:00'
93 """
94
95 import typing as t
96
97 from ansible_collections.community.crypto.plugins.module_utils._acme.acme import (
98 ACMEClient,
99 create_backend,
100 create_default_argspec,
101 )
102 from ansible_collections.community.crypto.plugins.module_utils._acme.errors import (
103 ModuleFailException,
104 )
105
106
107 def main() -> t.NoReturn:
108 argument_spec = create_default_argspec(with_account=False)
109 argument_spec.update_argspec(
110 certificate_path={"type": "path"},
111 certificate_content={"type": "str"},
112 )
113 argument_spec.update(
114 required_one_of=[("certificate_path", "certificate_content")],
115 mutually_exclusive=[("certificate_path", "certificate_content")],
116 )
117 module = argument_spec.create_ansible_module(supports_check_mode=True)
118 backend = create_backend(module, needs_acme_v2=True)
119
120 try:
121 client = ACMEClient(module=module, backend=backend)
122 if not client.directory.has_renewal_info_endpoint():
123 module.fail_json(
124 msg="The ACME endpoint does not support ACME Renewal Information retrieval"
125 )
126 renewal_info = client.get_renewal_info(
127 cert_filename=module.params["certificate_path"],
128 cert_content=module.params["certificate_content"],
129 include_retry_after=True,
130 )
131 module.exit_json(renewal_info=renewal_info)
132 except ModuleFailException as e:
133 e.do_fail(module=module)
134
135
136 if __name__ == "__main__":
137 main()