HEX
Server: LiteSpeed
System: Linux kapuas.iixcp.rumahweb.net 5.14.0-427.42.1.el9_4.x86_64 #1 SMP PREEMPT_DYNAMIC Fri Nov 1 14:58:02 EDT 2024 x86_64
User: mirz4654 (1666)
PHP: 8.1.33
Disabled: system,exec,escapeshellarg,escapeshellcmd,passthru,proc_close,proc_get_status,proc_nice,proc_open,proc_terminate,shell_exec,popen,pclose,dl,pfsockopen,leak,apache_child_terminate,posix_kill,posix_mkfifo,posix_setsid,posix_setuid,posix_setpgid,ini_alter,show_source,define_syslog_variables,symlink,syslog,openlog,openlog,closelog,ocinumcols,listen,chgrp,apache_note,apache_setenv,debugger_on,debugger_off,ftp_exec,dll,ftp,myshellexec,socket_bind,mail,posix_getwpuid
Upload Files
File: //lib/python3.9/site-packages/ansible/cli/__pycache__/galaxy.cpython-39.pyc
a

�)gk�@s�ddlmZmZmZeZddlmZddlZddl	Z	ddl
ZddlZddl
Z
ddlZddlZddlZddlZddlmZddlmZddlmZddlmZddlmZddlm Z m!Z!dd	l"m#Z#m$Z$dd
l%m&Z&m'Z'ddl(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1ddl2m3Z3dd
l4m5Z5ddl6m7Z7ddl8m9Z9ddl:m;Z;m<Z<m=Z=m>Z>ddl?m@ZAddlBmCZCddlDmEZEmFZFddlGmHZHmIZImJZJddlKmLZLddlMmNZNddlOmPZPddlQmRZRddlSmTZTddlUmVZVddlWmXZXddlYmZZZeX�Z[eLj\j]j^j_Z_gd�Z`ddid d!d"igid#d!d$igd%�ddid&�Zad'd(�Zbd<d+d,�Zcd-d.�Zdd=d/d0�Zed1d2�Zfd3d4�ZgeGd5d6�d6��ZhGd7d8�d8e�Zid>d9d:�Zjekd;k�r�ej�dS)?�)�absolute_import�division�print_function)�CLIN)�	dataclass)�	YAMLError)�context)�option_helpers)�AnsibleError�AnsibleOptionsError)�Galaxy� get_collections_galaxy_meta_info)�	GalaxyAPI�GalaxyError)	�build_collection�download_collections�find_existing_collections�install_collections�publish_collection�validate_collection_name�validate_collection_path�verify_collections�SIGNATURE_COUNT_RE)�ConcreteArtifactsManager)�
GPG_ERROR_MAP)�Requirement)�
GalaxyRole)�BasicAuthToken�GalaxyToken�
KeycloakToken�NoTokenSentinel)�__version__)�is_iterable)�	yaml_dump�	yaml_load)�to_bytes�	to_native�to_text)�six)�
DataLoader)�
AnsibleLoader)�RoleRequirement)�Templar)�AnsibleCollectionConfig)�Display)�get_versioned_doclink)	)�urlT�str)�usernameFr1)�passwordFr1)�tokenFr1)�auth_urlFr1)�v3F�bool)�validate_certsFr7)�	client_idFr1)�timeoutF�int�default�False�cli�namer8Z60r:)r<r>)r6r8r:r4cst����fdd��}|S)z�Inject an artifacts manager if not passed explicitly.

    This decorator constructs a ConcreteArtifactsManager and maintains
    the related temporary directory auto-cleanup around the target
    method invocation.
    cs�d|vr�|i|��Sdtjdi}tj�dd�}|durf|�t�|�tj�dd�tj�dd�d��tjtj	fi|���&}||d<�|i|��Wd�S1s�0YdS)N�artifacts_managerr8�resolved_validate_certs�keyring�required_valid_signature_count�ignore_gpg_errors)rBZrequired_signature_countZignore_signature_errors)
r�CLIARGS�get�update�	GalaxyCLI�
_resolve_pathrZunder_tmpdir�CZDEFAULT_LOCAL_TMP)�args�kwargsZartifacts_manager_kwargsrBZconcrete_artifact_cm��wrapped_method��6/usr/lib/python3.9/site-packages/ansible/cli/galaxy.py�method_wrapper`s$���z9with_collection_artifacts_manager.<locals>.method_wrapper)�	functools�wraps)rNrQrOrMrP�!with_collection_artifacts_managerYsrT�
�cCsBt�dj|||dtt|�|g�dtt|�|g�||d��dS)Nz)
# {0}
{1:{cwidth}} {2:{vwidth}}
{3} {4}
�-)�cwidth�vwidth)�display�format�max�len)�pathZh1Zh2Zw1Zw2rOrOrP�_display_headerys�r_cCs:|j}d}|r|�dd�}|s"d}t�d|j|f�dS)N�versionz(unknown version)z- %s, %s)�install_inforFrZr?)�grrar`rOrOrP�
_display_role�srcc	Cs0t�djt|j�|jt||�t||�d��dS)Nz"{fqcn:{cwidth}} {version:{vwidth}})�fqcnr`rXrY)rZr[r'rd�verr\)�
collectionrXrYZ
min_cwidthZ
min_vwidthrOrOrP�_display_collection�s�rgcCsRt|�s|f}dd�|D�}dd�|D�}tt|td��}tt|td��}||fS)NcSsh|]}t|j��qSrO)r'rd��.0�crOrOrP�	<setcomp>��z)_get_collection_widths.<locals>.<setcomp>cSsh|]}t|j��qSrO)r'rerhrOrOrPrk�rl��key)r"r]r\)�collectionsZfqcn_setZversion_setZfqcn_lengthZversion_lengthrOrOrP�_get_collection_widths�srpcCs&t�t|�}|dur"t|�d���|S)Nz% is not a valid signature count value)�re�matchr�
ValueError)�valuerrrOrOrP�validate_signature_count�sruc@s8eZdZUejedfed<eeed<edd��Z	dS)�RoleDistributionServerN�_api�api_serversc	Csb|jr|jS|jD]6}zd|jvr.||_WqJWqtyFYqYq0q|js\|jd|_|jS)NZv1r)rwrx�available_api_versions�	Exception)�selfZserverrOrOrP�api�s


zRoleDistributionServer.api)
�__name__�
__module__�__qualname__�t�Unionr�__annotations__�list�propertyr|rOrOrOrPrv�s
rvcs�eZdZdZdZdZ�fdd�Z�fdd�Zdad	d
�Zdbdd�Z	dcd
d�Z
dddd�Zdedd�Zdfdd�Z
dgdd�Zdhdd�Zdidd�Zdjdd�Zdkdd�Zdldd �Zdmd!d"�Z�fd#d$�Z�fd%d&�Zed'd(��Zd)d*�Zdnd,d-�Zd.d/�Zedod1d2��Zed3d4��Zed5d6��Zed7d8��Z dpd9d:�Z!d;d<�Z"d=d>�Z#d?d@�Z$e%dqdAdB��Z&dCdD�Z'dEdF�Z(e%drdGdH��Z)e%dsdIdJ��Z*dKdL�Z+dMdN�Z,dOdP�Z-dQdR�Z.dSdT�Z/e%dtdUdV��Z0dWdX�Z1dYdZ�Z2d[d\�Z3d]d^�Z4d_d`�Z5�Z6S)urHz�Command to manage Ansible roles and collections.

       None of the CLI tools are designed to run concurrently with themselves.
       Use an external scheduler and/or locking to ensure there are no clashing operations.
    zansible-galaxy)r?�descriptionZreadme_htmlZrelated�summary_fieldsZaverage_aw_compositeZaverage_aw_scorer0cs�||_d|_t|�dkrz|ddvrFd|vrFd|vrF|�dd�d|_|dd�ddgkrzt�d	�ttj	���t
