a ì)gpRã@s"ddlmZmZmZeZddlZddlZddlZddl Z ddl Z ddl Z ddl m Z ddlmZddlmZddlmZmZddlmZddlmZdd lmZmZdd lmZmZdd lm Z dd l!m"Z"dd l#m$Z$ddl%m&Z&ddl'm(Z(m)Z)e&ƒZ*ej+e,dœdd„ƒZ-Gdd„de.ƒZ/dS)é)Úabsolute_importÚdivisionÚprint_functionN)ÚMutableSequence)Úrmtree)Úcontext)Ú AnsibleErrorÚAnsibleParserError)Ú GalaxyAPI)Ú user_agent)Ú to_nativeÚto_text)Ú yaml_dumpÚ yaml_load)Ú LooseVersion)Úopen_url)ÚRoleRequirement)ÚDisplay)Ú is_subpathÚ unfrackpath)ÚreturncCsTd}ttdƒrPt d¡}tj|_d|_zt |d¡WntjyJYn0d}|S)zj Check if tarfile.data_filter implementation is working for the current Python version or not FÚ data_filterzdocs/README.mdz ../README.mdz/fooT)ÚhasattrÚtarfileZTarInfoZSYMTYPEÚtypeÚlinknamerZLinkOutsideDestinationError)ÚretZti©rú7/usr/lib/python3.9/site-packages/ansible/galaxy/role.pyÚ_check_working_data_filter2s   rc@sðeZdZeddgƒZej dd¡ej dd¡fZej dd¡Z ej dd¡ej dd¡fZ d Z d'd d „Z d d„Z dd„Zedd„ƒZedd„ƒZedd„ƒZedd„ƒZedd„ƒZdd„Zdd„Zdd „Zd!d"„Zed#d$„ƒZed%d&„ƒZd S)(Ú GalaxyRoleÚgitZhgÚmetazmain.ymlz main.yamlz.galaxy_install_infozrequirements.ymlzrequirements.yaml)ÚdefaultsÚfilesÚhandlersr"ZtasksZ templatesÚvarsZtestsNc sþdˆ_dˆ_dˆ_dˆ_tjd ˆ_t dˆj¡|ˆ_ |ˆ_ |ˆ_ |ˆ_ |pT|ˆ_ dˆ_|ˆ_‡fdd„|jDƒˆ_|durî| tj tjjˆj ¡¡s®tj |ˆj ¡}n8ˆjD]0}tj tj |||¡¡r´tj |ˆj ¡}qæq´|ˆ_n ˆjdˆ_dS)NZ ignore_certszValidate TLS certificates: %scsg|]}tj |ˆj¡‘qSr)ÚosÚpathÚjoinÚname)Ú.0Úx©ÚselfrrÚ fóz'GalaxyRole.__init__..r)Ú _metadataÚ_metadata_dependenciesÚ _requirementsÚ _install_inforÚCLIARGSÚ_validate_certsÚdisplayÚdebugÚgalaxyÚ_apir*ÚversionÚsrcÚ download_urlÚscmZ roles_pathsÚpathsÚendswithr'r(r)ÚsepÚ META_MAINÚexists) r.r9Úapir*r<r;r>r(Ú meta_mainrr-rÚ__init__Ts.  zGalaxyRole.__init__cCs |jrd|j|jfS|jSdS)zj Returns "rolename (version)" if version is not null Returns "rolename" otherwise z%s (%s)N)r;r*r-rrrÚ__repr__zszGalaxyRole.__repr__cCs |j|jkS©N)r*)r.ÚotherrrrÚ__eq__„szGalaxyRole.__eq__cCst|jtƒs|jjS|jSrH)Ú isinstancer:r rDr-rrrrD‡s zGalaxyRole.apic Cs¨|jdur¢|jD]�}|jD]„}tj ||¡}tj |¡rz8t|dƒ�}t|ƒ|_Wdƒn1sd0YWn(t y˜t   d|j ¡YdS0qqq|jS)z' Returns role metadata NÚrzUnable to load metadata for %sF) r1r?rBr'r(r)ÚisfileÚopenrÚ Exceptionr7Úvvvvvr*)r.r(rEÚ meta_pathÚfrrrÚmetadata�s     ,  zGalaxyRole.metadatacCsT|jdur,g|_|jdur,|j d¡p(g|_t|jtƒsNtd|›d|j›�ƒ‚|jS)zC Returns a list of dependencies from role metadata NZ dependenciesú.Expected role dependencies to be a list. Role z% has meta/main.yml with dependencies )r2rSÚgetrKrr r-rrrÚmetadata_dependencies¡s   ÿz GalaxyRole.metadata_dependenciescCsŽ|jdurˆtj |j|j¡}tj |¡rˆzTzt|dƒ}t|ƒ|_Wn.typt   d|j ¡YW|  ¡dS0W|  ¡n |  ¡0|jS)z+ Returns role install info NrLz)Unable to load Galaxy install info for %sF) r4r'r(r)Ú META_INSTALLrMrNrrOr7rPr*Úclose)r.Ú info_pathrRrrrÚ install_info³s    þzGalaxyRole.install_infocCs"|jD]}tj |¡rdSqdS)NTF)r?r'r(Úisdir)r.r(rrrÚ_existsÆs  zGalaxyRole._existsc Csºt|jtj ¡ d¡d�}tj tj |jd¡¡sHt  tj |jd¡¡tj |j|j ¡}t |dƒ�B}zt ||ƒ|_ Wn ty–YWdƒdS0Wdƒn1s¬0YdS)zÏ Writes a YAML-formatted file to the role's meta/ directory (named .galaxy_install_info) which contains some information we can use later for commands like 'list' and 'info'. z%c)r;Z install_dater"zw+NFT)Údictr;ÚdatetimeZutcnowÚstrftimer'r(rCr)ÚmakedirsrWrNrr4rO)r.ÚinforYrRrrrÚ_write_galaxy_install_infoÎsþ  2z%GalaxyRole._write_galaxy_install_infocCs.|jr*zt|jƒWdSty(Yn0dS)zÒ Removes the specified role from the roles path. There is a sanity check to make sure there's a meta/main.yml file at this path so the user doesn't blow away random directories. TF)rSrr(rOr-rrrÚremoveäs  zGalaxyRole.removec CsÞ|rÚ|jdur|j}n0d|vr@d|vr@d|d|d|jf}n|j}t d|¡zNt||jtƒd�}tjdd�}|  ¡}|r”|  |¡|  ¡}q||  ¡|j WSt yØ}zt d t|ƒ¡WYd}~n d}~00dS) zS Downloads the archived role to a temp location based on role data NZ github_userZ github_repoz*https://github.com/%s/%s/archive/%s.tar.gzz- downloading role from %s)Zvalidate_certsZ http_agentF)Údeletezfailed to download the file: %s)r=r;r<r7rr6r ÚtempfileZNamedTemporaryFileÚreadÚwriterXr*rOÚerrorr )r.Ú role_dataZ archive_urlZurl_fileZ temp_fileÚdataÚerrrÚfetchós&    (zGalaxyRole.fetchc Csö|jr&tjfdtjdi|j¤Ž}�nÔ|j�ròtj  |j¡rF|j}�qúd|jvrd|j}|  |¡}�qú|j   |j¡}|sŒt d|j|j jfƒ‚| d¡dkrªt d|j¡|j  d|d¡}|j�sPt|ƒd k�r.d d „|Dƒ}z | ¡Wn0t�yt d d  dd „|Dƒ¡ƒ‚Yn0t|dƒ|_n | dd¡�rH|d|_nd|_nB|jdk�r’|�r’t|jƒdd „|Dƒv�r’t d|j|j|fƒ‚|D]N}|d|jk�r¾d|v�r¾|d|_|d|jk�r–d|v�r–|d|_�q–|  |¡}nt dƒ‚|�ròt d|¡t |¡�s&t dƒ‚�nÌt |d¡}d}| ¡}|D]`} |j D]R} | | jv�rLtj !tj !| j¡¡} |�s‚| } | }nt| ƒt| ƒk�rL| } | }�qL�qB|�s´t dƒ‚n2zt"| #|¡ƒ|_$Wnt%�yät dƒ‚Yn0|j&} |j| d k�r |j| dd …<t| ƒ}t'| ƒD�]V\}}||_t d|j|jf¡�zÆtj (|j¡�r¨tj )|j¡�snt dƒ‚n8tj dd ¡�sŽt d!|jƒ‚n| *¡�s´t d"|jƒ‚n t +|j¡t,| d d#�}|D�].} |  -¡�sâ|  .¡�sâ�qÄd$D]Ø}t/| |dƒ}�s�qæ|d%k�r tj !t/| dd&ƒ¡}n&| 0| d&d'¡}tjj| 1tj2¡Ž}d&}tj |||¡}t3||d(d)��s„d*|›d+|›d,|›�}t |ƒ‚tj ||¡}tjj| 0|d&d'¡ 1tj2¡Ž}t4| ||ƒ�qæt5ƒ�rà|j6| t7|jƒd-d.�n| 6| t7|jƒ¡�qÄ| 8¡W�qtWnft9�yn}zL|j:t:j;k�rD||d'k�rDWYd}~�qt d/|jt7|ƒfƒ‚WYd}~n d}~00�qt d0t<|ƒ¡|j�ržtj  |j¡�sîzt =|¡Wn@t9t>f�yì}z"t d1|t|ƒf¡WYd}~n d}~00d(Sd S)2NZ keep_scm_metaz://z - sorry, %s was not found on %s.Z role_typeZAPPzP%s is a Container App role, and should only be installed using Ansible ContainerZversionsÚidrcSsg|]}t| dd¡ƒ‘qS©r*N)rrU©r+Úarrrr/-r0z&GalaxyRole.install..zÞUnable to compare role versions (%s) to determine the most recent version due to incompatible version formats. Please contact the role author to resolve versioning conflicts, or specify an explicit role version to install.z, cSsg|] }|j‘qSr)Zvstring)r+Úvrrrr/4r0éÿÿÿÿZ github_branchZmastercSsg|]}| dd¡‘qSrn)rUrorrrr/<r0zX- the specified version (%s) of %s was not found in the list of available versions (%s).r*Úsourcer=zNo valid role data foundzinstalling from %sz>the downloaded file does not appear to be a valid tar archive.rLz7this role does not appear to have a meta/main.yml file.z=this role does not appear to have a valid meta/main.yml file.z- extracting %s to %sz7the specified roles path exists and is not a directory.ÚforceFzJthe specified role %s appears to already exist. Use --force to replace it.zu%s doesn't appear to contain a role. please remove this directory manually if you really want to put the role here.)Úfollow)r*rrÚéT)ÚrealzInvalid z for tarfile member: path z is not a subpath of the role rj)Úfilterz Could not update files in %s: %sz- %s was installed successfullyz"Unable to remove tmp file (%s): %s)?r>rZscm_archive_rolerr5Úspecr<r'r(rMrlrDZlookup_role_by_namerZ api_serverrUr7Zwarningr*Zfetch_role_relatedr;ÚlenÚsortÚ TypeErrorr)r r=r8rZ is_tarfilerNZ getmembersrBÚdirnamerZ extractfiler1rOr?Ú enumeraterCr[rcr`rZisregZissymÚgetattrÚreplaceÚsplitrArÚsetattrrÚextractr rbÚOSErrorÚerrnoZEACCESÚstrÚunlinkÚIOError)r.Ztmp_fileriZ role_versionsZloose_versionsZ role_versionZ role_tar_fileZ meta_fileÚmembersÚmemberrEZmeta_parent_dirZarchive_parent_dirr?Z paths_lenÚidxr(Zresolved_archiveÚattrZ attr_valueÚ relative_toÚ full_pathÚerrZrelative_path_dirÚ relative_pathrkrrrÚinstallsò   ÿ þÿ    þ           ÿ     0,zGalaxyRole.installcCst|j|j|j|jd�S)zÈ Returns role spec info { 'scm': 'git', 'src': 'http://git.example.com/repos/repo.git', 'version': 'v1.0', 'name': 'repo' } )r>r<r;r*)r]r>r<r;r*r-rrrrzÂs zGalaxyRole.specc Cs¸|jdur�g|_|jD]x}tj |j|¡}tj |¡rzHzt|dƒ}t|ƒ|_Wn"tyrt   d|j ¡Yn0W|  ¡n |  ¡0q�qt |jtƒs²td|›d|j›�ƒ‚|jS)z+ Returns role requirements NrLz"Unable to load requirements for %srTz has meta/requirements.yml )r3ÚMETA_REQUIREMENTSr'r(r)rMrNrrOr7rPr*rXrKrr )r.Zmeta_requirementsrQrRrrrÚ requirementsÏs      zGalaxyRole.requirements)NNNN)Ú__name__Ú __module__Ú __qualname__ÚsetZSUPPORTED_SCMSr'r(r)rBrWr“Z ROLE_DIRSrFrGrJÚpropertyrDrSrVrZr\rbrcrlr’rzr”rrrrr Ls6  &      2 r )0Z __future__rrrrZ __metaclass__r†r^Ú functoolsr'rreÚcollections.abcrÚshutilrZansiblerZansible.errorsrr Zansible.galaxy.apir Zansible.galaxy.user_agentr Zansible.module_utils._textr r Z ansible.module_utils.common.yamlrrZ#ansible.module_utils.compat.versionrZansible.module_utils.urlsrZ!ansible.playbook.role.requirementrZansible.utils.displayrZansible.utils.pathrrr7ÚcacheÚboolrÚobjectr rrrrÚs0