
    Vh4                   D   d Z ddlmZ ddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlmZ ddlmZ ddlmZ ddlmZ ddlm Z  dd	l!m"Z" dd
l#m$Z$ 	 ddl%m&Z' dZ(	 ddl*m+Z+ ddl,m-Z- dZ.ej^                  rddl0m1Z1 ejd                  d   Z3ejd                  d   Z4ejd                  dddddddddddd d!d"e4f   Z5ejl                  e5ejn                  e8e9ejt                  e9   ejl                  e9e9f   df   f   Z;ejl                  e3e;f   Z<ejl                  e4ejn                  e9e8df   f   Z=ejl                  ejd                  d#   ejn                  ejt                  e=   e8f   f   Z>ddl?m@ZA dd$lBmCZC dd%lDmEZE dd&lFmGZG dd'l0mHZHmIZImJZJmKZKmLZL dd(lMmNZN dd)lOmPZPmQZQmRZRmSZS 	 dd*lTmUZU dd+lVmWZWmXZX dd,lYmZZZm[Z[m\Z\ dZ]dd-l^m_Z_m&Z&m`Z` dd.lambZb dd/lcmdZd dd0lemfZfmgZgmhZh dd1limjZjmkZkmlZl dd2lmmnZn dd3lompZp dd4lqmrZr dd5lsmtZt dd6lumvZvmwZw dd7lxmyZy  et       azd8Z{d9Z| ed:g d;      Z}d<Z~e G d= d>             Z G d? d@e      Z G dA dB      ZdC ZdD ZdE ZdF ZdG ZdH ZdI ZdJ ZdK ZdL ZedM        ZedhdN       ZdO ZdP ZdidQZdR ZdS ZdT ZdU ZdV ZdW ZdX ZdjdYZdZ Zd[ Zd\ Zd] Zd^ Zd_ Zd` ZdhdaZdb Zdc Zdd Zde ZdhdfZdg Zy# e)$ r  G d d      Z'dZ(Y zw xY w# e)$ r dZ.Y yw xY w# e)$ r dZ]Y ;w xY w)kz)Installed collections management package.    )annotationsN)
namedtuple)contextmanager)	dataclass)sha256)BytesIO)distribution)chain)RequirementTc                      e Zd Zy)PkgReqN)__name__
__module____qualname__     R/home/dcms/DCMS/lib/python3.12/site-packages/ansible/galaxy/collection/__init__.pyr   r   '   s    r   r   F)Manifest)DistlibException)ConcreteArtifactsManagercollection_infofile_manifest_fileformatnameftypechksum_typechksum_sha256r   	namespacer   versionauthorsreadmetagsdescriptionlicenselicense_filedependencies
repositorydocumentationhomepageissuesfilesr   )r.   )AnsibleError)	GalaxyAPI)_consume_file_download_file_get_json_from_installed_dir_get_meta_from_src_dir_tarfile_extract)MultiGalaxyAPIProxy)run_gpg_verifyparse_gpg_errorsget_signature_from_sourceGPG_ERROR_MAP)$build_collection_dependency_resolver)(CollectionDependencyResolutionImpossible)CollectionDependencyInconsistentCandidate)RESOLVELIB_VERSIONRESOLVELIB_LOWERBOUNDRESOLVELIB_UPPERBOUND)	Candidater   _is_installed_collection_dir)meets_requirements)get_all_plugin_loaders)S_IRWU_RG_ROS_IRWXU_RXG_RXOS_IXANY)to_bytes	to_nativeto_text)is_sequence)	yaml_dump)AnsibleCollectionRef)Display)secure_hashsecure_hash_s)Sentinel   zMANIFEST.jsonModifiedContentfilenameexpected	installedz0^(?P<strict>\+)?(?:(?P<count>\d+)|(?P<all>all))$c                  <     e Zd ZU dZded<   dZded<    fdZ xZS )ManifestControlNz	list[str]
directivesFboolomit_default_directivesc                    t        j                  t        |       d      j                         D ]'  \  }}t	        | |      t
        |   | |              ) y )NT)eval_str)inspectget_annotationstypeitemsgetattrsuper__setattr__)self
field_name
field_type	__class__s      r   __post_init__zManifestControl.__post_init__   sR     '.&=&=d4jSW&X&^&^&` 	>"J
tZ(0#J
=	>r   )r   r   r   rZ   __annotations__r\   rj   __classcell__)ri   s   @r   rY   rY      s"     J	 $)T)> >r   rY   c                  ,    e Zd ZddZd Zd Zd Zd Zy)CollectionSignatureErrorNc                J    || _         || _        || _        || _        d | _        y N)reasonsstdoutrcignore_reason_wrapper)rf   rq   rr   rs   rt   s        r   __init__z!CollectionSignatureError.__init__   s&    #r   c                @    d| d| j                    d| j                   S )NzUnexpected error for 'z<': GnuPG signature verification failed with the return code z and output )rs   rr   rf   collection_names     r   _report_unexpectedz+CollectionSignatureError._report_unexpected   s3    $_$5 6HHLyP\]a]h]h\ik	
r   c                N    d| d| j                    d}|| j                         z   S )N#Signature verification failed for 'z' (return code z):)rs   _format_reasons)rf   ry   headers      r   _report_expectedz)CollectionSignatureError._report_expected   s4    66GW[W^W^V__ab,,...r   c                   | j                   t        j                  dd      | _         | j                  D cg c],  }dj	                  | j                   j                  |            . }}ddj	                  |      z   S c c}w )Nz    * z      )initial_indentsubsequent_indent
)ru   textwrapTextWrapperrq   joinwrap)rf   reasonwrapped_reasonss      r   r}   z(CollectionSignatureError._format_reasons   s    '#+#7#7'"*$D  ,,
 IId**//78
 

 dii000
s   1A>c                ^    | j                   r| j                  |      S | j                  |      S rp   )rq   r   rz   rx   s     r   reportzCollectionSignatureError.report   s+    <<((99&&77r   )NNNF)r   r   r   rv   rz   r   r}   r   r   r   r   rn   rn      s    $
/18r   rn   c                      e Zd Zd Zy)CollectionVerifyResultc                     || _         d| _        y )NT)ry   successrx   s     r   rv   zCollectionVerifyResult.__init__   s    .r   N)r   r   r   rv   r   r   r   r   r      s    r   r   c           
         t        | j                        }t        | j                  d      }t        j	                  dj                  |              t        j	                  dj                  t        | j                                     g }|du }t        j                  t        |      }t        j                  t        |      }|si| j                  |j                  k7  rPdj                  | j                  | j                  |j                  	      }	t        j	                  |	       d
|_        |S t        j                  j                  t        |d      t               }
t#        | j$                        }|r0| j&                  $| j&                  d   D cg c]  }|d   	 c}|z   }n&|s$|j$                  rt#        |j$                        |z   }|j(                  du}|s|rt        j+                  d       n[|rYt-        | j                  |
||j(                  |j.                  |j0                        s	d
|_        |S t        j3                  d|         |r |t               }n|r|j$                  r |t               }n|j5                  |      }t        j7                  dj                  t        |                   t        j                  t8        |      }t        j                  t:        |      } |t               }t=        |t         ||       t        j	                  dj                  |              |t               }|d   }|d   }|d|d   z     }t=        ||||        ||      }t?               }t        j                  j                  |d      t        j                  j                  |d      h}|d   D ]  }|d   }|d   dk(  rS|jA                  t        j                  j                  |t        |d                   |d|d   z     }t=        ||||       |d   dk(  sl|jA                  t        j                  j                  |t        |d                    dg}t        jB                  |      D ]  \  }}}|D ]  }t        j                  j                  ||       t         tE        |      dz   d d      }tG         fd|D              rt        jI                  d z         l |vsq|jK                  tM        |d d!"              |D ]`  }t        j                  j                  ||       t         tE        |      dz   d d      } |vsD|jK                  tM        |d#d$"             b  |rd
|_        t        j	                  d%j                  t        | j                        &             |D ]S  }t        j	                  d'|jN                  z         t        jI                  d(|jP                  d)|jR                         U |S |rd*nd+}t        j	                  d,j                  | |-             |S c c}w ).a5  Verify integrity of the locally installed collection.

    :param local_collection: Collection being checked.
    :param remote_collection: Upstream collection (optional, if None, only verify local artifact)
    :param artifacts_manager: Artifacts manager.
    :return: a collection verify result object.
    surrogate_or_stricterrorszVerifying '{coll!s}'.collz(Installed collection found at '{path!s}'pathNzX{local_fqcn!s} has the version '{local_ver!s}' but is being compared to '{remote_ver!s}')
