HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.109.1.lve.el8.x86_64 #1 SMP Thu Mar 5 20:23:46 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.30
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/__pycache__/nexus.cpython-310.pyc
o

�N�g�[�@s�dZddlZddlZddlZddlZddlZddlm	Z	m
Z
ddlZddl
ZddlmZz
ddlmmZdZWneyDdZYnwe�e�ZdZdd	�Z	
				d6dd�Z		
				d7d
d�Z			d8dd�Z	
				d6dd�Z	
				d6dd�Zd9dd�Z 				d:dd�Z!	d9dd�Z"dd�Z#dd�Z$dd �Z%d!d"�Z&d#d$�Z'd%d&�Z(d'd(�Z)d)d*�Z*d+d,�Z+d-d.�Z,d/d0�Z-d;d2d3�Z.Gd4d5�d5e/�Z0dS)<zJ
Module for fetching artifacts from Nexus 3.x

.. versionadded:: 2018.3.0
�N)�	HTTPError�URLError)�CommandExecutionErrorTFZnexuscCsts	dd�t�fSdS)z<
    Only load if elementtree xml library is available.
    Fz6Cannot load {} module: ElementTree library unavailableT)�HAS_ELEMENT_TREE�format�__virtualname__�rr�F/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/nexus.py�__virtual__s��r
�/tmpc

Cs�t�d|||||||�i}
|r%|	r%d�t�|�d|	����dd��|
d<t|||||
d�}|d}t||||||||
d	�\}
}t|||�}t	|
||
�S)
a
    Gets latest snapshot of the given artifact

    nexus_url
        URL of nexus instance
    repository
        Snapshot repository in nexus to retrieve artifact from, for example: libs-snapshots
    group_id
        Group Id of the artifact
    artifact_id
        Artifact Id of the artifact
    packaging
        Packaging type (jar,war,ear,etc)
    target_dir
        Target directory to download artifact to (default: /tmp)
    target_file
        Target file to download artifact to (by default it is target_dir/artifact_id-snapshot_version.packaging)
    classifier
        Artifact classifier name (ex: sources,javadoc,etc). Optional parameter.
    username
        nexus username. Optional parameter.
    password
        nexus password. Optional parameter.
    z�======================== MODULE FUNCTION: nexus.get_latest_snapshot, nexus_url=%s, repository=%s, group_id=%s, artifact_id=%s, packaging=%s, target_dir=%s, classifier=%s)�Basic {}�:�
��
Authorization��	nexus_url�
repository�group_id�artifact_id�headers�latest_version)rrrr�version�	packaging�
classifierr)
�log�debugr�base64�encodestring�replace�_get_artifact_metadata�_get_snapshot_url�__resolve_target_file�__save_artifact)rrrrr�
target_dir�target_filer�username�passwordr�artifact_metadatar�snapshot_url�	file_namerrr	�get_latest_snapshot-sF$�
��
�
r+cCs�t�d||||||||	�	i}|
r&|r&d�t�|
�d|����dd��|d<t||||||||	|d�	\}
}t|||�}t|
||�S)a=
    Gets snapshot of the desired version of the artifact

    nexus_url
        URL of nexus instance
    repository
        Snapshot repository in nexus to retrieve artifact from, for example: libs-snapshots
    group_id
        Group Id of the artifact
    artifact_id
        Artifact Id of the artifact
    packaging
        Packaging type (jar,war,ear,etc)
    version
        Version of the artifact
    target_dir
        Target directory to download artifact to (default: /tmp)
    target_file
        Target file to download artifact to (by default it is target_dir/artifact_id-snapshot_version.packaging)
    classifier
        Artifact classifier name (ex: sources,javadoc,etc). Optional parameter.
    username
        nexus username. Optional parameter.
    password
        nexus password. Optional parameter.
    z�======================== MODULE FUNCTION: nexus.get_snapshot(nexus_url=%s, repository=%s, group_id=%s, artifact_id=%s, packaging=%s, version=%s, target_dir=%s, classifier=%s)rr
rrr)	rrrrrr�snapshot_versionrr)	rrrrrrr!r"r#)rrrrrrr,r$r%rr&r'rr)r*rrr	�get_snapshotzs:(�
�
�r-c	

Csbt�d|||||||�i}	|r%|r%d�t�|�d|����dd��|	d<t|||||||dd�S)	a�
    Gets the specific version string of a snapshot of the desired version of the artifact

    nexus_url
        URL of nexus instance
    repository
        Snapshot repository in nexus to retrieve artifact from, for example: libs-snapshots
    group_id
        Group Id of the artifact
    artifact_id
        Artifact Id of the artifact
    packaging
        Packaging type (jar,war,ear,etc)
    version
        Version of the artifact
    classifier
        Artifact classifier name (ex: sources,javadoc,etc). Optional parameter.
    username
        nexus username. Optional parameter.
    password
        nexus password. Optional parameter.
    z�======================== MODULE FUNCTION: nexus.get_snapshot_version_string(nexus_url=%s, repository=%s, group_id=%s, artifact_id=%s, packaging=%s, version=%s, classifier=%s)rr
