|
55 | 55 |
|
56 | 56 | async def wait_for_api_key(
|
57 | 57 | self,
|
58 |
| - operation: str, |
59 | 58 | key: str,
|
| 59 | + operation: str, |
60 | 60 | api_key: Optional[ApiKey] = None,
|
61 | 61 | max_retries: int = 50,
|
62 | 62 | timeout: RetryTimeout = RetryTimeout(),
|
63 | 63 | request_options: Optional[Union[dict, RequestOptions]] = None,
|
64 |
| - ) -> GetApiKeyResponse: |
| 64 | + ) -> GetApiKeyResponse | None: |
65 | 65 | """
|
66 | 66 | Helper: Wait for an API key to be added, updated or deleted based on a given `operation`.
|
67 | 67 | """
|
|
72 | 72 | "`apiKey` is required when waiting for an `update` operation."
|
73 | 73 | )
|
74 | 74 |
|
75 |
| - async def _func(_prev: GetApiKeyResponse) -> GetApiKeyResponse: |
| 75 | + async def _func(_prev: GetApiKeyResponse | None) -> GetApiKeyResponse | None: |
76 | 76 | try:
|
77 | 77 | return await self.get_api_key(key=key, request_options=request_options)
|
78 | 78 | except RequestException as e:
|
79 | 79 | if e.status_code == 404 and (operation == "delete" or operation == "add"):
|
80 | 80 | return None
|
81 | 81 | raise e
|
82 | 82 |
|
83 |
| - def _aggregator(_: GetApiKeyResponse) -> None: |
| 83 | + def _aggregator(_: GetApiKeyResponse | None) -> None: |
84 | 84 | self._retry_count += 1
|
85 | 85 |
|
86 |
| - def _validate(_resp: GetApiKeyResponse) -> bool: |
| 86 | + def _validate(_resp: GetApiKeyResponse | None) -> bool: |
87 | 87 | if operation == "update":
|
88 |
| - for field in api_key: |
89 |
| - if isinstance(api_key[field], list) and isinstance(_resp[field], list): |
90 |
| - if len(api_key[field]) != len(_resp[field]) or any( |
91 |
| - v != _resp[field][i] for i, v in enumerate(api_key[field]) |
| 88 | + resp_dict = _resp.to_dict() |
| 89 | + api_key_dict = api_key.to_dict() if isinstance(api_key, ApiKey) else api_key |
| 90 | + for field in api_key_dict: |
| 91 | + if isinstance(api_key_dict[field], list) and isinstance( |
| 92 | + resp_dict[field], list |
| 93 | + ): |
| 94 | + if len(api_key_dict[field]) != len(resp_dict[field]) or any( |
| 95 | + v != resp_dict[field][i] for i, v in enumerate(api_key_dict[field]) |
92 | 96 | ):
|
93 | 97 | return False
|
94 |
| - elif api_key[field] != _resp[field]: |
| 98 | + elif api_key_dict[field] != resp_dict[field]: |
95 | 99 | return False
|
96 | 100 | return True
|
97 | 101 | elif operation == "add":
|
|
0 commit comments