|
|
|
@ -29,6 +29,7 @@ if t.TYPE_CHECKING:
|
|
|
|
|
|
|
|
|
|
from ansible.errors import AnsibleError
|
|
|
|
|
from ansible.galaxy.api import GalaxyAPI
|
|
|
|
|
from ansible.galaxy.collection import HAS_PACKAGING, PkgReq
|
|
|
|
|
from ansible.module_utils._text import to_bytes, to_native, to_text
|
|
|
|
|
from ansible.module_utils.common.arg_spec import ArgumentSpecValidator
|
|
|
|
|
from ansible.utils.collection_loader import AnsibleCollectionRef
|
|
|
|
@ -268,13 +269,25 @@ class _ComputedReqKindsMixin:
|
|
|
|
|
@classmethod
|
|
|
|
|
def from_string(cls, collection_input, artifacts_manager, supplemental_signatures):
|
|
|
|
|
req = {}
|
|
|
|
|
if _is_concrete_artifact_pointer(collection_input):
|
|
|
|
|
# Arg is a file path or URL to a collection
|
|
|
|
|
if _is_concrete_artifact_pointer(collection_input) or AnsibleCollectionRef.is_valid_collection_name(collection_input):
|
|
|
|
|
# Arg is a file path or URL to a collection, or just a collection
|
|
|
|
|
req['name'] = collection_input
|
|
|
|
|
else:
|
|
|
|
|
elif ':' in collection_input:
|
|
|
|
|
req['name'], _sep, req['version'] = collection_input.partition(':')
|
|
|
|
|
if not req['version']:
|
|
|
|
|
del req['version']
|
|
|
|
|
else:
|
|
|
|
|
if not HAS_PACKAGING:
|
|
|
|
|
raise AnsibleError("Failed to import packaging, check that a supported version is installed")
|
|
|
|
|
try:
|
|
|
|
|
pkg_req = PkgReq(collection_input)
|
|
|
|
|
except Exception as e:
|
|
|
|
|
# packaging doesn't know what this is, let it fly, better errors happen in from_requirement_dict
|
|
|
|
|
req['name'] = collection_input
|
|
|
|
|
else:
|
|
|
|
|
req['name'] = pkg_req.name
|
|
|
|
|
if pkg_req.specifier:
|
|
|
|
|
req['version'] = to_text(pkg_req.specifier)
|
|
|
|
|
req['signatures'] = supplemental_signatures
|
|
|
|
|
|
|
|
|
|
return cls.from_requirement_dict(req, artifacts_manager)
|
|
|
|
|