rrrT)rrrrrrr�just_get_version_string)rrrrrrr!)
rrrrrrrr&r'rrrr	�get_snapshot_version_string�s2!���r/c

Cs�t�d|||||||�i}
|r%|	r%d�t�|�d|	����dd��|
d<t|||||
d�}|d}t|||||||�\}
}t|||�}t	|
||
�S)	a�
    Gets the latest release of the artifact

    nexus_url
        URL of nexus instance
    repository
        Release repository in nexus to retrieve artifact from, for example: libs-releases
    group_id
        Group Id of the artifact
    artifact_id
        Artifact Id of the artifact
    packaging
        Packaging type (jar,war,ear,etc)
    target_dir
        Target directory to download artifact to (default: /tmp)
    target_file
        Target file to download artifact to (by default it is target_dir/artifact_id-version.packaging)
    classifier
        Artifact classifier name (ex: sources,javadoc,etc). Optional parameter.
    username
        nexus username. Optional parameter.
    password
        nexus password. Optional parameter.
    z�======================== MODULE FUNCTION: nexus.get_latest_release(nexus_url=%s, repository=%s, group_id=%s, artifact_id=%s, packaging=%s, target_dir=%s, classifier=%s)rr
rrrrr)
rrrrrrr �_get_release_urlr"r#)rrrrrr$r%rr&r'rr(r�release_urlr*rrr	�get_latest_releases8$����r2cCs|t�d||||||||�	i}|	r&|
r&d�t�|	�d|
����dd��|d<t|||||||�\}}
t|
||�}t|||�S)a(
    Gets the specified release of the artifact

    nexus_url
        URL of nexus instance
    repository
        Release repository in nexus to retrieve artifact from, for example: libs-releases
    group_id
        Group Id of the artifact
    artifact_id
        Artifact Id of the artifact
    packaging
        Packaging type (jar,war,ear,etc)
    version
        Version of the artifact
    target_dir
        Target directory to download artifact to (default: /tmp)
    target_file
        Target file to download artifact to (by default it is target_dir/artifact_id-version.packaging)
    classifier
        Artifact classifier name (ex: sources,javadoc,etc). Optional parameter.
    username
        nexus username. Optional parameter.
    password
        nexus password. Optional parameter.
    z�======================== MODULE FUNCTION: nexus.get_release(nexus_url=%s, repository=%s, group_id=%s, artifact_id=%s, packaging=%s, version=%s, target_dir=%s, classifier=%s)rr
rrr)	rrrrrrr0r"r#)rrrrrrr$r%rr&r'rr1r*rrr	�get_releaseGs*'�
��r3cCs|durtj�||�}|S�N)�os�path�join)r*r$r%rrr	r"�sr"c
	Cs�|duri}|duo
|dk}
|durPt||||||d�}||dvr2dj|||||||d�}t|��|
rJ||dvrJdj|||||||d�}t|��|d|}t|�}
dj|||t|�d�}d	j|||
|||d
�}t�d|�|	rt|S||fS)Nr�rrrrrr�snapshot_versionsa�Cannot find requested packaging '{packaging}' in the snapshot version metadata.
                      nexus_url: {nexus_url}
                      repository: {repository}
                      group_id: {group_id}
                      artifact_id: {artifact_id}
                      packaging: {packaging}
                      classifier: {classifier}
                      version: {version})rrrrrrra�Cannot find requested classifier '{classifier}' in the snapshot version metadata.
                      nexus_url: {nexus_url}
                      repository: {repository}
                      group_id: {group_id}
                      artifact_id: {artifact_id}
                      packaging: {packaging}
                      classifier: {classifier}
                      version: {version}z8{artifact_id}-{snapshot_version}{classifier}.{packaging})rr,rr�H{nexus_url}/{repository}/{group_url}/{artifact_id}/{version}/{file_name}�rr�	group_urlrrr*zsnapshot_url=%s)�_get_snapshot_version_metadatar�
nexusError�__get_group_id_subpath�__get_classifier_urlrr)rrrrrrr,rrr.�has_classifierZsnapshot_version_metadataZ
error_messager<r*r)rrr	r!�st�	�����r!c
CsHt|�}dj|||t|�d�}dj||||||d�}	t�d|	�|	|fS)Nz/{artifact_id}-{version}{classifier}.{packaging})rrrrr:r;zrelease_url=%s)r?rr@rr)
rrrrrrrr<r*r1rrr	r0�s"��r0cCs*t|�}dj||||d�}t�d|�|S)NzE{nexus_url}/{repository}/{group_url}/{artifact_id}/maven-metadata.xml)rrr<rzartifact_metadata_url=%s�r?rrr)rrrrr<�artifact_metadata_urlrrr	�_get_artifact_metadata_urls��rDc