�d�g|_d|_
d|_tt|��|�dS)
NF�)z-hz--helpz	--version�rolerfT�Zlogina$The login command was removed in late 2020. An API key is now required to publish roles or collections to Galaxy. The key can be found at https://galaxy.ansible.com/me/preferences, and passed to the ansible-galaxy CLI via a file at {0} or (insecurely) via the `--token` command-line argument.)�	_raw_args�_implicit_roler]�insertrZ�errorr[r'rJZGALAXY_TOKEN_PATH�sys�exitrx�galaxy�
lazy_role_api�superrH�__init__)r{rK��	__class__rOrPr��s"��
zGalaxyCLI.__init__c
sBtt|�jdd�tjjdd�}|jddddd	�|jd
ddd
d	�|jddddddd�|jddtddd�t�|�tjjdd�}|jddddddd�tjjdd�}|jdd d!�|jd"d#d!�tjjdd�}|jd$d%ddd&d'�t	j
�d(��d)d*�}tjjdd�}|jd+d,d-tj
d.d/�t	jtjd0|d1�tjjdd�}|jd+d2d3tj
d.d/�tjtjd4�tjj�d1�tjjdd�}|jd5d6ddd7d�|jd8d9ddd:d�|jjd;d<d=�}	d.|	_|	jd>d?d!�}
|
j|jd@�|
jdAdBd=�}d.|_|j|||gdC�|j|||gdC�|j|||gdC�|j||gdC�|j ||||gdC�|j!|||gdC�|j"|||gdC�|	jdDdEd!�}|j|j#d@�|jdFdBd=�}
d.|
_|j|
|||gdC�|j$|
||gdC�|j%|
||gdC�|j!|
||gdC�|j&|
|gdC�|j'|
||gdC�|j(|
||gdC�|j)|
|||gdC�|j |
|||gdC�dS)Gz* create an options parser for bin/ansible z7Perform various Role and Collection related operations.)ZdescF)�add_helpz-sz--server�
api_serverzThe Galaxy API server URL��dest�helpz--tokenz	--api-key�api_keyz[The Ansible Galaxy API key which can be found at https://galaxy.ansible.com/me/preferences.z-cz--ignore-certs�
store_true�ignore_certsz)Ignore SSL certificate validation errors.N)�actionr�r�r<z	--timeoutr:�<zKThe time to wait for operations against the galaxy server, defaults to 60s.�r��typer<r�z-fz--force�forcez0Force overwriting an existing role or collection�r�r�r<r��github_user�GitHub username�r��github_repo�GitHub repository�	--offline�offlinez.Don't query the galaxy API when creating roles)r�r<r�r��DEFAULT_ROLES_PATHr<��-p�--roles-path�
roles_pathT)�pathsepz}The path to the directory containing your roles. The default is the first writable one configured via DEFAULT_ROLES_PATH: %s )r�r�r<r�r��--collections-path�collections_pathz�One or more directories to search for collections in addition to the default COLLECTIONS_PATHS. Separate multiple paths with '{0}'.z--clear-response-cache�clear_response_cachez)Clear the existing server response cache.z
--no-cache�no_cachez%Do not use the server response cache.ZTYPEr�)�metavarr�rfz$Manage an Ansible Galaxy collection.��func�COLLECTION_ACTIONr�)�parentsr�zManage an Ansible Galaxy role.ZROLE_ACTION)*r�rH�init_parser�opt_help�argparse�ArgumentParser�add_argumentr;Zadd_verbosity_optionsrJ�configZget_configuration_definitionrFZunfrack_pathr�ZPrependListActionr-�collection_pathsr[�osr^r��parser�add_subparsers�required�
add_parser�set_defaults�execute_collection�add_download_options�add_init_options�add_build_options�add_publish_options�add_install_options�add_list_options�add_verify_options�execute_role�add_remove_options�add_delete_options�add_search_options�add_import_options�add_setup_options�add_info_options)r{�commonr�Zgithubr�Zdefault_roles_pathr�r�Z
cache_optionsZtype_parserrfZcollection_parserr�Zrole_parserr�rOrPr��s�
�
��
������
��zGalaxyCLI.init_parserNcCs�|jd|dd�}|j|jd�|jddddd	�|jd
ddd
ddd�|jdddddd�|jddddd�|jddd
dd�dS) NZdownload�PDownload collections and their dependencies as a tarball for an offline install.�r�r�r�rKz
Collection(s)rf�*�r�r��nargs�-n�	--no-deps�no_depsr�Fz4Don't download collection(s) listed as dependencies.r�r�z--download-path�
download_pathz
./collectionsz-The directory to download the collections to.�r�r<r��-r�--requirements-file�requirementsz9A file containing a list of collections to be downloaded.r��--pre�allow_pre_release�UInclude pre-release versions. Semantic versioning pre-releases are ignored by default�r�r�r�)r�r��execute_downloadr�)r{r�r�Zdownload_parserrOrOrPr�>s$��
�
�
�zGalaxyCLI.add_download_optionscCs�|jdkrdnd}|jd|d�|�d�}|j|jd�|jdd	d
d�|�d�|jd
�|�d�|�|dkrptjntjd�|�d�i}|dkr�t	|d<|jd�|�fdd�|�
��i|��|dkr�|jdddddd�dS)Nr�rfr��initz4Initialize new {0} with the base structure of a {0}.r�r�z--init-path�	init_path�./zaThe path in which the skeleton {0} will be created. The default is the current working directory.r�z--{0}-skeleton�{0}_skeletonzAThe path to a {0} skeleton that the new {0} should be based upon.r��{0}_namer�z{0} namez--type�	role_type�storer<z_Initialize using an alternate role type. Valid types include: 'container', 'apb' and 'network'.r�)r�r�r[r��execute_initr�rJZGALAXY_COLLECTION_SKELETONZGALAXY_ROLE_SKELETONr�
capitalize)r{r�r��galaxy_typer�Zobj_name_kwargsrOrOrPr�Qs8��
������zGalaxyCLI.add_init_optionscCs4|jd|dd�}|j|jd�|jddddd	�dS)
N�removezDelete roles from roles_path.r�r�rKzRole(s)r��+r�)r�r��execute_remover�)r{r�r�Z
remove_parserrOrOrPr�lszGalaxyCLI.add_remove_optionscCs"|jd|dd�}|j|jd�dS)N�deletezWRemoves the role from Galaxy. It does not remove or alter the actual GitHub repository.r�r�)r�r��execute_delete)r{r�r�Z
delete_parserrOrOrPr�rs�zGalaxyCLI.add_delete_optionscCsld}|jdkrd}|jd|d�|�d�}|j|jd�|j||��d|d	�|dkrh|jd
ddd
dd�dS)Nr�r�rfr�zAShow the name and version of each {0} installed in the {0}s_path.r�r��?)r�r�r�z--format�
output_format)�human�yaml�jsonr�z-Format to display the list of collections in.)r��choicesr<r�)r�r�r[r��execute_listr�r�)r{r�r�r�Zlist_parserrOrOrPr�xs
��zGalaxyCLI.add_list_optionscCsd|jd|dd�}|j|jd�|jdddd�|jd	d
dd�|jdd
dd�|jddddd�dS)N�searchzLSearch the Galaxy database by tags, platforms, author and multiple keywords.r�r�z--platforms�	platformsz!list of OS platforms to filter byr�z
--galaxy-tags�galaxy_tagsz list of galaxy tags to filter byz--author�authorr�rKzSearch termsZ
searchtermr�r�)r�r��execute_searchr�)r{r�r�Z
search_parserrOrOrPr��s�zGalaxyCLI.add_search_optionscCsj|jd|dd�}|j|jd�|jddddd	d
�|jddd
d�|jdddd�|jdddddd
�dS)N�importz"Import a role into a galaxy serverr�r��	--no-wait�wait�store_falseTzDon't wait for import results.r�z--branch�	referencez\The name of a branch to import. Defaults to the repository's default branch (usually master)r�z--role-name�	role_namez>The name the role should have, if different than the repo namez--status�check_statusr�FzUCheck the status of the most recent import request for given github_user/github_repo.)r�r��execute_importr�)r{r�r�Z
import_parserrOrOrPr��s����zGalaxyCLI.add_import_optionscCs�|jd|dd�}|j|jd�|jddddd�|jd	d
ddd
d�|jddd�|jddd�|jddd�|jddd�dS)NZsetupz;Manage the integration between Galaxy and the given source.r�r�z--remove�	remove_idzSRemove the integration matching the provided ID value. Use --list to see ID values.r�z--list�
setup_listr�FzList all of your integrations.r��sourceZSourcer�r�r�r�r��secretZSecret)r�r��
execute_setupr�)r{r�r�Zsetup_parserrOrOrPr��s�
��zGalaxyCLI.add_setup_optionscCs4|jd|dd�}|j|jd�|jddddd	�dS)
N�infoz(View more details about a specific role.r�r�rKr�r�zrole_name[,version])r�r�r�)r�r��execute_infor�)r{r�r�Zinfo_parserrOrOrPr��szGalaxyCLI.add_info_optionsc
Cs�d}|jd|dd�}|j|jd�|jdd�|�dd	d
�|jddd
dddd�|jdddddd�|jddddd�|jddtjdd�|jddd d!d"�d#}d$}|jd%d&t|tjd'�|jd(d)t	d |tj
tt�
��d*�dS)+NrfZverify�wCompare checksums with the collection(s) found on the server and the installed copy. This does not verify dependencies.r�r�rKr�r�zVThe installed collection(s) name. This is mutually exclusive with --requirements-file.)r�r�r��-i�--ignore-errors�
ignore_errorsr�FzRIgnore errors during verification and continue with the next specified collection.r�r�r�z\Validate collection integrity locally without contacting server for canonical manifest hash.r�r�r�z7A file containing a list of collections to be verified.r��	--keyringrB�.The keyring used during signature verificationr��--signature�
signatures�appendaAn additional signature source to verify the authenticity of the MANIFEST.json before using it to verify the rest of the contents of a collection from a Galaxy server. Use in conjunction with a positional collection name (mutually exclusive with --requirements-file).r�aThe number of signatures that must successfully verify the collection. This should be a positive integer or all to signify that all signatures must be used to verify the collection. Prepend the value with + to fail if no valid signatures are found for the collection (e.g. +all).�A status code to ignore during signature verification (for example, NO_PUBKEY). Provide this option multiple times to ignore a list of status codes. Descriptions for the choices can be seen at L(https://github.com/gpg/gnupg/blob/master/doc/DETAILS#general-status-codes).� --required-valid-signature-countrC�r�r�r�r<�--ignore-signature-status-coderD�r�r�r�r�r<r�)r�r��execute_verifyr�r[rJ�GALAXY_GPG_KEYRINGru�%GALAXY_REQUIRED_VALID_SIGNATURE_COUNTr1�,GALAXY_IGNORE_INVALID_SIGNATURE_STATUS_CODESr�r�keys)r{r�r�r�Z
verify_parser�valid_signature_count_help�ignore_gpg_status_helprOrOrPr��s8��
��
�
�
�zGalaxyCLI.add_verify_optionsc
s�|jdkrdnd}i}|dkr,d|d<d}nd|d<d}|jd	|d
�|�d�}|j|jd�|jdQd�|�dd�|��|jddddd|d�|��}|jdddddd�|�d�|jddddd�|�d�d}d}	|dk�r�|jd d!d"|��d#d$�|jd%d&d'd(d)�|jd*d+dd,d-�|jd.d/d0ddd1d�|jd2d3tj	d4d$�|jd5d6dtj
d7d�|jd8d9d:d;d-�|jd<d=t|tjd>�|jd?d@t
d:|	tjtt���dA�|jdBdCdddDd�n�|jd%dEd'dFd)�t�dG��t�fdHdI�|jD��}
t�dJ��t�fdKdI�|jD��}|j�r�|
�s$|�r�|jd2d3tj	dLd$�|jd5d6dtj
d7d�|jd<d=t|tjd>�|jd?d@t
d:|	tjtt���dA�|jdMdNdOdddPd�dS)RNr�rfr�zxThe collection(s) name or path/url to a tar.gz collection artifact. This is mutually exclusive with --requirements-file.r�z�Ignore errors during installation and continue with the next specified collection. This will not ignore dependency conflict errors.zRole name, URL or tar filez8Ignore errors and continue with the next specified role.�installz5Install {0}(s) from file(s), URL(s) or Ansible Galaxyr�r�rKr�r�)r�r�rrrr�Fr�r�r�r�z+Don't download {0}s listed as dependencies.z--force-with-deps�force_with_depsz7Force overwriting an existing {0} and its dependencies.aThe number of signatures that must successfully verify the collection. This should be a positive integer or -1 to signify that all signatures must be used to verify the collection. Prepend the value with + to fail if no valid signatures are found for the collection (e.g. +all).rr�r�r�z6The path to the directory containing your collections.r�r�r�r�z8A file containing a list of collections to be installed.r�r�r�r�r�z-Uz	--upgrade�upgradezgUpgrade installed collection artifacts. This will also update dependencies unless --no-deps is providedrrBrz--disable-gpg-verify�disable_gpg_verifyzSDisable GPG signature verification when installing collections from a Galaxy serverrrrz�An additional signature source to verify the authenticity of the MANIFEST.json before installing the collection from a Galaxy server. Use in conjunction with a positional collection name (mutually exclusive with --requirements-file).rrCrrrDr r�r�z�Install collection artifacts (tarballs) without contacting any distribution servers. This does not apply to collections in remote Git repositories or URLs to remote tarballs.z--role-filez2A file containing a list of roles to be installed.z^(?<!-)-[a-zA-Z]*r[a-zA-Z]*csg|]}��|�r|�qSrO�rr�ri�a)�r_rerOrP�
<listcomp>rlz1GalaxyCLI.add_install_options.<locals>.<listcomp>z--role-file($|=)csg|]}��|�r|�qSrOr,r-)�role_file_rerOrPr0rlz9The keyring used during collection signature verificationz-gz--keep-scm-metaZ
keep_scm_metazBUse tar instead of the scm archive option when packaging the role.)rK)r�r�r[r��execute_installr��add_mutually_exclusive_group�_get_default_collection_pathrJr"ZGALAXY_DISABLE_GPG_VERIFYrur#r1r$r�rr%rq�compiler7r�r�)r{r�r�r�Zargs_kwargsZignore_errors_helpZinstall_parserZinstall_exclusiver&r'Z
contains_rZcontains_role_filerO)r/r1rPr��s�������

