diff options
Diffstat (limited to 'lib/ansible/galaxy/api.py')
-rw-r--r-- | lib/ansible/galaxy/api.py | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/lib/ansible/galaxy/api.py b/lib/ansible/galaxy/api.py index af7f1620..0d519980 100644 --- a/lib/ansible/galaxy/api.py +++ b/lib/ansible/galaxy/api.py @@ -11,6 +11,7 @@ import functools import hashlib import json import os +import socket import stat import tarfile import time @@ -27,7 +28,7 @@ from ansible.galaxy.user_agent import user_agent from ansible.module_utils.api import retry_with_delays_and_condition from ansible.module_utils.api import generate_jittered_backoff from ansible.module_utils.six import string_types -from ansible.module_utils.common.text.converters import to_bytes, to_native, to_text +from ansible.module_utils._text import to_bytes, to_native, to_text from ansible.module_utils.urls import open_url, prepare_multipart from ansible.utils.display import Display from ansible.utils.hashing import secure_hash_s @@ -65,7 +66,7 @@ def should_retry_error(exception): # Handle common URL related errors such as TimeoutError, and BadStatusLine # Note: socket.timeout is only required for Py3.9 - if isinstance(orig_exc, (TimeoutError, BadStatusLine, IncompleteRead)): + if isinstance(orig_exc, (TimeoutError, BadStatusLine, IncompleteRead, socket.timeout)): return True return False @@ -359,8 +360,7 @@ class GalaxyAPI: valid = False if cache_key in server_cache: expires = datetime.datetime.strptime(server_cache[cache_key]['expires'], iso_datetime_format) - expires = expires.replace(tzinfo=datetime.timezone.utc) - valid = datetime.datetime.now(datetime.timezone.utc) < expires + valid = datetime.datetime.utcnow() < expires is_paginated_url = 'page' in query or 'offset' in query if valid and not is_paginated_url: @@ -385,7 +385,7 @@ class GalaxyAPI: elif not is_paginated_url: # The cache entry had expired or does not exist, start a new blank entry to be filled later. - expires = datetime.datetime.now(datetime.timezone.utc) + expires = datetime.datetime.utcnow() expires += datetime.timedelta(days=1) server_cache[cache_key] = { 'expires': expires.strftime(iso_datetime_format), @@ -483,6 +483,8 @@ class GalaxyAPI: } if role_name: args['alternate_role_name'] = role_name + elif github_repo.startswith('ansible-role'): + args['alternate_role_name'] = github_repo[len('ansible-role') + 1:] data = self._call_galaxy(url, args=urlencode(args), method="POST") if data.get('results', None): return data['results'] @@ -921,7 +923,10 @@ class GalaxyAPI: data = self._call_galaxy(n_collection_url, error_context_msg=error_context_msg, cache=True) self._set_cache() - signatures = [signature_info["signature"] for signature_info in data.get("signatures") or []] - if not signatures: + try: + signatures = data["signatures"] + except KeyError: display.vvvv(f"Server {self.api_server} has not signed {namespace}.{name}:{version}") - return signatures + return [] + else: + return [signature_info["signature"] for signature_info in signatures] |