local_fqcn	local_ver
remote_verF
signatures	signaturezThe GnuPG keyring used for collection signature verification was not configured but signatures were provided by the Galaxy server. Configure a keyring for ansible-galaxy to verify the origin of the collection. Skipping signature verification.z>GnuPG signature verification succeeded, verifying contents of z&Remote collection cached as '{path!s}'z#MANIFEST.json hash: {manifest_hash})manifest_hashr   r   z	chksum_%sr      MANIFEST.json
   FILES.jsonr.   r   filedir   *.pycrR   c              3  J   K   | ]  }t        j                   |        y wrp   fnmatch).0	b_pattern	full_paths     r   	<genexpr>z*verify_local_collection.<locals>.<genexpr>[  s     \Y7??9i8\    #zIgnoring verification for %szthe file does not existzthe file existsrT   zthe directory does not existzthe directory existszECollection {fqcn!s} contains modified content in the following files:)fqcnz    %sz    Expected: z
    Found: z+are internally consistent with its manifestzmatch the remote collectionz=Successfully verified that checksums for '{coll!s}' {what!s}.)r   what)*r   r   rH   srcdisplayr   rJ   	functoolspartialr3   _get_file_hashverr   osr   r   MANIFEST_FILENAMElistr   source_infokeyringwarningverify_file_signatures#required_successful_signature_countignore_signature_errorsvvvvget_artifact_path_from_unknownvvv_get_json_from_tar_file_get_tar_file_hash_verify_file_hashsetaddwalklenanyvappendrS   rU   rV   rW   )!local_collectionremote_collectionartifacts_managerresultb_collection_pathmodified_contentverify_local_onlyget_json_from_validation_sourceget_hash_from_validation_sourceerrmanifest_filer   infokeyring_configuredr   b_temp_tar_pathmanifestfile_manifest_datafile_manifest_filenameexpected_hashfile_manifestcollection_dirscollection_filesmanifest_datar   b_ignore_patternsrootdirsr.   r   content_changer   r   s!                                   @r   verify_local_collectionr      s    $$4$9$9:F !1!5!5>STOO+228H2IJOO3G,0012
 )T1 '0&7&78TVg&h#&/&7&7HY&Z##4#8#8888>/44.22044 9? 9  OOC "FNMGGLL):CX!Y[lmM&112J-99E4D4P4PQ]4^_Dd;'_bll
#4#?#?+667*D
*22$>*/	
 
%!!%%AA55
 #FNMUVfUghi78IJ	 1 < <78IJ ,JJK\]5<<'/BZ<[	

 +4*;*;<SUd*e'*3*;*;<NP_*`' 88IJ+->O_`OO9@@}@]^./@AH ""67/7&{5G5V'VWM ')?P`a34JKMeO
&(89
&6 'w/ V$!V+  .F[0\] *+m8T*TUM/}FVW!U*.F[0\]  	
  WW%67 dE 
	DT40I9S):%;a%?%ABK`aD\J[\\		89DE 00 ''#T<Uars
	  	DT40I9S):%;a%?%ABK`aD/ ''#T<Zf|}	* &F 0 5 56F7	

 / 	oNOOH~'>'>>?II>;R;RTbTlTlmn	o M AR<WtKF(tF4	

 M `s   X>c                   d}g }t        j                  t        |      j                         }|d   xs d}	|d   }
|d   }|t	        |      }|D ]-  }t        |d      }	 t        ||||       |dz  }|
r'||k(  s- n |	r|sd}t        j                  d	|  d
       nF|
r| }|s?t        j                  d	|  d       n%| xs ||k(  }|st        j                  d	|  d       |s|D ]  }t        j                  |        |S # t        $ r;}|j                  rY d }~|j                  |j                  |              Y d }~d }~ww xY w)Nr   strictFallcountr   r   rR   r|   z': no successful signaturesz': some signatures failedz,': fewer successful signatures than required)rematchSIGNATURE_COUNT_RE	groupdictintrJ   verify_file_signaturern   rt   r   r   r   r   )r   r   detached_signaturesr   required_successful_countr   
successfulerror_messagessignature_count_requirementsr   require_allrequire_countr   errorverifiedmsgs                   r   r   r     sv   JN#%88,>@Y#Z#d#d#f )(3<uF.u5K09M M*( 	I.CD		!-GE\] !OJ]*!$ j=dVC^_`	%%OOA$G`ab**Imz.IOOA$Gstu! 	CLL	 O= ( 	6||!!%,,t"455		6s    D	E	E EE	c                   t        | ||t              \  }}|rt        |      }	 t        |      }g }d}	t	        |g|      D ]~  }t        t        j                               t        t        j                               j                  |j                           }
|
|v r|	dz  }	|j                  |j                                 t        |      |	k(  }t        t        |      |||      |rt        ||      y# t         $ r Y w xY w)zURun the gpg command and parse any errors. Raises CollectionSignatureError on failure.r   rR   )rq   rr   rs   rt   )rr   rs   N)r7   r   r8   nextr
   r   r:   keysvaluesindexri   r   get_gpg_error_descriptionr   rn   r   StopIteration)r   detached_signaturer   r   
gpg_resultgpg_verification_rcr   r   rq   ignored_reasonsstatus_codert   s               r   r   r     s    '5]DVX_ah&i#J#!*-	{LE GOw/ B"=#5#5#78m>R>R>T9U9[9[\a\k\k9lm"99#q(Ou>>@AB \_4F*3w<
Wjsyzz&j=PQQ )  		s   C7 7	DDc           	     r   t        | d      }	 t        |      }t        di |}t        ||d   |d   |d   |d   |d         }d	j                  |d   |d   |d
         }t        j                  j                  t        |      t        |d            }	t        j                  j                  |	      rOt        j                  j                  |	      rt        dt	        |	      z        |st        dt	        |	      z        t        ||	||      }
|
S # t        $ r}t        t	        |            |d}~ww xY w)a  Creates the Ansible collection artifact in a .tar.gz file.

    :param u_collection_path: The path to the collection to build. This should be the directory that contains the
        galaxy.yml file.
    :param u_output_path: The path to create the collection build artifact. This should be a directory.
    :param force: Whether to overwrite an existing collection build artifact or fail.
    :return: The path to the collection build artifact.
    r   r   Nr    r   build_ignorer   r'   z{ns!s}-{name!s}-{ver!s}.tar.gzr!   )r   nsr   zQThe output collection artifact '%s' already exists, but is a directory - abortingzWThe file '%s' already exists. You can use --force to re-create the collection artifact.r   )rH   r4   LookupErrorr/   rI   _build_manifest_build_files_manifestr   r   r   r   existsisdir_build_collection_tar)u_collection_pathu_output_pathforcer   collection_meta
lookup_errcollection_manifestr   artifact_tarball_file_nameb_collection_outputcollection_outputs              r   build_collectionr    su    !!2;PQB01BC *<O<)$'
#'M "B!H!HV$;'I& "I "
 '',,+4IJ
 
ww~~)*77==,-  ?AJK^A_ ` a a  :<EFY<Z [ \ \ ..?ATVikxyA  B9Z01zABs   D 	D6D11D6c                   t        d      5  t        t        |       |d|||ddd	      }ddd       t        |d      }g }t        dj	                  |            5  j                         j                         D ]  \  }	}
|
j                  r/t        j                  d	j	                  t        |
      
             Bt        j                  dj	                  t        |
      t        |                   |j                  |
      }t        j                  j                  |t        j                  j                  |            }|