�
�
���
�
�
�
��
�

�
�
�
��zGalaxyCLI.add_install_optionscCsH|jd|dd�}|j|jd�|jddddd	d
�|jddd
dd�dS)NZbuildzMBuild an Ansible collection artifact that can be published to Ansible Galaxy.r�r�rKrfr���.z�Path to the collection(s) directory to build. This should be the directory that contains the galaxy.yml file. The default is the current working directory.)r�r�r<r�z
--output-path�output_pathr�z[The path in which the collection is built to. The default is the current working directory.r�)r�r��
execute_buildr�)r{r�r�Zbuild_parserrOrOrPr�1s��
�zGalaxyCLI.add_build_optionscCsZ|jd|dd�}|j|jd�|jdddd�|jd	d
ddd
d�|jddtddd�dS)NZpublishz0Publish a collection artifact to Ansible Galaxy.r�r�rK�collection_pathz.The path to the collection tarball to publish.)r�r�rrrTz)Don't wait for import validation results.r�z--import-timeout�import_timeoutrz=The time to wait for the collection import process to finish.r�)r�r��execute_publishr�r;)r{r�r�Zpublish_parserrOrOrPr�?s����zGalaxyCLI.add_publish_optionscsZtt|��|�}t|d|jdur$dn|j�t|d|jdurD|jntj�|jt	_|S)Nr8rA)
r�rH�post_process_args�setattrr�r8rJZGALAXY_IGNORE_CERTS�	verbosityrZ)r{�optionsr�rOrPr=Ks
 zGalaxyCLI.post_process_argscsztt|���t�|_dd��i}dD]}|tjvr&tj|||<q&g}dd�tjpVgD�}t	|dd�D�]0\}�t