Csvt||||d�}ztj�|d|�}tj�|���}Wnttfy2}z
d�||�}	t	|	��d}~wwt
�d|�|S)N)rrrr�,Could not fetch data from url: {}. ERROR: {}zartifact_metadata_xml=%s)rD�urllib�request�Request�urlopen�readrrrrrr)
rrrrrrCrGZartifact_metadata_xml�err�messagerrr	�_get_artifact_metadata_xmls$����rMcCs�t|||||d�}t�|�}||�d�jksJ�||�d�jks"J�|�d��d�}g}|�d�D]}	|�|	j�q1t|�}
t�	d|
�d|
iS)	Nr�groupId�
artifactId�
versioning�versionsrzlatest version=%sr)
rM�ET�
fromstring�find�text�iter�append�maxrr)rrrrr�metadata_xml�rootrQZversionListrrrrr	r *s"�
r cCs,t|�}dj|||||d�}t�d|�|S)NzO{nexus_url}/{repository}/{group_url}/{artifact_id}/{version}/maven-metadata.xml)rrr<rrz snapshot_version_metadata_url=%srB)rrrrrr<�snapshot_version_metadata_urlrrr	�"_get_snapshot_version_metadata_url@s�r\c
Csxt|||||d�}ztj�|d|�}tj�|���}Wnttfy3}	z
d�||	�}
t	|
��d}	~	wwt
�d|�|S)N)rrrrrrEz snapshot_version_metadata_xml=%s)r\rFrGrHrIrJrrrrrr)rrrrrrr[rGZsnapshot_version_metadata_xmlrKrLrrr	�"_get_snapshot_version_metadata_xmlPs&����r]cCs�t||||||d�}t�|�}||�d�jksJ�||�d�jks#J�||�d�jks-J�|�d��d�}i}	|D]#}
|
�d�j}|
�d�j}||	|<|
�d	�dur\|
�d	�j}
||	|
<q9d
|	iS)Nr8rNrOrrPZsnapshotVersions�	extension�valuerr9)r]rRrSrTrU)rrrrrrrY�metadatar9Zextension_version_dictr,r^r_rrrr	r=is.�
�r=c

Cs�t�d||�didd�}tj�|�ret�d|�|d}t||�\}}}|r[t�d|�td|d	d
�}t�d||�||krRd|d
<||d<d�||�|d<|Sd�||�|d<n
d|d
<||d<|St�d||�zOtj	�
|d|�}	tj	�|	�}
tj
j�|d��}|�tj
j�|
����Wd�n1s�wYd|d
<td|��|d�|d<||dd<||d<W|Sttfy�}zd|d
<t||�|d<WYd}~|Sd}~ww)Nz__save_artifact(%s, %s)Fr)�status�changes�commentz,File %s already exists, checking checksum...z.sha1zDownloaded SHA1 SUM: %sz
file.get_hash�sha1)r6ZformzTarget file (%s) SHA1 SUM: %sTrar%zEFile {} already exists, checksum matches with nexus.
Checksum URL: {}rczLFile {} already exists, checksum does not match with nexus!
Checksum URL: {}zDownloading: %s -> %s�wbzArtifact downloaded from URL: rbZdownloaded_file)rrr5r6�isfile�
__downloadZ__salt__rrFrGrHrI�salt�utils�filesZfopen�writeZstringutils�to_bytesrJ�__append_commentrr�__get_error_comment)
Zartifact_urlr%r�resultZchecksum_urlZchecksum_successZartifact_sumZchecksum_commentZfile_sumrG�fZ
local_file�errr	r#�s\
�����
���r#cCs|�dd�}|S)N�.�/)r)rr<rrr	r?�sr?cCs |duo|dk}|rd|SdS)Nr�-r)rrArrr	r@�sr@c
Cs~t�d|�d}d}d}ztj�|d|�}tj�|�}|��}d}Wnty9}zt||�}WYd}~nd}~ww|||fS)NzDownloading content from %sFT)	rrrFrGrHrIrJrrn)�request_urlr�success�contentrcrG�urlrqrrr	rg�s��
rgcCsJ|jtjjkr
d|}|S|jtjjkrd�|�}|Sdj|j|d�}|S)NzHTTP Error 404. Request URL: z�HTTP Error 409: Conflict. Requested URL: {}. 
This error may be caused by reading snapshot artifact from non-snapshot repository.z)HTTP Error {err_code}. Request URL: {url})Zerr_coderx)�code�http�client�	NOT_FOUND�CONFLICTr)Z
http_errorrurcrrr	rn�s
�����rnrcCs|d|S)Nrr)Znew_commentZcurrent_commentrrr	rm�srmcs$eZdZ�fdd�Zdd�Z�ZS)r>cst���||_dSr4)�super�__init__r_)�selfr_��	__class__rr	r�s

znexusError.__init__cCs
t|j�Sr4)�reprr_)r�rrr	�__str__�s
znexusError.__str__)�__name__�
__module__�__qualname__rr��
__classcell__rrr�r	r>�sr>)rNNNN)NrNNNN)NNNr4)NNNN)r)1�__doc__r�http.clientrz�loggingr5�urllib.requestrF�urllib.errorrrZsalt.utils.filesrhZsalt.utils.stringutilsZsalt.exceptionsrZxml.etree.ElementTreeZetreeZElementTreerRr�ImportError�	getLoggerr�rrr
r+r-r/r2r3r"r!r0rDrMr r\r]r=r#r?r@rgrnrm�	Exceptionr>rrrr	�<module>s��

�T
�Q
�D
�L
�
A

�_
�8