j                  r0t        t!        t        |d      t        |d      d      d      }n(t#        j
                  t%        |      t%        |             t        j                  dj	                  |

             |j'                  t%        t        j                  j                  |            |
j(                  d        t        j                  j                  |d      }t        |d      }t        j                  dj	                  t        |                   t        t+        d|i      d      }t-        |d      5 }|j/                  |       ddd       ddd       y# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   yxY w)a  Download Ansible collections as their tarball from a Galaxy server to the path specified and creates a requirements
    file of the downloaded requirements to be used for an install.

    :param collections: The collections to download, should be a list of tuples with (name, requirement, Galaxy Server).
    :param output_path: The path to download the collections to.
    :param apis: A list of GalaxyAPIs to query when search for a collection.
    :param validate_certs: Whether to validate the certificate if downloading a tarball from a non-Galaxy host.
    :param no_deps: Ignore any collection dependencies and only download the base requirements.
    :param allow_pre_release: Do not ignore pre-release versions when selecting the latest.
    zProcess download dependency mapNFgalaxy_apispreferred_candidatesconcrete_artifacts_managerno_depsallow_pre_releaseupgradeinclude_signaturesoffliner   r   z2Starting collection download process to '{path!s}'r   z{coll!s} is not downloadabler   z/Downloading collection '{coll!s}' to '{path!s}'r   r   T)r  z1Collection '{coll!s}' was downloaded successfully)r   r!   zrequirements.ymlzEWriting requirements.yml file of downloaded collections to '{path!s}'collectionswbmode)_display_progress_resolve_depenency_mapr   rH   r   copyrb   
is_virtualr   rJ   r   r   r   r   basenameis_dirr  shutilrI   r   r   rL   openwrite)r"  output_pathapisr  r  r   dep_mapb_output_pathrequirementsr   concrete_coll_pin
b_src_pathb_dest_pathrequirements_pathb_requirements_path
yaml_bytesreq_fds                    r   download_collectionsr;    s   $ 
<	= 
(!%'8/$

 [1FGML	@FF$
 @% (/||~';';'= -	#D# ++2F(9 :F; OOBG$56W]=ST
 +IIJ[\J'',,  ,K
 !''&$
3HI4IJ"
 1 Ij19[3IJOOC-.  ""''"2"2;"?@,00	! 	I-	^ GGLL6HI&&;
 	"F0A(BFC	
 }l34(

 %D1 	%VLL$	%@% @%#
 
`	% 	%@% @%s0   J6H7KK%K6K K	KKc                   |j                  |       }|rd}t        |j                  d            D ]  }|s|} n |st        d|z        t	        dj                  |            5  |j                  ||       ddd       t        j                  d|j                  d|j                         yt        j                  d|j                  d|j                  d	|       y# 1 sw Y   lxY w)
ay  Publish an Ansible collection tarball into an Ansible Galaxy server.

    :param collection_path: The path to the collection tarball to publish.
    :param api: A GalaxyAPI to publish the collection to.
    :param wait: Whether to wait until the import process is complete.
    :param timeout: The time in seconds to wait for the import process to finish, 0 is indefinite.
    N/zoPublishing the collection did not return valid task info. Cannot wait for task status. Returned task info: '%s'zRCollection has been published to the Galaxy server {api.name!s} {api.api_server!s})apizMCollection has been successfully published and imported to the Galaxy server  z0Collection has been pushed to the Galaxy server zi, not waiting until import has completed due to --no-wait being set. Import task results can be found at )
publish_collectionreversedsplitr/   r&  r   wait_import_taskr   r   
api_server)collection_pathr>  waittimeout
import_uritask_idpath_segments          r   r@  r@  h  s     ''8J
 $Z%5%5c%:; 	L&	
    Q  T^   ^  _  _228&S&/
 	3   '2		3
 	88S^^5 	6 	88S^^ZA 	B	3 	3s   &C$$C-c                b  	 |h|z  D ch c]J  }t        |	      D ]9  }t        |j                  |j                  |j                  |j
                  d      ; L }}}t        t        j                  	fd| D                    }|D ch c]  }|j                   }}||s|r
t               nQ|D ch c]D  }|D ]=  }|j                  |j                  k(  r"t        |j                  |j                        r|? F c}}z  }|s|st        j                  d       y|D ch c]  }|j                  |vr| }}|rg n|r|n|}|D ch c]9  }t        |j                  |j                  |j                  |j
                  d      ; }}t        d      5  t        | ||	||||
 |	      }ddd       	j                  du}t        d      5  j                         D ]  \  }}|j                   r/t        j#                  dj%                  t'        |                   A||v r/t        j                  d	j%                  t'        |                   t|
s#|j(                  r|st        j+                  d
       |j
                  dk(  r|j-                         }	 t/        ||	        	 ddd       yc c}}w c c}w c c}}w c c}w c c}w # 1 sw Y   !xY w# t0        $ rG}|r9t        j+                  dj%                  t'        |      t'        |                   n Y d}~Ed}~ww xY w# 1 sw Y   yxY w)a  Install Ansible collections to the path specified.

    :param collections: The collections to install.
    :param output_path: The path to install the collections to.
    :param apis: A list of GalaxyAPIs to query when searching for a collection.
    :param validate_certs: Whether to validate the certificates if downloading a tarball.
    :param ignore_errors: Whether to ignore any errors when installing the collection.
    :param no_deps: Ignore any collection dependencies and only install the base requirements.
    :param force: Re-install a collection if it has already been installed.
    :param force_deps: Re-install a collection as well as its dependencies if they have already been installed.
    Nc              3     K   | ];  }|j                   r(fd j                  |      j                         D        n|f = yw)c              3  \   K   | ]#  }t        j                  t        |             % y wrp   )r   from_dir_pathrH   )r   sub_collr   s     r   r   z0install_collections.<locals>.<genexpr>.<genexpr>  s,       ))(8*<>OPs   ),N)
is_subdirs"get_direct_collection_dependenciesr   )r   install_reqr   s     r   r   z&install_collections.<locals>.<genexpr>  sN      
  %% &66{CDF -8?;
s   AAzxNothing to do. All requested collections are already installed. If you want to reinstall them, consider using `--force`.zProcess install dependency mapr  z#Starting collection install processzEncountered {coll!s}, skipping.r   z*'{coll!s}' is already installed, skipping.a  The GnuPG keyring used for collection signature verification was not configured but signatures were provided by the Galaxy server to verify authenticity. Configure a keyring for ansible-galaxy to use or disable signature verification. Skipping signature verification.galaxyzeFailed to install collection {coll!s} but skipping due to --ignore-errors being set. Error: {error!s})r   r   )find_existing_collectionsr   r   r   r   ra   r   r
   from_iterablerC   r   rA   r&  r'  r   rb   r)  r   r   rJ   r   r   with_signatures_repopulatedinstallr/   )r"  r/  r0  ignore_errorsr  r  
force_depsr  r  r   disable_gpg_verifyr   read_requirement_pathsr   r   existing_collectionsunsatisfied_requirementsreqrequested_requirements_namesexs"existing_non_requested_collectionspreferred_requirementspreferred_collectionsdependency_mapkeyring_existsr   r4  r   s            `                  r   install_collectionsrf    se   8 !M$::-d4EF  	DIItxx499dCC   # 
  +
 	
  9Q#QCHH#Q #Q *+C'C 88sxx$6sww$H 	CC  $G(	

 	
 .*9988 	*& * 38/!  +  	$))TXXtxxDA 
 
;	< 
/!6'8/#55


 '..d:N	@	A +'5';';'= *	#D# ++5F(9 :F;  $99@F(9 :F; %*;*F*F~7 !%%1$5$Q$Q$S!);8IJ=*	+ +M( $RC"*

 
\    OOM!():!;")#,   A+ +sb   AJ*J01A	J5J;>K KC	L%KL%K	L"<LL%L""L%%L.c                v    | j                  d      \  }}}t        j                  |      r| S t        d| z        )zValidates the collection name as an input from the user or a requirements file fit the requirements.

    :param name: The input name with optional range specifier split by ':'.
    :return: The input value, required for argparse validation.
    :zInvalid collection name '%s', name must be in the format <namespace>.<collection>. 