��fdd	�tD��}tt
|����}tj�d
�|�tj�d
��}|�d�}	|�d�}
|d
p�t}|d}|�d�}
|ddu�rtjd|d<|d}|
�r ddi|d<d|d
<|�rBt||d�|d
<n0|�rr|	�rdt||	||
d�|d
<nt|d�|d
<|�|�|�t|j�fd|i|���qhtjd�ttjdd�}tjd}��r"t�fdd	�|D�d�}|�r�|j�|�n.|j�t|jd�f|t|�d|d�|���n||_t|j�dk�r`|j�t|jdtjf|d|d�|���td|j�|_tjd�S) NcSsTd||fd||d�gdd|��|��fig||d�}|tvrP|�t|�|S)NzThe %s of the %s Galaxy serverzgalaxy_server.%s)�sectionrnr?zANSIBLE_GALAXY_SERVER_%s_%s)r�Zini�envr�r�)�upper�SERVER_ADDITIONALrG)rArnr�Zoption_typeZ
config_defrOrOrP�server_config_def\s
����z(GalaxyCLI.run.<locals>.server_config_def)r�r�r:cSsg|]}|r|�qSrOrO�ri�srOrOrPr0xrlz!GalaxyCLI.run.<locals>.<listcomp>r�)�startc3s&|]\}}}|��|||�fVqdS�NrO)ri�k�reqZensure_type)rE�
server_keyrOrP�	<genexpr>}rlz GalaxyCLI.run.<locals>.<genexpr>Z
galaxy_serverr5r9r4r2r6r8rAz/v3ryr3)Zaccess_tokenr5r8r9)r4�priorityr�r�c3s|]}|j�kr|VqdSrI�r?rF)�
cmd_serverrOrPrM�rlZcmd_arg)r4rNr8rr<r�) r�rH�runrr�rrErJZGALAXY_SERVER_LIST�	enumerate�dict�
SERVER_DEFr*r#Zget_single_datar�Z+initialize_plugin_configuration_definitionsZget_plugin_options�popr rrrrGrr�nextrxr]Z
GALAXY_SERVERrvr�)r{Zgalaxy_optionsZoptional_keyZconfig_serversZserver_listZserver_priorityZconfig_dictZdefsZserver_optionsr5r9Z	token_valr2r6r8Z	cmd_tokenZ
config_serverr�)rPrErLrPrQVs�



�
���


�
��

���	z
GalaxyCLI.runcCs|jjSrI)r�r|�r{rOrOrPr|�sz
GalaxyCLI.apicCs
tjdS)Nr)rJ�COLLECTIONS_PATHSrWrOrOrPr4�sz&GalaxyCLI._get_default_collection_pathTc
s�ggd�}t�dd�}tj�|�s2tdt����t�d��t|d��Z}zt	|�}Wn<t
y�}	z$tdt��t|	�f��WYd}	~	n
d}	~	00Wd�n1s�0Y|dur�td	t������fd
d�}
t|t��r|s�td��|D]}|d
|
|�7<q�n�t
|����t
d
dg��}|�rHtdtd�|����|�d
��pVgD]}|d
|
|�7<�qX���fdd�|�d��p�gD�|d<|S)a�
        Parses an Ansible requirement.yml file and returns all the roles and/or collections defined in it. There are 2
        requirements file format:

            # v1 (roles only)
            - src: The source of the role, required if include is not set. Can be Galaxy role name, URL to a SCM repo or tarball.
              name: Downloads the role to the specified name, defaults to Galaxy name from Galaxy or name of repo if src is a URL.
              scm: If src is a URL, specify the SCM. Only git or hd are supported and defaults ot git.
              version: The version of the role to download. Can also be tag, commit, or branch name and defaults to master.
              include: Path to additional requirements.yml files.

            # v2 (roles and collections)
            ---
            roles:
            # Same as v1 format just under the roles key

            collections:
            - namespace.collection
            - name: namespace.collection
              version: version identifier, multiple identifiers are separated by ','
              source: the URL or a predefined source name that relates to C.GALAXY_SERVER_LIST
              type: git|file|url|galaxy

        :param requirements_file: The path to the requirements file.
        :param allow_old_format: Will fail if a v1 requirements file is found and this is set to False.
        :param artifacts_manager: Artifacts manager.
        :return: a dict containing roles and collections to found in the requirements file.
        )�rolesro�surrogate_or_strict��errorsz*The requirements file '%s' does not exist.z Reading requirement file at '%s'�rbzIFailed to parse the requirements yml at '%s' with the following error:
