a ì)gà'ã@sþdZddlmZmZmZeZddlZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlZddlZddlZddlZddlZddlZddlZddlZddlZddlmZddlmZddlmZmZddl m!Z!ddl"m#Z#dd l$m%Z%dd l&m'Z'zdd l(m)Z*Wn&e+�y*Gd d „d ƒZ*dZ,Yn0dZ,zddl-m.Z.ddl/m0Z0Wne+�yddZ1Yn0dZ1ej2�r4ddl3m4Z4ej5dZ6ej5dZ7ej5dddddddddddd d!d"e7fZ8ej9e8ej:e;eej9e6e>fZ?ej9e7ej:ed?„d?eƒZ€Gd@dA„dAƒZ�dBdC„Z‚dDdE„ZƒdFdG„Z„dHdI„Z…dJdK„Z†dLdM„Z‡dNdO„ZˆdPdQ„Z‰dRdS„ZŠdTdU„Z‹edVdW„ƒZŒed‰dXdY„ƒZ�dZd[„ZŽd\d]„Z�dŠd_d`„Z�dadb„Z‘dcdd„Z’dedf„Z“dgdh„Z”didj„Z•dkdl„Z–dmdn„Z—dodp„Z˜dqdr„Z™dsdt„Zšdudv„Z›dwdx„Zœdydz„Z�d‹d{d|„Zžd}d~„ZŸdd€„Z d�d‚„Z¡dƒd„„Z¢dŒd…d†„Z£d‡dˆ„Z¤dS)�z)Installed collections management package.é)Úabsolute_importÚdivisionÚprint_functionN)Ú namedtuple)Úcontextmanager)Ú dataclassÚfields)Úsha256)ÚBytesIO)Ú distribution)Úchain)Ú Requirementc@s eZdZdS)ÚPkgReqN)Ú__name__Ú __module__Ú __qualname__©rrúF/usr/lib/python3.9/site-packages/ansible/galaxy/collection/__init__.pyr%srFT)Ú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)Ú 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)Ú raise_from)Ú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\+)?(?:(?P\d+)|(?Pall))$cs:eZdZUdZeeed<dZeed<‡fdd„Z ‡Z S)ÚManifestControlNÚ directivesFÚomit_default_directivescs6t|ƒD](}t||jƒdurtƒ |j| ¡¡qdS©N)Ú dc_fieldsÚgetattrrÚsuperÚ __setattr__Útype)ÚselfZfield©Ú __class__rrÚ __post_init__–s zManifestControl.__post_init__) rrrrWÚlistÚstrÚ__annotations__rXÚboolrbÚ __classcell__rrr`rrV‘s  rVc@s6eZdZd dd„Zdd„Zdd„Zd d „Zd d „ZdS)ÚCollectionSignatureErrorNFcCs"||_||_||_||_d|_dSrY)ÚreasonsÚstdoutÚrcÚignoreÚ_reason_wrapper)r_rirjrkrlrrrÚ__init__ s z!CollectionSignatureError.__init__cCsd|›d|j›d|j›�S)NzUnexpected error for 'z<': GnuPG signature verification failed with the return code z and output )rkrj©r_Úcollection_namerrrÚ_report_unexpected¨s ÿÿÿz+CollectionSignatureError._report_unexpectedcCs d|›d|j›d�}|| ¡S)Nú#Signature verification failed for 'z' (return code z):)rkÚ_format_reasons)r_rpÚheaderrrrÚ_report_expected®sz)CollectionSignatureError._report_expectedcs<ˆjdurtjddd�ˆ_‡fdd„ˆjDƒ}dd |¡S)Nz * z )Úinitial_indentÚsubsequent_indentcsg|]}d ˆj |¡¡‘qS)Ú )ÚjoinrmÚwrap)Ú.0Úreason©r_rrÚ ¹sÿz.rx)rmÚtextwrapZ TextWrapperriry)r_Zwrapped_reasonsrr}rrs²s þ þz(CollectionSignatureError._format_reasonscCs|jr| |¡S| |¡SrY)rirurqrorrrÚreportÀs zCollectionSignatureError.report)NNNF)rrrrnrqrursr€rrrrrhŸs  rhc@seZdZdd„ZdS)ÚCollectionVerifyResultcCs||_d|_dS)NT)rpÚsuccessrorrrrnÉszCollectionVerifyResult.__init__N)rrrrnrrrrr�Èsr�c Cs t|jƒ}t|jdd�}t dj|d�¡t djt|jƒd�¡g}|du}t t |¡}t t |¡}|s |j |j kr dj|j|j |j d �} t | ¡d |_ |St j t|dd�t¡} t|jƒ} |rè|jdurèd d „|jd Dƒ| } n|�s|j�rt|jƒ| } |jdu} | �s&| �r&t d¡n<| �rbt|j| | |j|j|jƒ�sRd |_ |St d|›�¡|�rr|tƒ} nt| �rŠ|j�rŠ|tƒ} n\|j�r˜|jn|j|ƒ}t djt|ƒd�¡t t|¡}t t|¡}|tƒ} t |t| |ƒt dj| d�¡|tƒ}|d}|d}|d|d}t ||||ƒ||ƒ}t!ƒ}t j |d¡t j |d¡h}|dD]€}|d}|ddk�r´| "t j |t|dd�¡¡|d|d}t ||||ƒ|ddk�r`| "t j |t|dd�¡¡�q`t  #|¡D]´\}}}|D]N}t j ||¡}t|t$|ƒdd…dd�}||v�rú| %t&|ddd �¡�qú|D]N}t j ||¡}t|t$|ƒdd…dd�}||v�rN| %t&|d!d"d �¡�qN�qì|�rúd |_ t d#jt|jƒd$�¡|D],}t d%|j'¡t (d&|j)|j*f¡�qÊn"|�rd'nd(}t d)j||d*�¡|S)+a5Verify 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©ÚerrorszVerifying '{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}')Z local_fqcnZ local_verZ remote_verFcSsg|] }|d‘qS)Ú signaturer)r{Úinforrrr~ûóz+verify_local_collection..Ú signatureszòThe 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_hashrrz chksum_%sró MANIFEST.jsonó FILES.jsonr.rÚfileÚdirrPzthe file does not existzthe file existsrRzthe directory does not existzthe directory existszECollection {fqcn!s} contains modified content in the following files:©Úfqcnz %sz Expected: %s Found: %sz+are internally consistent with its manifestzmatch the remote collectionz=Successfully verified that checksums for '{coll!s}' {what!s}.)r‡Úwhat)+r�r”rFÚsrcÚdisplayrrHÚ functoolsÚpartialr3Ú_get_file_hashÚverr‚Úosr‰ryÚMANIFEST_FILENAMErcr�Z source_infoÚkeyringÚwarningÚverify_file_signaturesÚ#required_successful_signature_countÚignore_signature_errorsÚvvvvÚis_concrete_artifactÚget_artifact_pathÚget_galaxy_artifact_pathÚvvvÚ_get_json_from_tar_fileÚ_get_tar_file_hashÚ_verify_file_hashÚsetÚaddÚwalkÚlenÚappendrQrSÚvrTrU)Úlocal_collectionÚremote_collectionÚartifacts_managerÚresultÚb_collection_pathZmodified_contentZverify_local_onlyZget_json_from_validation_sourceZget_hash_from_validation_sourceÚerrÚ manifest_filer�Zkeyring_configuredrŽZb_temp_tar_pathÚmanifestZfile_manifest_dataZfile_manifest_filenameÚ expected_hashÚ file_manifestZcollection_dirsZcollection_filesZ manifest_datarÚrootÚdirsr.Ú full_pathr‰Zcontent_changer•rrrÚverify_local_collectionÎsê ÿÿ   üÿ    ÿú  ÿ üÿ    þ ÿÿ  ÿ  ÿ þÿÿÿr¾c Cs\d}g}t t|¡ ¡}|dp"d} |d} |d} | durDt| ƒ} |D]„} t| dd�} zt|| ||ƒWnFty°} z.| jrŒWYd} ~ qH|  |   |¡¡WYd} ~ qHd} ~ 00|d7}| rÀqH|| krHqÎqH| rî|sîd}t   d |›d �¡nN| �r| }|�s¢sÿz&install_collections..c3s6|].}|jr(‡fdd„ˆ |¡ ¡Dƒn|fVqdS)c3s|]}t |ˆ¡VqdSrY)r Ú from_dir_path)r{Zsub_coll©r³rrÚ ©sÿz0install_collections...N)Z is_subdirsZ"get_direct_collection_dependenciesrÌ)r{Z install_reqrrrr¨s ÿø ÿýz&install_collections..cSsh|] }|j’qSrr“)r{ÚreqrrrrµrŒcs4h|],}ˆD]"}|j|jkr t|j|jƒr |’q qSr)r”rCr›)r{rZexs)Úexisting_collectionsrrr¹sýzxNothing to do. All requested collections are already installed. If you want to reinstall them, consider using `--force`.Ncsh|]}|jˆvr|’qSrr“r)Úrequested_requirements_namesrrrÊs ÿcSs$h|]}t|j|j|j|jdƒ’qSrY)rAr”r›r–r^rrrrrÔsÿzProcess install dependency maprÞz#Starting collection install processzEncountered {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 Ú from_iterabler—rìríržrïrðr£rrHr�rŸr^Zwith_signatures_repopulatedÚinstallr/)rèrör÷Ú ignore_errorsrârØZ force_depsrärãr³Zdisable_gpg_verifyræZunsatisfied_requirementsZ"existing_non_requested_collectionsZpreferred_requirementsZpreferred_collectionsZdependency_mapZkeyring_existsr”rør¶r)r³r r rÚinstall_collections‰s’þ öÿþÿ ÿýý ÷$  ÿÿ ÿÿÿ üÿ rcCs.| d¡\}}}t |¡r|Std|ƒ‚dS)zöValidates 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. ú:z®Invalid collection name '%s', name must be in the format .. Please make sure namespace and collection name contains characters from [a-zA-Z0-9_] only.N)Ú partitionrKZis_valid_collection_namer/)rÚ collectionÚdummyrrrÚvalidate_collection_names  ýrcCs&tj |¡ddkr"tj |d¡S|S)zÜEnsure 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. rPZansible_collections)rœr‰rÿry)rrrrÚvalidate_collection_path'src Cs2g}t||ƒ}tƒ��|D�]î}�zž|jr@tdj|jd�d�‚d|j} |D]„} ttj   | |j |j ¡dd�} tj   | ¡s|qNt| ƒs�d|j} qNt | |¡} dd „|jpªgDƒ} t| j| j| j| jt| ƒd �} qÞqNt| d�‚|rèd }nÂ| | ¡}| d d „|j�pgDƒ¡t|j|jd k�r&|jn| jd dt|ƒƒ}z |jd u�sL|�sV| |¡WnPt�y¨}z6dj|d�}|j|k�r’tdj|d�ƒ‚‚WYd }~n d }~00t| ||ƒ}| |¡Wqt�y }z.|�rôt dj|t|ƒd�¡n‚WYd }~qd }~00qWd ƒn1�s$0Y|S)aMVerify 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.)Z coll_type)Úmessagez>Collection %s is not installed in any of the collection paths.rƒr„zŠCollection %s does not have a MANIFEST.json. A MANIFEST.json is expected if the collection has been built and installed via ansible-galaxycSsg|]}t|tƒ‘qSr©r9r—©r{Úsourcerrrr~msÿz&verify_collections..)r�NcSsg|]}t|tƒ‘qSrrrrrrr~�sÿÚ*r 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¶)r6rìr¤r/rr^r”rFrœr‰ryr rrÕrBrArZsignature_sourcesr›r–Ú frozensetZget_signaturesÚextendržZget_collection_version_metadatarr¾r¯r—rŸrH)rèZ search_pathsr÷rZlocal_verify_onlyr³ÚresultsZ api_proxyrZ default_errÚ search_pathZ b_search_pathr±Zsupplemental_signaturesr²r�ÚeZexpected_error_msgr´r¶rrrÚverify_collections4s¨   þÿ þû þÿÿþû    þû ÿÿÿ þÿ ýÿ:r!c cs<tjttjdd�d�}z|VWt |¡n t |¡0dS)Nrƒr„)r’)ÚtempfileZmkdtemprFÚCZDEFAULT_LOCAL_TMPróÚrmtree)Ú b_temp_pathrrrÚ_tempdir¹sr&ccsàtj}|durtj ¡n|}|dur.t |¡|s.progressc@seZdZdd„Zdd„ZdS)z(_display_progress..DisplayThreadcSs ||_dSrY)r2)r_r2rrrrnèsz1_display_progress..DisplayThread.__init__cs‡‡fdd„}|S)Ncsˆj ˆ||f¡dSrY)r2Zput)r6r7©Úattrr_rrÚ call_displayìszJ_display_progress..DisplayThread.__getattr__..call_displayr)r_r;r<rr:rÚ __getattr__ësz4_display_progress..DisplayThread.__getattr__N)rrrrnr=rrrrÚ DisplayThreadæsr>)Útargetr6T)r#ZGALAXY_DISPLAY_PROGRESSÚsysrjÚisattyr—Úobjectr1ZQueuer,ÚThreadÚdaemonÚstartr*ryÚ Exception)rÉZconfig_displayZ display_wheelr9r>Z old_displayr2r3rrrrìÂs2   ÿ  rìcCs€ttj t|ƒ|¡dd�}tj |¡s,d}n4t|dd��}t|ƒ}Wdƒn1sV0Y||kr|| t |||d�¡dS)Nrƒr„ÚrbrêrR) rFrœr‰ryrHÚisfilerôr1r¯rQ)Úb_pathrSr¹Z error_queueZ b_file_pathÚ actual_hashZ file_objectrrrrªs &rªcCsddddtdœgtdœS)NÚ.r’rr-©ÚMANIFEST_FORMATrrrrÚ_make_manifestsûÿ örNr c Cs&d|d|d|r|ndd|›�|dtiS)NrrrZchksum_rrL)rrrÚchksumrrrÚ _make_entry"s   ûrPcCs8|r|turtdƒ‚|tur*t||||ƒSt||||ƒS)Nz4"build_ignore" and "manifest" are mutually exclusive)rOr/Ú_build_files_manifest_distlibÚ_build_files_manifest_walk)rµr rÚignore_patternsÚmanifest_controlrrrrÓ,s ürÓc Cs~ts tdƒ‚|duri}ztfi|¤Ž}Wn2ty\}ztd|›�ƒ‚WYd}~n d}~00t|jƒs|td|jjj›�ƒ‚t|j t ƒsœtd|j jj›�ƒ‚|j r°|js°tdƒ‚g}|j rÈ|  |j¡n’|  gd¢¡t dd„t ƒDƒƒ}t|ƒD].}|d v�rqòqò|tjvrò| d |›d �¡qò|  d d g¡|  |j¡|  d|›d|›d�ddg¡t d¡t t d |¡d¡¡t|dd�} t| ƒ} |D]|} z|  | ¡Wnft�yÚ} ztd| ›�ƒ‚WYd} ~ n.)ÚmodulesZ module_utilszrecursive-include plugins/z **.yml **.yamlz7recursive-include plugins/modules **.ps1 **.yml **.yamlz;recursive-include plugins/module_utils **.ps1 **.psm1 **.csz8exclude galaxy.yml galaxy.yaml MANIFEST.json FILES.json ú-z -*.tar.gzz!recursive-exclude tests/output **zglobal-exclude /.* /__pycache__zManifest Directives:rxz rƒr„zInvalid manifest directive: z-Unknown error processing manifest directive: T)Zwantdirsr’r‘r ©Z hash_func©rrOr.)$Ú HAS_DISTLIBr/rVÚ TypeErrorrIrWrarÚ isinstancerXrfrr«rDÚsortedr#ZDOCUMENTABLE_PLUGINSr¯r—r§rÚindentryrHrZprocess_directiverrFrNrœr‰ÚrelpathrÕrPrMr )rµr rrTZcontrolÚexrWZpluginsZpluginr×ÚmZ directiver r¸Zabs_pathÚrel_pathZmanifest_entryrrrrQ<s„$  ÿÿ ÿ     ÿþ ý  "(  ürQc sfddddddddtd  ||¡ƒg ‰ˆd d „|Dƒ7‰tgd ¢ƒ‰tƒ‰‡‡‡‡fd d„‰ˆ||ƒˆS)Nr�r�s galaxy.ymls galaxy.yamló.gits*.pycs*.retrys tests/outputz{0}-{1}-*.tar.gzcSsg|] }t|ƒ‘qSr)rF©r{Úprrrr~­rŒz._build_files_manifest_walk..)sCVSs.bzrs.hgrfs.svns __pycache__s.toxc s^t |¡D�]L‰tj |ˆ¡}||kr*dn|t|ƒdd…}tj |ˆ¡‰tˆdd�}tj |¡�r t‡fdd„ˆDƒƒs’t‡fdd„ˆDƒƒr¦t  dt|ƒ¡q tj  |¡rÜtj  |¡}t ||ƒsÜt  d t|ƒ¡q ˆd  t|d ƒ¡tj  |¡�sXˆ||ƒq t‡fd d„ˆDƒƒ�r6t  dt|ƒ¡q ˆd  t|d dt|td�d�¡q dS)NrŒrPrƒr„c3s|]}ˆ|kVqdSrYr)r{rI)Úb_itemrrrºrŒz<_build_files_manifest_walk.._walk..c3s|]}t ˆ|¡VqdSrY©Úfnmatch©r{Z b_pattern©Ú b_rel_pathrrr»rŒz"Skipping '%s' for collection buildzLSkipping '%s' as it is a symbolic link to a directory outside the collectionr.r’c3s|]}t ˆ|¡VqdSrYrjrlrmrrrÌrŒr‘r r[r\)rœÚlistdirr‰ryr®rHrÕÚanyr—r§ÚislinkÚrealpathÚ_is_child_pathrŸr¯rPrMr )rIZb_top_level_dirZ b_abs_pathZb_rel_base_dirreÚ b_link_target©Ú_walkZ b_ignore_dirsZb_ignore_patternsr¸)rirnrrv²s@  ÿ   ÿ  üÿz)_build_files_manifest_walk.._walk)rFrrrN)rµr rrSrrurrRžs ÷  ) rRc KsB|||||||| d|pd|| | | | dœddddtdœtdœ}|S)Nr&)r rr!r"r#r$r%r&r'r(r)r*r+r,ú FILES.jsonr‘r rrrL)r rr!r"r#r$r%r'r(r)r*r+r,r7r¸rrrrÒás0òûèrÒc Cs8ttj|dd�dd�}t|td�|dd<ttj|dd�dd�}tƒ��Ú}tj |tj  |¡¡}t j |dd ���D}t |fd |ffD]F\} } t | ƒ} t  | ¡} t| ƒ| _tt ¡ƒ| _d | _|j| | d �q‚|d D]Ò} | ddkräqÒt| ddd�}tj |t|dd�¡}dd„}tj |¡�r†tj |¡}t||ƒ�r†tjj|tj |¡d�}t  |¡} t j| _t|dd�| _|| ƒ} |j| d�qÒ|jttj |¡ƒ|d|d�qÒWdƒn1�s¼0Yt  !t|ƒt|ƒ¡d|dd|ddf}t"|ƒ}t# #d||f¡|WdƒS1�s*0YdS)z:Build a tar.gz collection artifact from the manifest data.T©rarƒr„r[rrzw:gzrêrwé¤)ÚtarinfoZfileobjr.rrKcSsJ|jtjkr.|jtj@}|s$| ¡r(dnd|_d|_|_d|_ |_ |S)NéíryrÚ) r^ÚtarfileÚSYMTYPErëÚstatÚS_IXUSRrÕÚuidÚgidÚunameÚgname)rzÚexisting_is_execrrrÚ reset_stat!s     z)_build_collection_tar..reset_stat)rE)rzF)ZarcnameÚ recursiveÚfilterNú%s.%srr zCreated collection for %s at %s)$rFÚjsonÚdumpsrNr r&rœr‰ryrñr}rôr�r ZTarInfor®ÚsizerÆr.ÚmtimerëZaddfilerGrqrrrsrbÚdirnamer~r^Úlinknamer¬rórîrHr—)rµZ b_tar_pathrÚrºÚfiles_manifest_jsonÚcollection_manifest_jsonr%Zb_tar_filepathZtar_filerÚbÚb_ioZtar_infoÚ file_inforSrùr†rtrnrpZtar_pathrrrrÖsT          ü(  ÿrÖc Cs¼tj|dd�ttj|dd�dd�}t|td�|dd <ttj|dd�dd�}t|fd |ffD]ˆ\}}tj  |t|dd�¡}t |d ƒ�D} t |ƒ�} t   | | ¡Wd ƒn1s²0YWd ƒn1sÐ0Yt |d ¡q^g} t|ddd„d�D]®} | ddk�r�qtj  |t| ddd�¡} tj  |t| ddd�¡}t | ¡jtj@}|�rfdnd }tj | ¡�r”d}|  | ¡t ||¡n t  | |¡t ||¡�qt|ƒ}|S)z|Build a collection directory from the manifest data. This should follow the same pattern as _build_collection_tar. r{rêTrxrƒr„r[rrrwréNryr.cSs|dS)Nrr)ÚxrrrÚ[rŒz'_build_collection_dir..)ÚkeyrrK)rœÚmakedirsrFrŠr‹rNr r�r‰ryrôr róÚ copyfileobjÚchmodr`rÚst_moder€rÕr¯ÚmkdirÚcopyfilerH)rµrÛrÚrºr�r‘rr’rIZfile_objr“Zbase_directoriesr”Zsrc_fileZ dest_filer…rërÜrrrÚ_build_collection_dirGs2H  ržc csÐt|dd�}t |¡D]´}tj ||¡}tj |¡r6qt |¡D]ˆ}tj ||¡}tj |¡s`q@zt ||¡}Wn2t y¢}zt t |ƒ|ƒWYd}~n d}~00t   djt|ƒt|jƒd�¡|Vq@qdS)z–Locate all collections under a given path. :param path: Collection dirs layout search path. :param artifacts_manager: Artifacts manager. rƒr„Nz1Found installed collection {coll!s} at '{path!s}'rç)rFrœror‰ryrHrÕrAZfrom_dir_path_as_unknownÚ ValueErrorrEr/r—r§rrHr–) r‰r³rIZ b_namespaceÚb_namespace_pathZ b_collectionrµrZval_errrrrr qs&   $ÿÿr cCsÐ|jr |jn|j|ƒ}tj ||j|j¡}t|dd�}t   dj t |ƒ|d�¡tj  |¡rdt  |¡|jrzt||||ƒnòsz$install_artifact..Nrƒr„rwr.rrKrr‘r)r¹)r}rôZ getmembersÚ_ansible_normalized_cacheÚ_extract_tar_filer�rœr‰ryrHr©Ú getmemberr5rŠÚloadsÚreadÚ_extract_tar_dirrFrór$rŽroÚrmdir)Zb_coll_targz_pathrµr%r�ržr¨r¢Úcollection_tarr·Zfiles_member_objrZ files_objr.r”Ú file_namer rrrr¢âs8 ÿ 4  ÿ2    r¢cCsv| |¡}d|vr"g|d<t|d<tfi|¤Ž}t||d|d|d|dƒ}t||||ƒ}t dj||d�¡dS)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 rz+Created collection for {coll!s} at {path!s}rçN)Zget_direct_collection_metarOrÒrÓržr—r)rrµZb_collection_output_pathr³rÙrÚrºZcollection_output_pathrrrr¡s(  üþÿÿr¡c Cst|dd� tjj¡}z|j|}WntyBtd|ƒ‚Yn0tj |t |dd�¡}tj  |¡}ztj |dd�Wn2t yª}z|j t jkr–‚WYd}~n d}~00|jtjkröt |jdd�}t|||d�sètdt|ƒ|fƒ‚t ||¡ntj |¡�st |d¡dS) z- Extracts a directory from a collection tar. rƒr„z&Unable to extract '%s' from collectionr{rêN©Ú link_nameú]Cannot extract symlink '%s' in collection: path points to location outside of collection '%s')rGr«rœr‰r§r­ÚKeyErrorr/ryrFrŽr˜ÚOSErrorÚerrnoZEEXISTr^r}r~r�rsÚsymlinkrÕrœ)ÚtarrŽÚb_destÚ tar_memberZ b_dir_pathÚ b_parent_pathr Ú b_link_pathrrrr²Cs*     ÿr²c Cs²t||ƒ���\}}|jtjkr(t|ƒ}n8tj|dd��}t||ƒ}Wdƒn1sV0Y|rŠ||krŠtdt|dd�t|j ƒfƒ‚t j   t j   |t|dd�¡¡} t j  | ¡} t| |ƒsÒtdt|dd�ƒ‚t j  | ¡sìt j| dd �|jtjk�r:t|jdd�} t| || d ��s,td t|ƒ| fƒ‚t  | | ¡nTt t|j dd�| ¡| t|dd�¡}d } t |j¡tj@�r‚| d O} t  | | ¡Wdƒn1�s¤0YdS)z( Extracts a file from a collection tar. F)r’ÚdeleteNz4Checksum mismatch for '%s' inside collection at '%s'rƒr„zSCannot extract tar entry '%s' as it will be placed outside the collection directoryr{rêr¶r¸ryéI)Ú_get_tar_file_memberr^r}r~r1r"ZNamedTemporaryFiler/rGrrœr‰ÚabspathryrFrŽrsrÔr˜r�r¼róÚmover¯rÚS_IMODErër€rš) r½rSr¾r%r¹r¿Útar_objrJZ tmpfile_objZb_dest_filepathZ b_parent_dirrÁZnew_moderrrr®bs<  ( ÿ   ÿ  ÿr®cCsNt|dd�}z| |¡}Wn(tyBtdt|jƒ|fƒ‚Yn0t||ƒS)Nrƒr„z?Collection tar at '%s' does not contain the expected file '%s'.)rGr¯r¹r/rr5)r½rSZ n_filenameÚmemberrrrrÄ�s  þrÄc Cs”d}tj|dd��h}t||ƒ�>\}}d}| |¡}|rN|t|ƒ7}| |¡}q2Wdƒn1sb0YWdƒn1s€0Yt |¡S)Nr|rªrêi)r}rôrÄr±rHrŠr°)rIrSZ file_contentsr´rrÈÚbufsizeÚdatarrrr¨›s  Hr¨c Csvtj|dd��T}t||ƒ�*\}}t|ƒWdƒWdƒS1sJ0YWdƒn1sh0YdS)Nrªrê)r}rôrÄr1)rIrSr´rrÈrrrr©©sr©cCsLtj |t|dd�¡}t|dƒ�}t|ƒWdƒS1s>0YdS)Nrƒr„rG)rœr‰ryrFrôr1)rIrSÚfilepathÚfprrrrš¯s ršcCspt|dd�}|rFtj |¡sFtj t|dd�¡}tj tj ||¡¡}t|dd�}||kpn| |ttjjƒ¡S)z> Checks that path is a path within the parent_path specified. rƒr„) rFrœr‰ÚisabsrŽrÅryÚ startswithr§)r‰Ú parent_pathr·rIZ b_link_dirrÀrrrrsµs   rsc  stts tdƒ‚tstdƒ‚d} zžz tdƒ} Wnty<Yn 0t‡fdd„| jpRgDƒdƒ} W| dur–ttkrzt ksºntdt j ›dtj ›�ƒ‚n$| j   tj ¡sºtd | j ›| j ›�ƒ‚n`| durôttkrØt ksòntdt j ›dtj ›�ƒ‚n&| j   tj ¡�std | j ›| j ›�ƒ‚0t||||| ||||d � } z| j|d d �jWSt�y¢} z>d d„| jDƒ} ttd| ƒƒ}ttd |¡ƒ| ƒ‚WYd} ~ nÖd} ~ 0t�y<} z‚dd„| j ¡Dƒ}dj| j|�sØdndjd |¡d�d�g}| j ¡D]} | dj| d�¡�qúttd |¡ƒ| ƒ‚WYd} ~ n.z#ansible-galaxy requires resolvelib=zansible-galaxy requires ) rßráZuser_requirementsràZ with_depsZwith_pre_releasesräråræi€„)Z max_roundscss6|].}dj|j|jdurdn dj|jd�d�VqdS)z+* {req.fqcn!s}:{req.ver!s} ({dep_origin!s})Núdirect requestúdependency of {parent!s}©Úparent©rZ dep_origin)rZ requirementrÕ)r{Zreq_infrrrr÷sùÿÿü)z_Failed to resolve the requested dependencies map. Could not satisfy the following requirements:rxcSsg|]}|durt|ƒ‘qSrY)rdrgrrrr~sÿz*_resolve_depenency_map..z¥Failed 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* {req.fqcn!s}:{req.ver!s})r) ÚHAS_RESOLVELIBr/Ú HAS_PACKAGINGr rFrÊZrequiresr?r>r@ZvstringZ specifierÚcontainsrr;ÚresolveÚmappingr<Zcausesrcr rEryr=Z criterionZ iter_parentrÚ candidateZiter_requirementr¯rŸrG)Zrequested_requirementsrßráràrârãrärårærZdistZcollection_dep_resolverZdep_excZconflict_causesZerror_msg_linesÚparentsÚexcrrÑrríÂs–    ÿøÿ÷ þ ø ú þÿÿÿúþ ÿ þrí)N)r N)N)N)¥Ú__doc__Z __future__rrrr^Z __metaclass__r»rkr˜rŠrœr1rÂrórr@r}r"rr,r.Útypingr3rèrÚ contextlibrZ dataclassesrrrZZhashlibr Úior Úimportlib.metadatar Ú itertoolsr Zpackaging.requirementsr rÚ ImportErrorrØZdistlib.manifestrZdistlibrr]Ú TYPE_CHECKINGZ3ansible.galaxy.collection.concrete_artifact_managerrÚLiteralZManifestKeysTypeZFileMetaKeysTypeZCollectionInfoKeysTypeÚDictÚUnionrÆrdÚListZManifestValueTypeZCollectionManifestTypeZFileManifestEntryTypeZFilesManifestTypeZansible.constantsZ constantsr#Zansible.errorsr/Zansible.galaxy.apir0r1r2r3r4r5Z*ansible.galaxy.collection.galaxy_api_proxyr6Zansible.galaxy.collection.gpgr7r8r9r:Z$ansible.galaxy.dependency_resolutionr;Z+ansible.galaxy.dependency_resolution.errorsr<r=Z.ansible.galaxy.dependency_resolution.providersr>r?r@r×Z0ansible.galaxy.dependency_resolution.dataclassesrArBZ/ansible.galaxy.dependency_resolution.versioningrCZansible.plugins.loaderrDZansible.module_utils.sixrEZansible.module_utils._textrFrGrHZ'ansible.module_utils.common.collectionsrIZ ansible.module_utils.common.yamlrJZansible.utils.collection_loaderrKZansible.utils.displayrLZansible.utils.hashingrMrNZansible.utils.sentinelrOr—rMr�rQrÄrVrFrhr�r¾r rÇrÝrúrýrrrr!r&rìrªrNrPrÓrQrRrÒrÖržr rr£r©r¢r¡r²r®rÄr¨r©ršrsrírrrrÚs           ÿÿ÷þ .$               ),2 /j%   C  bC F* 0 8) -