Please make sure namespace and collection name contains characters from [a-zA-Z0-9_] only.)	partitionrM   is_valid_collection_namer/   )r   
collectiondummys      r   validate_collection_namerm    sL      $~~c2Ju44Z@
 < ?CC D Dr   c                    t         j                  j                  |       d   dk7  r t         j                  j                  | d      S | S )zEnsure a given path ends with 'ansible_collections'

    :param collection_path: The path that should end in 'ansible_collections'
    :return: collection_path ending in 'ansible_collections' if it does not already.
    rR   ansible_collections)r   r   rB  r   )rE  s    r   validate_collection_pathrp  -  s;     
ww}}_%a(,AAww||O-BCCr   c                   g }t        ||      }t               5  | D ]-  }	 |j                  r&t        dj	                  |j
                              d|j                  z  }	|D ]   }
t        t        j                  j                  |
|j                  |j                        d      }t        j                  j                  |      sdt        |      sd|j                  z  }	t        j                   ||      }|j"                  xs g D cg c]  }t%        |t&               }}t        |j                  |j(                  |j*                  |j
                  t-        |            } n t        |	      |rd	}n|j/                  |      }|j1                  |j"                  xs g D cg c]  }t%        |t&               c}       t        |j                  |j(                  d
k7  r|j(                  n|j(                  d	dt-        |            }	 |j2                  |s|j5                  |       t9        |||      }|j;                  |       0 	 d	d	d	       |S c c}w c c}w # t        $ rB}dj	                  |      }|j6                  |k(  rt        dj	                  |             d	}~ww xY w# t        $ r>}|r0t&        j=                  dj	                  |t?        |                   n Y d	}~d	}~ww xY w# 1 sw Y   |S xY w)aM  Verify the integrity of locally installed collections.

    :param collections: The collections to check.
    :param search_paths: Locations for the local collection lookup.
    :param apis: A list of GalaxyAPIs to query when searching for a collection.
    :param ignore_errors: Whether to ignore any errors when verifying the collection.
    :param local_verify_only: When True, skip downloads and only verify local manifests.
    :param artifacts_manager: Artifacts manager.
    :return: list of CollectionVerifyResult objects describing the results of each collection verification
    zM'{coll_type!s}' type is not supported. The format namespace.name is expected.)	coll_type)messagez>Collection %s is not installed in any of the collection paths.r   r   zCollection %s does not have a MANIFEST.json. A MANIFEST.json is expected if the collection has been built and installed via ansible-galaxy)r   N*rS  z4Failed to find collection {coll.fqcn!s}:{coll.ver!s}r   zHFailed to find remote collection '{coll!s}' on any of the galaxy serverszdFailed to verify collection '{coll!s}' but skipping due to --ignore-errors being set. Error: {err!s})r   r   ) r6   r&  is_concrete_artifactr/   r   ra   r   rH   r   r   r   r    r   r  rB   rA   rN  signature_sourcesr9   r   r   r   	frozensetget_signaturesextendr   get_collection_version_metadatars  r   r   r   rJ   )r"  search_pathsr0  rX  local_verify_onlyr   results	api_proxyrk  default_errsearch_pathb_search_pathr   sourcesupplemental_signaturesr   r   eexpected_error_msgr   r   s                        r   verify_collectionsr  :  s#   $ G#D*;<I		 j% i	Jh22&!A9  _akapapp#/ #<K$,'&00*//  5%M 77==7 7F?AKQ $
 !'0'>'>%'8($
 '1&B&B&Hb/" 2&'B/+ / (1(--(,,(,,(--#,-D#E($ C#<F '{;;$(,%!*!9!9:J!KJ%%&0&B&B&Hb'" 2&'B' 
 )2"*4..C*?
-11h!*-)% -44<J%EE 1" 11ACTVghv&}i	jX NS/('0 (  S"F
F3 + 99(::".!J &J 7# 
 $   	 OO) JGCLA	 	CjX Nsy   K:C*J0I
"BJ0'I>AJ0I",J0
K:
J0"	J-+=J((J--J00	K793K2,K:2K77K::Lc               #     K   t        j                  t        t        j                  d            } 	 |  t        j                  |        y # t        j                  |        w xY ww)Nr   r   )r   )tempfilemkdtemprH   CDEFAULT_LOCAL_TMPr,  rmtree)b_temp_paths    r   _tempdirr    sG     ""x0C0CLa'bcK#k"k"s   0A'A A'A$$A'c              #    K   t         j                  }|t        j                  j	                         n|}| t
        j                  |        |sd  y d } G d dt              }t
        }	 t        j                         } ||      at        j                  |||f      }d|_         |j                          	 d  d|_         |j                          	 |ay # d|_         |j                          w xY w# t        $ r  w xY w# |aw xY ww)Nc                   |j                  d       t        j                         }	 dD ]Z  }|j                  |dz   d       t	        j
                  d       	 	 | j                  dd      \  }}}t        ||      } ||i | - `# t        j                  $ r Y nw xY wt        |dd      s|j                  d	        y )
Nz(Starting display_progress display threadz|/-\F)newlineg?)blockrG  finishz7Received end signal for display_progress display thread)
debug	threadingcurrent_threadr   timesleepgetrc   queueEmpty)display_queueactual_displaytcmethodargskwargsfuncs           r   progressz#_display_progress.<locals>.progress  s    GH$$& &&q4x&?

3 ./</@/@uVY/@/Z,f  '~v>d-f-   !;;  1h."(()bcs   BBBc                      e Zd Zd Zd Zy)(_display_progress.<locals>.DisplayThreadc                    || _         y rp   )r  )rf   r  s     r   rv   z1_display_progress.<locals>.DisplayThread.__init__  s
    !.Dr   c                      fd}|S )Nc                 B    j                   j                  | |f       y rp   )r  put)r  r  attrrf   s     r   call_displayzJ_display_progress.<locals>.DisplayThread.__getattr__.<locals>.call_display  s    ""&&dF';<r   r   )rf   r  r  s   `` r   __getattr__z4_display_progress.<locals>.DisplayThread.__getattr__  s    =  r   N)r   r   r   rv   r  r   r   r   DisplayThreadr    s    	/	 r   r  )targetr  T)r  GALAXY_DISPLAY_PROGRESSsysrr   isattyr   objectr  Queuer  Threaddaemonstartr  r   	Exception)r   config_displaydisplay_wheelr  r  old_displayr  r  s           r   r&  r&    s     ..N+9+ACJJ%%'~M .	  	  K.HM;3OP		AHAFFH
  AHAFFH  sC   A)D,AC7 :C >C7 DC44C7 7DD D		Dc                P   t        t        j                  j                  t	        |       |      d      }t        j                  j                  |      sd }n!t        |d      5 }t        |      }d d d        |k7  r|j                  t        |||             y y # 1 sw Y   -xY w)Nr   r   rbr$  rT   )
rH   r   r   r   rJ   isfiler-  r1   r   rS   )b_pathrU   r   error_queueb_file_pathactual_hashfile_objects          r   r   r     s    277<<BK`aK77>>+&+D) 	5['4K	5 #?H}`klm $	5 	5s   $BB%c                 *    ddd d t         dgt         dS )N.r   r   r-   MANIFEST_FORMATr   r   r   _make_manifestr    s,     #!%)
 " r   c           
     0    d| d|d|r|nd d| |dt         iS )Nr   r   r   chksum_r   r  )r   r   r   chksums       r   _make_entryr  (  s0    f{$
+/ r   c                v    |r|t         urt        d      |t         urt        | ||||      S t        | |||      S )Nz4"build_ignore" and "manifest" are mutually exclusive)rQ   r/   _build_files_manifest_distlib_build_files_manifest_walk)r   r    r   ignore_patternsmanifest_controlr'   s         r   r	  r	  2  sS     +8;QRRx',
 	
 &&7D/ZZr   c           
     l   t         st        d      |i }	 t        d"i |}t	        |j
                        s,t        d|j
                  j                  j                         t        |j                  t              s,t        d|j                  j                  j                         |j                  r|j
                  st        d      g }|j                  r|j                  |j
                         n|j                  g d       |r|j                  d|        t        d t               D              }t        |      D ]/  }	|	d	v r|	t         j"                  v s|j                  d