%sNz"No requirements found in file '%s'cs(d|vrTt�|�}t�dt|��d|vr<d|vr<td��t�j�jfi|��gSt	|ddd�}t
j�|�s�tdt
|�t
��f��t|d	���}z0�fd
d�dd
�t|�D�D�WWd�St�y}z$tdt
��t
|�f��WYd}~n
d}~00Wd�n1�s0YdS)NZincludezfound role %s in yaml filer?�srcz!Must specify name or src for rolerZr[z5Failed to find include requirements file '%s' in '%s'r]cs"g|]}t�j�jfi|���qSrO)rr�r��ri�rrWrOrPr0rlzNGalaxyCLI._parse_requirements_file.<locals>.parse_role_req.<locals>.<listcomp>css|]}t�|�VqdSrI)r+�role_yaml_parse)ri�irOrOrPrMrlzMGalaxyCLI._parse_requirements_file.<locals>.parse_role_req.<locals>.<genexpr>z9Unable to load data from include requirements file: %s %s)r+rarZ�vvvr'r
rr�r�r%r�r^�isfiler&�openr$rz)Zrequirementr�Zb_include_pathZ	f_include�e)�requirements_filer{rOrP�parse_role_req	s(
�
��z:GalaxyCLI._parse_requirements_file.<locals>.parse_role_reqzrExpecting requirements file to be a dict with the key 'collections' that contains a list of collections to installrYroz\Expecting only 'roles' and/or 'collections' as base keys in the requirements file. Found: %sz, cs g|]}t���|�����qSrO)rZfrom_requirement_dict�_init_coll_req_dict)riZcollection_req)r@r{�validate_signature_optionsrOrPr01s��z6GalaxyCLI._parse_requirements_file.<locals>.<listcomp>)r%r�r^�existsr
r&rZrcrer$r�
isinstancer��setr%�
difference�joinrF)
r{rg�allow_old_formatr@rjr�Zb_requirements_fileZreq_objZfile_requirements�errrhZrole_reqZ
extra_keysrO)r@rgr{rjrP�_parse_requirements_file�sF���8��
	z"GalaxyCLI._parse_requirements_filecs�t�t�sd�iSd�vs4��d�r4��dd�dkr8�Stt�fdd�|jD��t|jdj�dd��dt	j
d	d
���d<�S)Nr?rr�r�c3s&|]}�d|j|jhvr|VqdS)rN)r?r�)riZsrvr��coll_reqrOrPrMLs�z0GalaxyCLI._init_coll_req_dict.<locals>.<genexpr>zexplicit_requirement_{name!s}rOrA)r8)rlrSrFrV�iterrxrr�r[rrE)r{rtrOrsrPri<s.
�������zGalaxyCLI._init_coll_req_dictr�cCstjdstd��dS)zn
        Exits with the specified return code unless the
        option --ignore-errors was specified
        rzR- you can use --ignore-errors to skip failed roles and finish processing the list.N)rrEr
)�rcrOrOrP�exit_without_ignore\s
zGalaxyCLI.exit_without_ignorecCs�ddt|d�g}|�di�}|�d|�dd��}|�d|�t|���D]�}|tjvr^qNt||t�r�|�d|�t||���D]*}|tjvr�q�|�d||||f�q�qN|�d	|||f�qN|�d�d
�	|�S)Nr�zRole: %sr?�galaxy_infor�z	description: %sz	%s:z		%s: %sz	%s: %s�
)
r'rFr�sortedr%rH�SKIP_INFO_KEYSrlrSro)�	role_info�textrxr�rJrnrOrOrP�_display_role_infoes 


zGalaxyCLI._display_role_infocCstj�tj�tj�|���SrI)r�r^�abspath�
expanduser�
expandvars�r^rOrOrPrI�szGalaxyCLI._resolve_pathcstt|dd�d�� }t|��dd�}Wd�n1s80Yt�}g}g}|D]r}|�dd�rh|n|}|�|dd�}	|	s�|�dd�}
|
dkr�d	}	n|
d
kr�g}	n|
dkr�i}	|	|d<|�|�qTt�d
��t�d����fdd�}t	�}t
|||d�d�}
||
jjd<|
�
|�}|S)NrZr[r]r�Frnr�r1r�r�rSrtzL\(([^)]+),\s+([^)]+)\)zC\(([^)]+)\)csJt|t�rd�dd�|D��}��d|�}��d|�}tj|ddddd	�S)
Nz. cSsg|]}|�d��qSr6)�rstrip)ri�lrOrOrPr0�rlzKGalaxyCLI._get_skeleton_galaxy_yml.<locals>.comment_ify.<locals>.<listcomp>z\1 <\2>z'\1'�uz# F)�width�initial_indent�subsequent_indentZbreak_on_hyphens)rlr�ro�sub�textwrap�fill)�v�Z
const_patternZlink_patternrOrP�comment_ify�s

z7GalaxyCLI._get_skeleton_galaxy_yml.<locals>.comment_ify)�required_config�optional_config�Z	variablesr�)rer%r'�readr
rFrrqr5r)r,Zenvironment�filters�template)Z
template_path�inject_dataZtemplate_objZ
meta_templateZgalaxy_metar�r�Z
meta_entryZconfig_listrtZ	meta_typer��loader�templar�
meta_valuerOr�rP�_get_skeleton_galaxy_yml�s4.

	
z"GalaxyCLI._get_skeleton_galaxy_ymlcsr|r|rtd��n\|s$|s$td��nJ|rT�dur8td��t�|�}|j|d�d�}n��fdd�|D�gd�}|S)	NzRThe positional collection_name arg and --requirements-file are mutually exclusive.z:You must specify a collection name or a requirements file.z�The --signatures option and --requirements-file are mutually exclusive. Use the --signatures with positional collection_name args or provide a 'signatures' key for requirements in the --requirements-file.F)rpr@csg|]}t�|����qSrO)rZfrom_string)riZ
coll_input�r@rrOrPr0�s�zFGalaxyCLI._require_one_of_collections_requirements.<locals>.<listcomp>)rorY)r
rHrIrr)r{rorgrr@r�rOr�rP�(_require_one_of_collections_requirements�s*

�
���z2GalaxyCLI._require_one_of_collections_requirementscCsdS)z�
        Perform the action on an Ansible Galaxy role. Must be combined with a further action like delete/install/init
        as listed below.
        NrOrWrOrOrPr��szGalaxyCLI.execute_rolecCsdS)z�
        Perform the action on an Ansible Galaxy collection. Must be combined with a further action like init/install as
        listed below.
        NrOrWrOrOrPr��szGalaxyCLI.execute_collectioncCs�tjd}t�tjd�}t|dd�}tj�|�s>t�|�ntj�	|�rZt
dt|���tjdD]*}t�|�}tt
|dd�t
|dd�|�qddS)a*
        Build an Ansible Galaxy collection artifact that can be stored in a central repository like Ansible Galaxy.
        By default, this command builds from the current working directory. You can optionally pass in the
        collection input path (where the ``galaxy.yml`` file is).
        r�r8rZr[z9- the output collection directory %s is a file - abortingrKN)rrErHrIr%r�r^rk�makedirsrdr
r&rr')r{r�r8�
b_output_pathr:rOrOrPr9�s



