Skip to content

Commit

Permalink
use new normalize_combined_identifier function to normalize identifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
lspiehler committed Oct 13, 2024
1 parent 70ce0f2 commit 3a1aad8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
3 changes: 3 additions & 0 deletions plugins/module_utils/acme/challenges.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ def create_key_authorization(client, token):
def combine_identifier(identifier_type, identifier):
return '{type}:{identifier}'.format(type=identifier_type, identifier=identifier)

def normalize_combined_identifier(identifier):
parts = split_identifier(identifier)
return '{type}:{identifier}'.format(type=parts[0], identifier=parts[1].lower())

def split_identifier(identifier):
parts = identifier.split(':', 1)
Expand Down
3 changes: 2 additions & 1 deletion plugins/module_utils/acme/orders.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

from ansible_collections.community.crypto.plugins.module_utils.acme.challenges import (
Authorization,
normalize_combined_identifier,
)


Expand Down Expand Up @@ -93,7 +94,7 @@ def refresh(self, client):
def load_authorizations(self, client):
for auth_uri in self.authorization_uris:
authz = Authorization.from_url(client, auth_uri)
self.authorizations[authz.combined_identifier.lower()] = authz
self.authorizations[normalize_combined_identifier(authz.combined_identifier)] = authz

def wait_for_finalization(self, client):
while True:
Expand Down
13 changes: 7 additions & 6 deletions plugins/modules/acme_certificate.py
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,7 @@
)

from ansible_collections.community.crypto.plugins.module_utils.acme.challenges import (
normalize_combined_identifier,
combine_identifier,
split_identifier,
wait_for_validation,
Expand Down Expand Up @@ -721,7 +722,7 @@ def start_challenges(self):
raise ModuleFailException('ACME v1 only supports DNS identifiers!')
for identifier_type, identifier in self.identifiers:
authz = Authorization.create(self.client, identifier_type, identifier)
self.authorizations[authz.combined_identifier.lower()] = authz
self.authorizations[normalize_combined_identifier(authz.combined_identifier)] = authz
else:
replaces_cert_id = None
if (
Expand Down Expand Up @@ -755,8 +756,8 @@ def get_challenges_data(self, first_step):
if authz.status == 'valid':
continue
# We drop the type from the key to preserve backwards compatibility
data[identifier] = authz.get_challenge_data(self.client)
if first_step and self.challenge is not None and self.challenge not in data[identifier]:
data[authz.identifier] = authz.get_challenge_data(self.client)
if first_step and self.challenge is not None and self.challenge not in data[authz.identifier]:
raise ModuleFailException("Found no challenge of type '{0}' for identifier {1}!".format(
self.challenge, type_identifier))
# Get DNS challenge data
Expand Down Expand Up @@ -835,10 +836,10 @@ def get_certificate(self):
with an error.
'''
for identifier_type, identifier in self.identifiers:
authz = self.authorizations.get(combine_identifier(identifier_type, identifier.lower()))
authz = self.authorizations.get(normalize_combined_identifier(combine_identifier(identifier_type, identifier)))
if authz is None:
raise ModuleFailException('Found no authorization information for "{identifier}"!'.format(
identifier=combine_identifier(identifier_type, identifier.lower())))
identifier=combine_identifier(identifier_type, identifier)))
if authz.status != 'valid':
authz.raise_error('Status is "{status}" and not "valid"'.format(status=authz.status), module=self.module)

Expand Down Expand Up @@ -965,7 +966,7 @@ def main():
auths = dict()
for k, v in client.authorizations.items():
# Remove "type:" from key
auths[split_identifier(k)[1]] = v.to_json()
auths[v.identifier] = v.to_json()
module.exit_json(
changed=client.changed,
authorizations=auths,
Expand Down

0 comments on commit 3a1aad8

Please sign in to comment.