|	 d       1 |j                  ddg       |j                  |j
                         |j                  d| d| dddg       t$        j'                  d       t$        j'                  t)        j*                  dj-                  |      d             t/        | d      }
t1        |
      }|D ]  }	 |j3                  |        t9               }|j                  d      D ]  }t:        j<                  j?                  ||
      }t:        j<                  jA                  |      rtC        |d      }ntC        |ddtE        |tF                     }|d!   j                  |        |S # t        $ r}t        d|       d }~ww xY w# t4        $ r}t        d|       d }~wt6        $ r}t        d|       d }~ww xY w)#Nz7Use of "manifest" requires the python "distlib" libraryzInvalid "manifest" provided: z+"manifest.directives" must be a list, got: zE"manifest.omit_default_directives" is expected to be a boolean, got: z"manifest.omit_default_directives" was set to True, but no directives were defined in "manifest.directives". This would produce an empty collection artifact.)
zinclude meta/*.ymlz2include *.txt *.md *.rst *.license COPYING LICENSEzrecursive-include .reuse **zrecursive-include LICENSES **zrecursive-include tests **zLrecursive-include docs **.rst **.yml **.yaml **.json **.j2 **.txt **.licensez?recursive-include roles **.yml **.yaml **.json **.j2 **.licensez=recursive-include playbooks **.yml **.yaml **.json **.licensez6recursive-include changelogs **.yml **.yaml **.licensez.recursive-include plugins */**.py */**.licensezinclude c              3  ^   K   | ]%  \  }}|j                   j                  d       d    ' yw)r  N)packagerB  )r   dls      r   r   z0_build_files_manifest_distlib.<locals>.<genexpr>u  s&     T41aaiiooc*2.Ts   +-)modulesmodule_utilszrecursive-include plugins/z **.yml **.yamlzBrecursive-include plugins/modules **.ps1 **.yml **.yaml **.licensezFrecursive-include plugins/module_utils **.ps1 **.psm1 **.cs **.licensez8exclude galaxy.yml galaxy.yaml MANIFEST.json FILES.json -z	-*.tar.gzz!recursive-exclude tests/output **z:global-exclude /.* /__pycache__ *.pyc *.pyo *.bak *~ *.swpzManifest Directives:r   z    r   r   zInvalid manifest directive: z-Unknown error processing manifest directive: T)wantdirsr   r   r   	hash_funcr   r  r.   r   )$HAS_DISTLIBr/   rY   	TypeErrorrK   rZ   ri   r   
isinstancer\   r[   ry  r   r   rD   sortedr  DOCUMENTABLE_PLUGINSr   r   r   indentr   rJ   r   process_directiver   r  r  r   r   relpathr  r  rO   r   )r   r    r   r  r'   controlexrZ   pluginspluginr  m	directiver  r   abs_pathrel_pathmanifest_entrys                     r   r  r  D  sA    TUUA!5$45 w))*HI[I[IeIeInInHopqqg55t<S..88AABD
 	

 &&w/A/AY
 	

 J&&',,- 
 	 78T;Q;STTWo 	F441111!!0H		 	PT
 	
 	',,-FykQRSWRXXab/H
 	 KK&'KK		* 5v>? 1:OP"#A T		T	*T HHHdH+ 177??8->?77=="(59N($"8v>	N 	  01 Os  A:2$?@@AH   	C!=aSABB 	T!NqcRSS	Ts;   K *K=	K:'K55K:=	L3LL3 L..L3c                   	 ddddddddt        d	j                  ||            g	|D cg c]  }t        |       c}z  t        g d
      t               	dd	fd | |        	S c c}w )Nr   r   s
   galaxy.ymls   galaxy.yaml   .gitr   s   *.retrys   tests/outputz{0}-{1}-*.tar.gz)s   CVSs   .bzrs   .hgr  s   .svns   __pycache__s   .toxc                    | |k(  ryt         j                  j                  || f      }t         j                  j                  | |      }|j	                  t         j                  j
                  j                               S )Nr   )r   r   
commonpathr  lstripsepencode)r  b_top_level_dircommon_prefixb_rel_base_dirs       r   !_discover_relative_base_directoryzE_build_files_manifest_walk.<locals>._discover_relative_base_directory  s\    _$**OV+DE?$$RWW[[%7%7%9::r   c                    | |      }t        j                  |       D ]  t         j                  j                  |       }t         j                  j                  |      t	        d      }t         j                  j                  |      rt        fd
D              st        fdD              r"t        j                  dt	        |      z         t         j                  j                  |      rNt         j                  j                  |      }t        ||      s#t        j                  dt	        |      z         (d   j                  t        |d             t         j                  j                  |      rg 	||       rt        fd	D              r#t        j                  dt	        |      z         d   j                  t        |d
dt        |t                             y )Nr   r   c              3  (   K   | ]	  }|k(    y wrp   r   )r   r  b_items     r   r   z<_build_files_manifest_walk.<locals>._walk.<locals>.<genexpr>  s     DFv'Ds   c              3  J   K   | ]  }t        j                   |        y wrp   r   r   r   
b_rel_paths     r   r   z<_build_files_manifest_walk.<locals>._walk.<locals>.<genexpr>  s     fyGOOJ	Bfr   z"Skipping '%s' for collection buildzLSkipping '%s' as it is a symbolic link to a directory outside the collectionr.   r   c              3  J   K   | ]  }t        j                   |        y wrp   r   r   s     r   r   z<_build_files_manifest_walk.<locals>._walk.<locals>.<genexpr>  s     a)wz9=ar   r   r   r  r  )r   listdirr   r   rJ   r  r   r   r   islinkrealpath_is_child_pathr   r   r  rO   r   )r  r  r  
b_abs_pathr  b_link_targetr  r  r  _walkb_ignore_dirsr   r   s         @@r   r	  z)_build_files_manifest_walk.<locals>._walk  s}   :6?Sjj( %	Fff5Jnf=Jz2GHHww}}Z(DmDDfTeffKK DwzGZ Z[77>>*-$&GG$4$4Z$@M)-I(v*1**=)> ? !((Xu)EFww~~j1*o6aO`aaKK DwzGZ Z[ !(( $,*:H	=%	r   )r  bytesr  r  returnr  )rH   r   rw  r  )
r   r    r   r  pr  r	  r
  r   r   s
        @@@@@r   r  r    s    
 	#**9d;<
 ?!(1+??bcMH;' 'R 

./Oo @s   A5c                Z    | |||||||d   |xs d ||	|
||ddddd t         dt         d}|S )Nr&   )r    r   r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   
FILES.jsonr   r   r   r   r  )r    r   r!   r"   r#   r$   r%   r'   r(   r)   r*   r+   r,   r  r   s                  r   r  r    sf     #&i((0D($* 
" !#!%
 "1H6 Or   c                   t        t        j                  |d      d      }t        |t              |d   d<   t        t        j                  |d      d      }t               5 }t        j                  j                  |t        j                  j                  |            }t        j                  |d	      5 }t        |fd
|ffD ]u  \  }	}
t        |
      }t        j                  |	      }t        |
      |_        t#        t%        j$                               |_        t(        |_        |j-                  ||       w |d   D ]  }|d   dk(  rt/        |d   d      }t        j                  j                  | t        |d            }d }t        j                  j1                  |      rt        j                  j3                  |      }t        j                  j5                  |      s$t7        dt/        |       dt/        |       d      t9        ||       rt        j                  j;                  |t        j                  j=                  |            }t        j                  |      }t        j>                  |_         t/        |d      |_!         ||      }|j-                  |       o|jE                  t/        t        j                  j3                  |            |d|        	 ddd       tG        jH                  t/        |      t/        |             |d   d   d|d   d   }tK        |      }tL        jM                  d|d|       |cddd       S # 1 sw Y   uxY w# 1 sw Y   yxY w)z:Build a tar.gz collection artifact from the manifest data.Tr  r   r   r  r   r   zw:gzr$  r  )tarinfofileobjr.   r   r  c                    | j                   t        j                  k7  r@| j                  t        j
                  z  }|s| j                         rt        nt        | _        dx| _	        | _
        dx| _        | _        | S )Nr    )ra   tarfileSYMTYPEr%  statS_IXUSRr  rF   rE   uidgidunamegname)r  existing_is_execs     r   
reset_statz)_build_collection_tar.<locals>.reset_stat5  sZ    ||w6+2<<$,,+F(:Jgmmoco011GK'+466GMGM"Nr   z Failed to find the target path 'z' for the symlink ''.)r  )r  F)arcname	recursivefilterNr   r    zCreated collection for z at )'rH   jsondumpsrP   r   r  r   r   r   r*  r  r-  r   r   TarInfor   sizer   r  mtimerE   r%  addfilerI   r  r  r
  r/   r  r  dirnamer  ra   linknamer   r,  r(  rJ   r   )r   
b_tar_pathr  r   files_manifest_jsoncollection_manifest_jsonr  b_tar_filepathtar_filer   bb_iotar_info	file_inforU   r5  r  r  r  ry   tar_paths                        r   r  r    s    #4::mD#IRghANObntAu,-o>'

3Ft(T]rs	 :{k2773C3CJ3OP\\.v6 0	(.0HILZmKno Aaqz"??40 #A!$TYY[!1 ,  4 @A +73 &	V$+ %Yv%6?TUWW\\*;XhWl=mn
# 77>>*-$&GG$4$4Z$@M77>>-8*-MiXeNfMggz  |E  FP  |Q  {R  RT  ,U  V  V%m5FG%'WW__]"''//ZdJe_%f
#*??8#<(/,5jI^,_)#-h#7 (((:  bgg..z:;$#%	  C&0	d 	In-y/DE%89J%KK%X%89J%KF%SU:&oxXYu: :0	 0	: :s'   &AM3;H7M'3A*M3'M0	,M33M<c                `   t        j                  |t               t        t	        j
                  |d      d      }t        |t              |d   d<   t        t	        j
                  |d      d      }t        |fd	|ffD ]  \  }}t         j                  j                  |t        |d            }t        |d
      5 }	t        |      5 }
t        j                  |
|	       ddd       ddd       t        j                  |t                 g }t#        |d   d       D ]c  }|d   dk(  rt         j                  j                  | t        |d   d            }t         j                  j                  |t        |d   d            }t        j$                  |d      j&                  t$        j(                  z  }|rt        nt         }t         j                  j+                  |      rMt         j                  j-                  |      s.t        }|j/                  |       t        j0                  ||       nt        j2                  ||d       t         j                  j-                  |      rNt        j                  ||       f t5        |      }|S # 1 sw Y   xY w# 1 sw Y   xY w)z|Build a collection directory from the manifest data.

    This should follow the same pattern as _build_collection_tar.
    r$  Tr  r   r   r  r   r   r  r#  Nr.   c                    | d   S )Nr   r   )xs    r   <lambda>z'_build_collection_dir.<locals>.<lambda>q  s
    !F) r   )keyr   r  F)follow_symlinks)r   makedirsrF   rH   r$  r%  rP   r   r   r   r   r-  r   r,  copyfileobjchmodrE   r  r  st_moder  r  r  r   mkdircopyfilerJ   )r   r  r  r   r-  r.  r   r1  r  file_objr2  base_directoriesr4  src_file	dest_filer  r%  r  s                     r   _build_collection_dirrF  ]  s+   
 KK#/:"4::mD#IRghANObntAu,-o>'

3Ft(T]rs '(@ALReCfg 'a18DI^3_`&$ 	/8WQZ 	/4tX.	/ 	/ 	&' M'28KL &	V#77<< 18If<MVk3lmGGLL!4hy?PYn6op	778UCKKdllZ"2 77=="277>>(+C"D##H-HHY% OOHiG
 ww~~i(HHY%/&2   34A	/ 	/ 	/ 	/s$    J#J#J#J J##J-	c                    t        | t        j                        r| j                         n| }t        j                  t        j
                  j                  |            j                         j                         S rp   )	r  pathlibPathas_posixr   r   
expandvars
expanduserabsolute)r   str_paths     r   _normalize_collection_pathrO    sN    ",T7<<"@t}}dH<<
8$ jl88:r   c           	   #    K   t         t        d      | rt        |       s| g} |rt        |      s|g}|rt        |      s|g}t               }t        d      j	                  d      D ]U  }t        |      }|j                         s| r$| D ]  }	 |j                  t        |              n E|j                  |       W t               }|D ]  }|j                  j                  }	|j                  }
|r|	|vr,|r|
|vr3|r)	 t        d|	 d|
       }||v rL|j                  |       n|}t        |j                               }	 t        j                   ||      }t"        j'                  dj)                  t+        |      t+        |j,                                     |  y# t        $ r Y &w xY w# t        $ r Y w xY w# t        $ r!}t"        j%                  |        Y d}~d}~ww xY ww)	zLocate all collections under a given path.

    :param path: Collection dirs layout search path.
    :param artifacts_manager: Artifacts manager.
    Nz4importlib_resources is not installed and is requiredro  z*/*/zansible_collections.r  z1Found installed collection {coll!s} at '{path!s}'r!  )r.   r/   rK   r   globrO  r+  relative_to