�zGalaxyCLI.execute_buildcCs�tjd}tjd}tjd}tjd}|r6t�|�}|j|||d�d}t�|�}t|dd�}tj�|�svt�	|�t
|||j|tjd	|d�d
S)r�rKr�r�r��r@rorZr[r�r)rrErHrIr�r%r�r^rkr�rrx)r{r@ror�r�rgr�Zb_download_pathrOrOrPr��s,




��


�zGalaxyCLI.execute_downloadc%s�tjd}tjd}tjd}tjd�|�}tjd�|�}td�|�td�d�}|d	kr�|�td
dd|tjd
ddddtdd�gd��tj}t	j
�||�}nV|dkr�|�dd�\}	}
|�t|	|
dddgdgddddgd��tj
}t	j
�||	|
�}t|dd�}t	j
�|��r�t	j
�|��r4tdt|���n|�sJtd t|���t	j|d!d"�D]T\}}
}|
D]}t	j
�||�}t�|��qf|D]}t	j
�||�}t	�|��q��qX|du�r�d#}nd!}|jj}d$g}t	j
�|�}d%d&�|D��t	j
�|��std'�t|�|���t�}t||d(�}t	j
�|��s6t	�|�t	j|d!d"�D�]V\}}
}t	j
�||����t	j�}|d)}|dk�r�|d*v�o�d+|v}n|d+k}�fd,d&�|
D�|
dd�<|D�]��t	j
���\}}t ��fd-d.��D���r�q�|dk�r�|�r��dk�r��d/k�r�|�!�}|�"d0�|d1<t#�$t	j
�|���|�}tt	j
�|�|�dd�}t%|d2��"}|�&t|dd��Wd�n1�s�0Yn�|d3k�r"|�s"t	j
�|��}t	j
�|�|�}t'|�(|�d)dd�}t|�)|�dd�} t%|d2��}!|!�&| �Wd�n1�s0Yn8t	j
�t	j
�|��|�}"t�*t	j
�|��t	j
�||"���q�|
D]6}#tt	j
�|�|#�dd�}$t	j
�|$��sbt	�|$��qb�qDt+�+d4|�,�|f�dS)5z�
        Creates the skeleton framework of a role or collection that complies with the Galaxy metadata format.
        Requires a role or collection name. The collection name must be in the format ``<namespace>.<collection>``.
        r�r�r�r�r�zyour {0} descriptionzplugins/plugins.html)r�Zansible_plugin_list_dirr�z	your namezyour company (optional)z$license (GPL-2.0-or-later, MIT, etc)r�z http://example.com/issue/trackerzhttp://example.com/repositoryzhttp://docs.example.comzhttp://example.comNr�)rZcompany�licenser	r�Zissue_tracker_urlZrepository_urlZdocumentation_urlZhomepage_urlZmin_ansible_versionZdependenciesrfr7r�z1.0.0z	README.mdzyour name <[email protected]>zGPL-2.0-or-later)�	namespace�collection_namer`ZreadmeZauthorsr�Z
repositoryZ
documentationZhomepageZissuesZbuild_ignorerZr[z6- the path %s already exists, but is a file - abortingz�- the directory %s already exists. You can use --force to re-initialize this directory,
however it will reset any main.yml files that may have
been modified there already.T)�topdownFz^.*/.git_keep$cSsg|]}t�|��qSrO)rqr5)ri�xrOrOrPr0mrlz*GalaxyCLI.execute_init.<locals>.<listcomp>z9- the skeleton path '{0}' does not exist, cannot init {1}r�r)Z	playbooksrYZ	templatescs&g|]�t�fdd��D��s��qS)c3s|]}|���VqdSrIr,r_��drOrPrM�rlz4GalaxyCLI.execute_init.<locals>.<listcomp>.<genexpr>)�any)ri)�skeleton_ignore_rer�rPr0�rlc3s"|]}|�tj�����VqdSrI)rrr�r^ror_)�f�rel_rootrOrPrM�rlz)GalaxyCLI.execute_init.<locals>.<genexpr>z
galaxy.yml.j2r�r?�wbz.j2z - %s %s was created successfully)-rrEr[rSr/rG�ansible_versionrJZGALAXY_ROLE_SKELETON_IGNOREr�r^ro�splitZ!GALAXY_COLLECTION_SKELETON_IGNOREr%rkrdr
r&�walk�shutil�rmtree�unlinkr�Zdefault_role_skeleton_pathr�r)r,r��relpath�sep�splitextr��copyrUrHr�re�writer'Z_get_file_contentsr��copyfilerZ�title)%r{r�r�r�Zobj_skeletonZobj_namer�Zskeleton_ignore_expressionsZobj_pathr�r�Z
b_obj_path�root�dirs�filesZold_dirr^Zold_fileZown_skeletonr�r�Zrel_dirsZrel_root_dirZin_templates_dir�filename�extZ
template_datar�Zb_dest_fileZ
galaxy_objZsrc_templateZ	dest_fileZ
b_renderedZdfZ
f_rel_pathr�Z
b_dir_pathrO)r�r�r�rPr�s�


�
���
�


$4,$zGalaxyCLI.execute_initcCs�tjd}d}tjdD�]V}d|i}t|j|j|�}|j}|rdd|vrZ|d|d<|d=|�|�tjd�sd}z|j�|d	�}Wn`t	y�}zH|j
d
kr�d|jvr�d|}WYd}~�qrtd
||f��WYd}~n
d}~00|r�|�|�nd|}�qrn"tjd�r*|j
�s*d|}�qr|j�r>|�|j�t�}	|	�d|i�}
|
�rb|�|
�||�|�7}q|�|�dS)zx
        prints out detailed information about an installed role as well as info available from the galaxy API.
        r�r�rKr^r`Zinstalled_versionr�NFi�zBad Request�- the role %s was not foundz"Unable to find info about '%s': %sr�)rrErr�r�rarGr|Zlookup_role_by_namerZ	http_code�messager
