Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

acme module utils: add function for retrieval of ARI information #738

Merged
merged 1 commit into from
Apr 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions plugins/module_utils/acme/acme.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@
)

from ansible_collections.community.crypto.plugins.module_utils.acme.utils import (
compute_cert_id,
nopad_b64,
parse_retry_after,
)

try:
Expand Down Expand Up @@ -153,6 +155,9 @@ def get_nonce(self, resource=None):
self.module, msg='Was not able to obtain nonce, giving up after 5 retries', info=info, response=response)
retry_count += 1

def has_renewal_info_endpoint(self):
return 'renewalInfo' in self.directory


class ACMEClient(object):
'''
Expand Down Expand Up @@ -383,6 +388,32 @@ def get_request(self, uri, parse_json_result=True, headers=None, get_only=False,
self.module, msg=error_msg, info=info, content=content, content_json=result if parsed_json_result else None)
return result, info

def get_renewal_info(
self,
cert_filename=None,
cert_content=None,
include_retry_after=False,
retry_after_relative_with_timezone=True,
):
if not self.directory.has_renewal_info_endpoint():
raise ModuleFailException('The ACME endpoint does not support ACME Renewal Information retrieval')

cert_id = compute_cert_id(self.backend, cert_filename=cert_filename, cert_content=cert_content)
url = '{base}{cert_id}'.format(base=self.directory.directory['renewalInfo'], cert_id=cert_id)

data, info = self.get_request(url, parse_json_result=True, fail_on_error=True, get_only=True)

# Include Retry-After header if asked for
if include_retry_after and 'retry-after' in info:
try:
data['retryAfter'] = parse_retry_after(
info['retry-after'],
relative_with_timezone=retry_after_relative_with_timezone,
)
except ValueError:
pass
return data


def get_default_argspec(with_account=True):
'''
Expand Down