ValueErrorr   parentr   ImportErrorrH   rJ  rA   from_dir_path_as_unknownr   r   r   r   rJ   r   )path_filterr   namespace_filtercollection_filterdedupepathsr   pfseenr    r   rE  r   r^  val_errs                  r   rT  rT    s     }QRR;{3"m,< =,-->!?./EE+,11&9 )$/{{}! $$%?%CD  		$ 5D KK$$	yy	1A A->!>"'*>yk4&(Q"R $&HH_%"O$_%=%=%?@	445FHYZC
 	@F7377+;F<	
 	? " &    	OOwi)	sz   BG1F%)AG1F52G1GA	G1%	F2.G11F22G15	G>G1 GG1	G.G)#G1)G..G1c           	        |j                  |       }t        j                  j                  || j                  | j
                        }t        |d      }t        j                  dj                  t        |       |             t        j                  j                  |      rt        j                  |       | j                  rt        | |||       nt        |||j                   | j"                  |j$                  |j&                  |j(                         t+        | |       | j,                  r't/        | j0                  t2              rt5        | ||       t        j                  dj                  t        |                    y)zInstall a collection under a given path.

    :param collection: Collection to be installed.
    :param path: Collection dirs layout path.
    :param artifacts_manager: Artifacts manager.
    r   r   z#Installing '{coll!s}' to '{path!s}'r!  z#{coll!s} was installed successfullyr   N)r   r   r   r   r    r   rH   r   r   rJ   r
  r,  r  r+  install_srcinstall_artifact_b_working_directoryr   r   r   r   remove_source_metadatais_online_index_pointerr  r   r0   write_source_metadata)rk  r   r   b_artifact_pathrE  r   s         r   rW  rW    s.    (FFzROggll4)=)=zOO 9NOOO.GJ'o>
 
ww~~'('(J1BDUV22!!%%AA55	
 	z+<=..:jnni3X!!! OO-GJ'(r   c                v   |j                  |       }t        t        |      d      }| j                  |      }t        j
                  j                  |      d   }t        j
                  j                  |      rt        j                  |       	 t	        j                  |t               t        |d      5 }|j                  |       d d d        t	        j                  |t               y # 1 sw Y   $xY w# t         $ r6 t        j
                  j#                  |      rt        j                  |        w xY w)Nr   r   r   r$  zw+b)get_galaxy_artifact_source_inforH   rL   construct_galaxy_info_pathr   r   rB  r
  r,  r  r@  rF   r-  r.  r>  rE   r  r  )rk  r   r   source_datab_yaml_source_datab_info_dest