�_exists�metadatar+rar~�pager)r{r��datar�r|rbraZremote_datarfrKZ	role_specrOrOrPr�sF

&
zGalaxyCLI.execute_infocCs�tjd}tjd}tjd}tjd}tjd}tjd}|durLt|�}|j||||d�d	}d
d�|D�}	t||	|j|||d�}
td
d�|
D��r�dSdS)rrKr�rr�r�rN�rr@rocSsg|]}tt�|���qSrO)rrHrI)rir^rOrOrPr0�rlz,GalaxyCLI.execute_verify.<locals>.<listcomp>)�local_verify_onlyr@css|]}|js|VqdSrI)�success)ri�resultrOrOrPrMrlz+GalaxyCLI.execute_verify.<locals>.<genexpr>r�r)rrEr�r�rrxr�)r{r@roZsearch_pathsrr�rgrr�Zresolved_paths�resultsrOrOrPr!�s2





���zGalaxyCLI.execute_verifycCstjd}tjd}d}tj�d�}|dur4t|�}|rBt�|�}dt|�}g}g}tjddkr�t�tjd�}|j||||d	�}	|	d
}|	dr�t�	|�
d���n|s�|dur�td
��|�rp|�d�s�|�d�s�t
d��|j}
|jo�d|
vo�d|
v}|j|||d�}	|	d}|	d
�r^|j�r:d|
v�s:d|
v�r^|j�rHtjntj	}||�
d��n|��}|	d
}n<tjdD]0}
t�|
���}|�t|j|jfi|����qz|�s�|�s�t�d�dS|�r�t�d�|�|�|�rt�d�|j|||d�dS)a�
        Install one or more roles(``ansible-galaxy role install``), or one or more collections(``ansible-galaxy collection install``).
        You can pass in a list (roles or collections) or use the file
        option listed below (these are mutually exclusive). If you pass in a list, it
        can be a name (which will be downloaded via the galaxy API and github), or it can be a local tar archive file.
        rKr�Nrz�The requirements file '%s' contains {0}s which will be ignored. To install these {0}s run 'ansible-galaxy {0} install -r' or to install both at the same time run 'ansible-galaxy install -r' without a custom install path.r�rfr�r�rorYr�z3- you must specify a user/role name or a roles filez.yamlz.ymlzJInvalid role requirements file, it must end with a .yml or .yaml extensionr�r�)r@rjz'Skipping install, no requirements foundz$Starting galaxy role install processz*Starting galaxy collection install processr�)rrErFr�rHrIr'r�rZrcr[r�endswithr
r�r�rr�warningr4r+ra�striprrr�r��_execute_install_role�_execute_install_collection)r{r@Z
install_itemsrgr:rZtwo_type_warningZcollection_requirementsZrole_requirementsr�Zgalaxy_argsZwill_install_collectionsZdisplay_funcZrnamer�rOrOrPr2st


����
 



�zGalaxyCLI.execute_installcstjd}tjd}tjd}tjd}ztjd}Wn"tyX|jrRtd���Yn0tj�dd�}	tj�d	d�}
tj}t�fd
d�|D��dkr�t	�
d
t��td�|��f�t
��}t|dd�}
tj�|
�s�t�|
�t|||j|||||
|	||tj�dd�d�dS)Nr�rr�r)r+z�Unable to properly parse command line arguments. Please use "ansible-galaxy collection install" instead of "ansible-galaxy install".r�Fr*csg|]}|���r|�qSrO)�
startswith)ri�pr�rOrPr0urlz9GalaxyCLI._execute_install_collection.<locals>.<listcomp>rz�The specified collections path '%s' is not part of the configured Ansible collections paths '%s'. The installed collection will not be picked up in an Ansible run, unless within a playbook-adjacent collections directory.�:rZr[r�)r�r@r+r�)rrE�KeyErrorr�r
rFrJrXr]rZr�r'rorr%r�r^rkr�rrx)r{r�r^r@r�rr�r)r+r�r*r�r8r�rOr�rPr�_s@



��

�	z%GalaxyCLI._execute_install_collectioncCstjd}tjd}tjd}tjdp*|}|D�]�}|rftjdrf|jtjdvrft�d|j�q0t�d|j�|jdu�r|jd|jks�|r�|r�t�d	|j|jd|jp�d
f�|��n$t�d|j|jd|jp�d
f�q0n|�st�dt	|��q0z|�
�}WnRt�yd}z8t�d
|jt|�f�|�
�WYd}~q0WYd}~n
d}~00|�s�|�r�|j�s�t�d|j��nT|j|j}	|	D�]@}
t�d|
�t�}|�|
�}t|j|jfi|��}
d|
jv�rd|
jv�r|
jdu�r�q�|
jdu�rF|
|v�r4t�dt|
��|�|
�nt�d|
j�n�|
jd|
jk�r�|�r�t�d|
j|
jd|
j�pzd
f�|
��|�|
�n$t�dt|
�|
j|j|
jdf�n"|�r�|�|
�nt�d|
j��q�|s0t�d|j�|�
�q0dS)Nr�r�r)r�rKzSkipping role %szProcessing role %s r`z - changing role %s from %s to %s�unspecifiedzD- %s (%s) is already installed - use --force to change version to %sz$- %s is already installed, skipping.z(- %s was NOT installed successfully: %s z-Meta file %s is empty. Skipping dependencies.zInstalling dep %sr7z- adding dependency: %sz-- dependency %s already pending installation.z*- changing dependent role %s from %s to %szW- dependency %s (%s) from role %s differs from already installed version (%s), skippingz/- dependency %s is already installed, skipping.z$- %s was NOT installed successfully.r)rrEr?rZrcrar`r�r�r1r(r
r'rwr�r^Zmetadata_dependenciesr��debugr+rarr�r�r^Zscmr)r{r�Z	role_filer�Z
force_depsr�r�Z	installedrfZrole_dependenciesZdepZdep_reqZdep_infoZdep_rolerOrOrPr��s|



�
�"

$
��
zGalaxyCLI._execute_install_rolecCs�tjdstd��tjdD]x}t|j|j|�}z*|��rJt�d|�nt�d|�Wqty�}z t	d|t
|�f��WYd}~qd}~00qdS)zV
        removes the list of roles passed as arguments from the local system.
        rKz/- you must specify at least one role to remove.z- successfully removed %sz - %s is not installed, skipping.zFailed to remove role %s: %sNr)rrErrr�r|r�rZrzr
r&)r{r	r�rfrOrOrPr��s
,zGalaxyCLI.execute_removecCs2tjddkr|��ntjddkr.|��dS)z5
        List installed collections or roles
        r�r�rfN)rrE�execute_list_role�execute_list_collectionrWrOrOrPr��s
zGalaxyCLI.execute_listc	Cs�d}d}g}tjd}tjd}|D�]}t�|�}tj�|�rFd}n|�d�|��q$|r�t	|j
|j|tj�||�d�}tj�|j�r�d}t
�
dtj�|j��t|��qD|�d|�q$tj�|�s�|�d	|�q$tj�|�s�|�d
|�q$t
�
d|�t�|�}	|	D]*}
t	|j
|j|
|d�}|j�rt|��qq$|�rT|�rTg}|D]}t
�|��qX|�s�td�tjd���d
S)zQ
        List all roles installed on the local system or a specific role
        Fr�r�T�)- the configured path {0} does not exist.r�z# %sr�z(- the configured path %s does not exist.z<- the configured path %s, exists, but it is not a directory.�V- None of the provided paths were usable. Please specify a valid path with --{0}s-pathr�r)rrErHrIr�r^�isdirrr[rr�r�rorZ�dirnamercrk�listdirr�r�r)r{�
path_foundZ
role_found�warningsZroles_search_pathsr	r^Z	role_pathrbZ
path_filesZ	path_file�wrOrOrPr��sL




