99from __future__ import annotations
1010
1111import typing as t
12+ from collections .abc import Mapping
1213
13- from ansible .module_utils .common ._collections_compat import Mapping
1414from ansible_collections .community .crypto .plugins .module_utils ._acme .errors import (
1515 ACMEProtocolException ,
1616 ModuleFailException ,
2222 ACMEClient ,
2323 )
2424
25+ _JsonMapping = Mapping [str , t .Any ]
26+ else :
27+ # Since we need to pass this to t.cast(), we need a version that doesn't break with Python 3.7 and 3.8
28+ _JsonMapping = Mapping
29+
2530
2631class ACMEAccount :
2732 """
@@ -42,7 +47,7 @@ def _new_reg(
4247 terms_agreed : bool = False ,
4348 allow_creation : bool = True ,
4449 external_account_binding : dict [str , t .Any ] | None = None ,
45- ) -> tuple [bool , dict [str , t .Any ] | None ]:
50+ ) -> tuple [bool , Mapping [str , t .Any ] | None ]:
4651 """
4752 Registers a new ACME account. Returns a pair ``(created, data)``.
4853 Here, ``created`` is ``True`` if the account was created and
@@ -132,7 +137,7 @@ def _new_reg(
132137 # Account did not exist
133138 if "location" in info :
134139 self .client .set_account_uri (info ["location" ])
135- return True , result
140+ return True , t . cast ( _JsonMapping , result )
136141 if info ["status" ] == 200 :
137142 # Account did exist
138143 if result .get ("status" ) == "deactivated" :
@@ -147,7 +152,7 @@ def _new_reg(
147152 raise ModuleFailException ("Account is deactivated" )
148153 if "location" in info :
149154 self .client .set_account_uri (info ["location" ])
150- return False , result
155+ return False , t . cast ( _JsonMapping , result )
151156 if (
152157 info ["status" ] in (400 , 404 )
153158 and result ["type" ] == "urn:ietf:params:acme:error:accountDoesNotExist"
@@ -236,7 +241,7 @@ def setup_account(
236241 allow_creation : t .Literal [True ] = True ,
237242 remove_account_uri_if_not_exists : bool = False ,
238243 external_account_binding : dict [str , t .Any ] | None = None ,
239- ) -> tuple [bool , dict [str , t .Any ]]: ...
244+ ) -> tuple [bool , Mapping [str , t .Any ]]: ...
240245
241246 @t .overload
242247 def setup_account (
@@ -247,7 +252,7 @@ def setup_account(
247252 allow_creation : bool = True ,
248253 remove_account_uri_if_not_exists : bool = False ,
249254 external_account_binding : dict [str , t .Any ] | None = None ,
250- ) -> tuple [bool , dict [str , t .Any ] | None ]: ...
255+ ) -> tuple [bool , Mapping [str , t .Any ] | None ]: ...
251256
252257 def setup_account (
253258 self ,
@@ -257,7 +262,7 @@ def setup_account(
257262 allow_creation : bool = True ,
258263 remove_account_uri_if_not_exists : bool = False ,
259264 external_account_binding : dict [str , t .Any ] | None = None ,
260- ) -> tuple [bool , dict [str , t .Any ] | None ]:
265+ ) -> tuple [bool , Mapping [str , t .Any ] | None ]:
261266 """
262267 Detect or create an account on the ACME server. For ACME v1,
263268 as the only way (without knowing an account URI) to test if an
@@ -288,7 +293,7 @@ def setup_account(
288293 created = False
289294 # Verify that the account key belongs to the URI.
290295 # (If update_contact is True, this will be done below.)
291- account_data = self .get_account_data ()
296+ account_data : Mapping [ str , t . Any ] | None = self .get_account_data ()
292297 if account_data is None :
293298 if remove_account_uri_if_not_exists and not allow_creation :
294299 self .client .account_uri = None
@@ -314,7 +319,7 @@ def setup_account(
314319
315320 def update_account (
316321 self , * , account_data : dict [str , t .Any ], contact : list [str ] | None = None
317- ) -> tuple [bool , dict [str , t .Any ]]:
322+ ) -> tuple [bool , Mapping [str , t .Any ]]:
318323 """
319324 Update an account on the ACME server. Check mode is fully respected.
320325
@@ -340,9 +345,11 @@ def update_account(
340345 return False , dict (account_data )
341346
342347 # Apply change
348+ account_data_res : Mapping [str , t .Any ]
343349 if self .client .module .check_mode :
344- account_data = dict (account_data )
345- account_data .update (update_request )
350+ account_data_dict = dict (account_data )
351+ account_data_dict .update (update_request )
352+ account_data_res = account_data_dict
346353 else :
347354 raw_account_data , info = self .client .send_signed_request (
348355 self .client .account_uri , update_request
@@ -354,9 +361,9 @@ def update_account(
354361 info = info ,
355362 content_json = account_data ,
356363 )
357- account_data = raw_account_data
364+ account_data_res = raw_account_data
358365
359- return True , account_data
366+ return True , account_data_res
360367
361368
362369__all__ = ("ACMEAccount" ,)
0 commit comments