b_info_dirfds           r   re  re    s    #CCJOK!)K"8AVW778IJK{+A.J	ww~~j!j!	
/2+E* 	)bHH'(	)
l+	) 	)  77==$MM*%	s$   (C9 8C-
"C9 -C62C9 9?D8c                L   | j                    d| j                   d}t        j                  j	                  |dt        |d            }t        j                  |      x}rt        j                  d| d       |D ]  }	 t        j                  |        y # t        $ r Y 'w xY w)Nr  z-*.infos   ../../r   r   z	Removing z% metadata from previous installations)r    r   r   r   r   rH   rQ  r   r   r,  r  r  )rk  r   pattern	info_pathoutdated_infoinfo_dirs         r   rc  rc    s    %%&a
'8@G!67I
 9---y	)NOP! 	MM(#  		s   ?B	B#"B#c                    d}t        | d      j                  t        j                  j                        }|d   d|d   }t        || ||||      st        d| d      t        j                  d	|        y )
NFr   r   r  zNot installing z- because GnuPG signature verification failed.z+GnuPG signature verification succeeded for )	rJ   rB  r   r   r  r   r/   r   r   )r   r   r   required_signature_countr   failed_verifycoll_path_partsry   s           r   verify_artifact_manifestrz  .  s    Mm4IJPPQSQXQXQ\Q\]O!0!4ob6IJO!/=*gWo  rI  J__,==jkllLL>>OPQr   c           
     :   	 t        j                  | d      5 }t        |t        ||       |>t        j
                  j                  t        |d      t              }t        |||||       |j                  d      }	t        ||	      5 \  }
}t        j                  t        |j                         d            }ddd       t        |d||       d   D ]6  }|d   }|d	k(  r|d
   dk(  rt        |||||d          *t        |||       8 	 ddd       y# 1 sw Y   _xY w# 1 sw Y   yxY w# t        $ r` t!        j"                  |       t        j
                  j%                  |      }t	        j&                  |      st	        j(                  |        w xY w)a.  Install a collection from tarball under a given path.

    :param b_coll_targz_path: Collection tarball to be installed.
    :param b_collection_path: Collection dirs layout path.
    :param b_temp_path: Temporary dir path.
    :param signatures: frozenset of signatures to verify the MANIFEST.json
    :param keyring: The keyring used during GPG verification
    :param required_signature_count: The number of signatures that must successfully verify the collection
    :param ignore_signature_errors: GPG errors to ignore during signature verification
    rr$  Nr   r   r  r.   r   r  r   r   r   )r   )r  r-  _extract_tar_filer   r   r   r   rJ   rz  	getmemberr5   r$  loadsread_extract_tar_dirr  r,  r  r*  r  rmdir)b_coll_targz_pathr   r  r   r   rw  r   collection_tarr   files_member_objrl  	files_objr.   r4  	file_nameb_namespace_paths                   r   ra  ra  8  s   #\\+#6 	S.n.?ART_`" "W5FOd-egx y(
GMeg~-77E!.2BC \GYy

79>>+;DY#Z[\ nl<M{["7^ 
S	%f-	#W%/%niART_4=o4NP %^Y@QR
S	S 	S\ \	S 	S4  '(77??+<=zz*+HH%&sC   D1 A0D%	2D;AD%D1 D"	D%%D.*D1 .D1 1A)Fc           	        |j                  |       }d|vrg |d<   t        |d<   t        d	i |}t        ||d   |d   |d   |d   |d         }t	        ||||      }t
        j                  dj                  | |             y)
a  Install the collection from source control into given dir.

    Generates the Ansible collection artifact data from a galaxy.yml and
    installs the artifact to a directory.
    This should follow the same pattern as build_collection, but instead
    of creating an artifact, install it.

    :param collection: Collection to be installed.
    :param b_collection_path: Collection dirs layout path.
    :param b_collection_output_path: The installation directory for the \
                                     collection artifact.
    :param artifacts_manager: Artifacts manager.

    :raises AnsibleError: If no collection metadata found.
    r  r   r    r   r'   z+Created collection for {coll!s} at {path!s}r!  Nr   )get_direct_collection_metarQ   r  r	  rF  r   r   )rk  r   b_collection_output_pathr   r  r  r   collection_output_paths           r   r`  r`  i  s      (BB:NO_,*,'&.
#)<O<)$of&='
#'M 33]
 OO5J%;<r   c                   t        |d      }	 | j                  |      }t        j
                  j                  |t        |d            }t        j
                  j                  |      }	 t	        j                  |t               |j                  t        j                   k(  rWt        |j"                  d      }t%        |||      st        dt        |      d|d	      t	        j&                  ||       yt        j
                  j)                  |      st	        j*                  |t               yy# t        $ r t        d|z        w xY w# t        $ r(}|j                  t        j                  k7  r Y d}~d}~ww xY w)
z- Extracts a directory from a collection tar. r   r   z&Unable to extract '%s' from collectionr$  N	link_nameCannot extract symlink '@' in collection: path points to location outside of collection '')rI   r~  KeyErrorr/   r   r   r   rH   r*  r<  rF   OSErrorerrnoEEXISTra   r  r  r+  r  symlinkr  r@  )tarr*  b_dest
tar_member
b_dir_pathb_parent_pathr  b_link_paths           r   r  r    s8   (=>GO]]7+
 fhw?T&UVJGGOOJ/M
M8
 '//)z22;PQk6ZH4=g4F U V V 	

;
+ ww}}Z(HHZ1 )+  OCgMNNO  77ell" #s#   D5 +E 5E	FE<<Fc           
     *   t        | |      5 \  }}|j                  t        j                  k(  rt	        |      }n,t        j                  |d      5 }t	        ||      }ddd       |r5|k7  r0t        dt        |d      dt        | j                        d      t        j                  j                  t        j                  j                  |t        |d                  }	t        j                  j                  |	      }
t!        |
|      st        d	t        |d      z        t        j                  j#                  |
      st        j$                  |
t&        
       |j                  t        j                  k(  rWt        |j(                  d      }t!        |||	      st        dt        |      d|d      t        j*                  ||	       nt-        j.                  t        j                  d      |	       | j1                  t        |d            }t2        }t5        j6                  |j8                        t4        j:                  z  r	|t<        z  }t        j>                  |	|       ddd       y# 1 sw Y    xY w# 1 sw Y   yxY w)z( Extracts a file from a collection tar. F)r   deleteNzChecksum mismatch for 'r   r   z' inside collection at 'r  zSCannot extract tar entry '%s' as it will be placed outside the collection directoryr$  r  r  r  ) _get_tar_file_memberra   r  r  r1   r  NamedTemporaryFiler/   rI   r   r   r   abspathr   rH   r*  r  r
  r<  rF   r+  r  r,  mover~  rE   r  S_IMODEr%  r  rG   r>  )r  rU   r  r  r   r  tar_objr  tmpfile_objb_dest_filepathb_parent_dirr  new_modes                r   r}  r}    s   	c8	, (00EW??goo-'0K ,,UK B{+G[AB [M9"+H=R"SU^_b_g_gUh j k k ''//"'',,vxYn?o*pqww7lF3t!*8<Q!R S T T ww~~l+ KK?;??goo-":#6#6?TUK!+vQ"8A(8K[$Z [ [ JJ{O4 KK!1!1:OPRab yBW'XYJ#H||JOO,t||;G#HH_h/Q(0 (0
B B(0 (0s%   AJ	I<HJ	<J	J		Jc                    t        |d      }	 | j                  |      }t        | |      S # t        $ r& t        dt        | j                        d|d      w xY w)Nr   r   zCollection tar at 'z&' does not contain the expected file 'r   )rI   r~  r  r/   r   r5   )r  rU   
n_filenamemembers       r   r  r    sc    8,ABJz* C((  chh  	s	   , /Ac                >   d}t        j                  | d      5 }t        ||      5 \  }}d}|j                  |      }|r"|t	        |      z  }|j                  |      }|r"d d d        d d d        t        j                  |      S # 1 sw Y   &xY w# 1 sw Y   *xY w)Nr  r|  r$  i   )r  r-  r  r  rJ   r$  r  )r  rU   file_contentsr  rl  r  bufsizedatas           r   r   r     s    M	f3	' ->!.(; 	-?OwG<<(D.||G, 	-- ::m$$	- 	-- -s"   B:B"BB	BBc                    t        j                  | d      5 }t        ||      5 \  }}t        |      cd d d        cd d d        S # 1 sw Y   nxY w	 d d d        y # 1 sw Y   y xY w)Nr|  r$  )r  r-  r  r1   )r  rU   r  rl  r  s        r   r   r     si    	f3	' *>!.(; 	*?Ow )	* 	** *	* 	* 	** * *s!   AA	AA	AA%c                    t         j                  j                  | t        |d            }t	        |d      5 }t        |      cd d d        S # 1 sw Y   y xY w)Nr   r   r  )r   r   r   rH   r-  r1   )r  rU   filepathfps       r   r   r     sG    ww||FHX>S$TUH	h	 !R ! ! !s   AAc                   t        | d      }|rt        j                  j                  |      sgt        j                  j	                  t        |d            }t        j                  j                  t        j                  j                  ||            }t        |d      }||k(  xs5 |j                  |t        t        j                  j                        z         S )z> Checks that path is a path within the parent_path specified. r   r   )	rH   r   r   isabsr*  r  r   
startswithr  )r   parent_pathr  r  
b_link_dirr  s         r   r  r    s    d#89Fv.WW__Xi@U%VW
j&!AB[1FGM]"^f&7&7QSQXQXQ\Q\H]8]&^^r   c	           
        t         st        d      t        st        d      d}		 t        d      }