zGalaxyCLI.execute_list_rolecCs�|durd|_tjd}ttjd�}tjd}tj}i}g}d}d}	|D�]$}
t�|
�}tj	�
|
�s�|
|vrpqJ|�d�|��qJtj	�
|�s�|�d�|��qJd}|�r�t|�|�d	�\}}
t|�}ttj	�|||
�d
d�}tj	�
|�s�|�d�|��qJtj	�
|��s|�d�|��qJd}	zt�||�}
Wn6t�yh}zt�t|�|�WYd}~n
d}~00|d
v�r�|
jd|
jii||<qJt|
g�\}}t|dd||�t|
||�qJt|
�}tj	�
|��r�t�d�|��t t!||��}nt�d�|��qJ|�st�d�|��qJ|d
v�r4dd�|D�||<qJt|�\}}t|dd||�t"|t#d�D]}
t|
||��q\qJ|	�r�|�r�g}|D]}t�$|��q�|�s�t%d�tjd���|dk�r�t�t&�'|��n|dk�r�t�t(|��dS)zz
        List all collections installed on the local system

        :param artifacts_manager: Artifacts manager.
        NFr�r�rfr�z=- the configured path {0}, exists, but it is not a directory.Tr7rZr[z(- unable to find {0} in collection paths>r�r�r`�
CollectionZVersionzSearching {0} for collectionsz/No 'ansible_collections' directory found at {0}zNo collections found at {0}cSsi|]}|jd|ji�qS)r`)rdre)rirfrOrOrP�
<dictcomp>�sz5GalaxyCLI.execute_list_collection.<locals>.<dictcomp>rmr�r�r�r�r))Zrequire_build_metadatarrErmr-r�rHrIr�r^rkrr[r�rr�rr%rorZfrom_dir_path_as_unknownrsr(Z
raise_fromr
rdrerpr_rgrZrcr�rrzr'r�rr��dumpsr#)r{r@r�Zcollections_search_pathsr�Zdefault_collections_pathZcollections_in_pathsr�r�Zcollection_foundr^r:r�rfZb_collection_pathZval_errZ
fqcn_widthZ
version_widthror�rOrOrPr�2s�



�&
��
�


z!GalaxyCLI.execute_list_collectioncCs8t�tjd�}tjd}tjd}t||j||�dS)zs
        Publish a collection into Ansible Galaxy. Requires the path to the collection tarball to publish.
        rKrr;N)rHrIrrErr|)r{r:rr:rOrOrPr<�s

zGalaxyCLI.execute_publishc	Cs�d}d}tjdr"d�tjd�}|sLtjdsLtjdsLtjdsLtd��|jj|tjdtjdtjd|d	�}|d
dkr�tjdtjd
�dSdg}|d
|kr�|�	d|d
|f�n|�	d|d
�g}|dD]"}|�	t
|dd|d��q�t|�}d|}|�	d�|�	|d�|�	|d�|dD],}|�	|d|d|df|df��q>d�|�}|�|�dS)z0 searches for roles on the Ansible Galaxy serveri�NrKr�rrrzYInvalid query. At least one search term, platform, galaxy tag or author must be provided.)r�tagsr�	page_size�countrzNo roles match your search.�Zcolorr�r�z6Found %d roles matching your search. Showing first %s.z$Found %d roles matching your search:r�r2r7r?z %%-%ds %%s)�NameZDescription)z----z-----------�%s.%sr�ry)
rrEror
r|Zsearch_rolesrZrJ�COLOR_ERRORrr]r\r�)	r{r�r�Zresponser�Zmax_lenr�Zname_lenZ
format_strrOrOrPr�s:
"� 
*

zGalaxyCLI.execute_searchc	Csdtjtjtjtjd�}ttjddd�}ttjddd�}tjdrZ|jj||d�}�n|jj	||tjd	tjd
d�}t
|�dk�rtjd
||fdd�tjdtjd�|D]4}tjd|ddd|dddftjd�q�tjd||ftjd�dSt�d|dd�tjd�sft�d|dddd�t�d|dd|ddf�tjd�s~tjd�rg}d}|�s|jj|ddd�}|dddD]<}|d|v�r�tj|d ||d!d�|�
|d��q�|dd"d#v�rd$}n
t�d%��q�dS)&z+ used to import a role into Ansible Galaxy Znormal)�INFOZWARNINGZERROR�SUCCESS�FAILEDr�rZr[r�r
)r�r�rr	)rr	r�zEWARNING: More than one Galaxy role associated with Github repo %s/%s.Zyellowr�z.The following Galaxy roles are being updated:
r�r�r�r�r?z[
To properly namespace this role, remove each of the above and re-import %s/%s from scratchrz(Successfully submitted import request %d�idrz
Role name: %szRepo: %s/%sF)Ztask_idZ
task_messagesZmessage_textZmessage_type�state)r�r�TrU)rJZ
COLOR_WARNr��COLOR_OKr'rrEr|Zget_import_taskZcreate_import_taskr]rZZ
COLOR_CHANGEDr�time�sleep)	r{Zcolorsr�r�Ztaskr�Zmsg_list�finished�msgrOrOrPr�sT�

��2�"zGalaxyCLI.execute_importcCstjdr�|j��}t|�dkr.t�d�dStjdtjd�tjdtjd�|D]0}tjd|d|d	|d
|dftjd�qRdStjdr�|j�tjd�tjd
tjd�dStjd	}tjd
}tjd}tjd}|j�	||||�}t�d|d	|d
|df�dS)zD Setup an integration from Github or Travis for Ansible Galaxy rolesr
rzNo integrations found.z
ID         Source     Repor�z ---------- ---------- ----------z%-10s %-10s %s/%sr�rr�r�rzDSecret removed. Integrations using this secret will not longer work.rzAdded integration for %s %s/%s)
rrEr|Zlist_secretsr]rZrJr�Z
remove_secretZ
add_secret)r{Zsecretsrrr�r��resprOrOrPrs2


��




 zGalaxyCLI.execute_setupcCs�tjd}tjd}|j�||�}t|d�dkrxt�d�t�d�t�d�|dD]}t�d|j|j|jf�qXt�|d	�d
S)z$ Delete a role from Ansible Galaxy. r�r�Z
deleted_rolesr�zDeleted the following roles:zID     User            Namez!------ --------------- ----------z
%-8s %-15s %s�statusr)	rrEr|Zdelete_roler]rZr�r�r?)r{r�r�r�r�rOrOrPr�8s




zGalaxyCLI.execute_delete)N)N)N)N)N)N)N)N)N)N)N)N)N)TNT)r�)NN)N)N)N)N)7r}r~r�__doc__r?r{r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r=rQr�r|r4rrri�staticmethodrwr~rIr�r�r�r�r9rTr�r�rr!r2r�r�r�r�r�r�r<rrrr��
__classcell__rOrOr�rPrH�sxU









!
Y

z

e 


/�
$6 Y+R
8z
)7!rHcCst�|�dSrI)rHZcli_executor)rKrOrOrP�mainKsr��__main__)rUrV)rUrVrUrV)N)lZ
__future__rrrr�Z
__metaclass__Zansible.clirrRr�Zos.pathr�rqr�r�r�r��typingr�ZdataclassesrZ
yaml.errorrZansible.constantsZ	constantsrJZansiblerZansible.cli.argumentsr	r�Zansible.errorsr
rZansible.galaxyrr
Zansible.galaxy.apirrZansible.galaxy.collectionrrrrrrrrrZ3ansible.galaxy.collection.concrete_artifact_managerrZansible.galaxy.collection.gpgrZ0ansible.galaxy.dependency_resolution.dataclassesrZansible.galaxy.rolerZansible.galaxy.tokenrrrr Z$ansible.module_utils.ansible_releaser!r�Z'ansible.module_utils.common.collectionsr"Z ansible.module_utils.common.yamlr#r$Zansible.module_utils._textr%r&r'Zansible.module_utilsr(Zansible.parsing.dataloaderr)Zansible.parsing.yaml.loaderr*Z!ansible.playbook.role.requirementr+Zansible.templater,Zansible.utils.collection_loaderr-Zansible.utils.displayr.Zansible.utils.plugin_docsr/rZZmovesZurllib�parse�urlparserTrDrTr_rcrgrprurvrHr�r}rOrOrOrP�<module>s�,