t	        fd|
j
                  xs g D        d      }	|	Ft        t        cxk  r	t        k  s|n t        dt        j                   dt        j                         |	j                  j                  t        j                        s$t        d|	j                   |	j                         |rd	nd
}t        |||| ||||      }	 |j                  | d      j                   S # t        $ r Y w xY w# |	Gt        t        cxk  r	t        k  s/n t        dt        j                   dt        j                         w |	j                  j                  t        j                        s$t        d|	j                   |	j                         w xY w# t"        $ rY}d |j$                  D        }t'        t)        d|            }|j+                  |       t        dj-                  |            |d}~wt.        $ r}|j0                  j3                         D cg c]  }|t5        |       nc c}w }}dj7                  |j8                  |sdn dj7                  dj-                  |                  g}|j0                  j;                         D ]-  }	|j+                  d|	j<                  d|	j>                         / |j+                  |       t        dj-                  |            |d}~wt@        $ r}t        tC        |            |d}~ww xY w)z#Return the resolved dependency map.zHFailed to import resolvelib, check that a supported version is installedzGFailed to import packaging, check that a supported version is installedNzansible-corec              3  X   K   | ]!  }t        |      xj                  d k(  s # yw)
resolvelibN)r   r   )r   r|  rrs     r   r   z)_resolve_depenency_map.<locals>.<genexpr>*  s'     `1q	/"9O9OS_9_B`s   **z#ansible-galaxy requires resolvelib<z,>=zansible-galaxy requires r  zHint: Pre-releases hosted on Galaxy or Automation Hub are not installed by default unless a specific version is requested. To enable pre-releases globally, use --pre.)r  r  r  	with_depswith_pre_releasesr  r  r   i )
max_roundsc              3     K   | ]I  }d j                  |j                  |j                  dndj                  |j                               K yw)z+* {req.fqcn!s}:{req.ver!s} ({dep_origin!s})Ndirect requestdependency of {parent!s}rT  r^  
dep_origin)r   requirementrT  )r   req_infs     r   r   z)_resolve_depenency_map.<locals>.<genexpr>L  sV      	
  :@@''>>) ,/gnn- A 	
s   AA)z_Failed to resolve the requested dependencies map. Could not satisfy the following requirements:r   zFailed to resolve the requested dependencies map. Got the candidate {req.fqcn!s}:{req.ver!s} ({dep_origin!s}) which didn't satisfy all of the following requirements:r  r  z, r  r  z* rh  )"HAS_RESOLVELIBr/   HAS_PACKAGINGr	   r   requiresr  r?   r>   r@   vstring	specifiercontainsr   r;   resolvemappingr<   causesr   r
   r   r   r=   	criterioniter_parentstrr   	candidateiter_requirementr   r   rS  rI   )requested_requirementsr  r  r  r  r  r  r  r   r^  distpre_release_hintcollection_dep_resolverdep_excconflict_causeserror_msg_linesr  parentsexcr  s                      @r   r'  r'    sT    effdee
CUN+ `!4"`bfg; ),>VAVV"9:O:W:W9XX[\q\y\y[z{  ''(:(B(BC!9#((CMM?STT.r	6  C#=1++-	64&.." / 
 '	A  
 ; ),>VAVV"9:O:W:W9XX[\q\y\y[z{  W ''(:(B(BC!9#((CMM?STT D0 4 D	
 #>>	
 u
  
  	/0499_56GC4 D#--99;
} F
 
 
K ))"  0(BF$))G"4F5	  
 $$557 	C""SXXL#''-	 	/0499_56GC 49S>*34sg   D" #D1 G "	D.+D1 -D..D1 1BG		M
AH))M
5L$I&%B?L$$M
0MM
rp   )r   N)NNT)__doc__
__future__r   r  r   r   rQ  r_   r$  r   rH  r  r   r,  r  r  r  r  r   r  r  typingr  r"  r   
contextlibr   dataclassesr   hashlibr   ior   importlib.metadatar	   	itertoolsr
   packaging.requirementsr   r   r  rU  distlib.manifestr   distlibr   r  TYPE_CHECKING3ansible.galaxy.collection.concrete_artifact_managerr   LiteralManifestKeysTypeFileMetaKeysTypeCollectionInfoKeysTypeDictUnionr   r  ListManifestValueTypeCollectionManifestTypeFileManifestEntryTypeFilesManifestTypeansible.constants	constantsr  "ansible.compat.importlib_resourcesr.   ansible.errorsr/   ansible.galaxy.apir0   r1   r2   r3   r4   r5   *ansible.galaxy.collection.galaxy_api_proxyr6   ansible.galaxy.collection.gpgr7   r8   r9   r:   $ansible.galaxy.dependency_resolutionr;   +ansible.galaxy.dependency_resolution.errorsr<   r=   .ansible.galaxy.dependency_resolution.providersr>   r?   r@   r  0ansible.galaxy.dependency_resolution.dataclassesrA   rB   /ansible.galaxy.dependency_resolution.versioningrC   ansible.plugins.loaderrD    ansible.module_utils.common.filerE   rF   rG   +ansible.module_utils.common.text.convertersrH   rI   rJ   'ansible.module_utils.common.collectionsrK    ansible.module_utils.common.yamlrL   ansible.utils.collection_loaderrM   ansible.utils.displayrN   ansible.utils.hashingrO   rP   ansible.utils.sentinelrQ   r   r  r   rS   r   rY   r  rn   r   r   r   r   r  r;  r@  rf  rm  rp  r  r  r&  r   r  r  r	  r  r  r  r  rF  rO  rT  rW  re  rc  rz  ra  r`  r  r}  r  r   r   r   r  r'  r   r   r   <module>r     s   0 "       	   	   
       " % !   + < M)( K?? yy: yy	 YYVY8>oH 			 5qwwsCPSVWV\V\]`be]eVfhl?l7mmnVV$46G$GHFF#3QWWS#t^5L#LMqyy):;QWWQVVLaEbdgEg=hhi  4 ' (  K   N  O 9 S S T T ? 6 @ ) < + )# .0UVH  
> 
> 
>%8y %8R l^/d@-`c%L"BJK^D"
BJ # # @ @F
n[$dNFT@EP.b@F+\. R.b'T2>*0Z	)%*!
_j4Y7    M	  KJ  Ns6    K. 	L 	L .LLLLLL