
    Vh]                       d Z ddlmZ ddlZddlZddlmZ ddlm	Z	m
Z
 ddlmZ ddlmZ ddlmZ ej"                  rdd	lmZ  ej(                  d
ddd      ZddlmZmZ ddlmZ ddlmZmZ ddlmZm Z m!Z! ddl"m#Z# ddl$m%Z% ddl&m'Z' dZ(dZ)dZ*dZ+ e'       Z,d Z-d Z.d Z/d Z0d Z1d Z2d Z3d  Z4d! Z5d" Z6d# Z7 G d$ d      Z8 edd%      Z9 edd&      Z: G d' de8e9      Z; G d( de8e:      Z<y))zDependency structs.    )annotationsN)
namedtuple)MutableSequenceMutableMapping)iglob)urlparse)	safe_load)ConcreteArtifactsManager
Collection	CandidateRequirement_ComputedReqKindsMixin)AnsibleErrorAnsibleAssertionError)	GalaxyAPI)HAS_PACKAGINGPkgReq)to_bytes	to_nativeto_text)ArgumentSpecValidator)AnsibleCollectionRef)DisplayFs
   galaxy.ymls   MANIFEST.jsons
   GALAXY.ymlc           
     N   t        | d      }t        j                  j                  |       sy 	 t	        | d      5 }t        |      }d d d        t        t              st        j                  d| d       y t        ||||      }|rSt        j                  d| d	       t        j                  d
j                  |             t        j                  d       y |S # 1 sw Y   xY w# t        $ r0}t        j                  d| dt        |d              Y d }~y d }~ww xY w)Nsurrogate_or_stricterrorsrb)modez0Error getting collection source information at 'z': z': expected a YAML dictionaryz!Ignoring source metadata file at z due to the following errors:
z@Correct the source metadata file by reinstalling the collection.)r   ospathisfileopenr	   OSErrordisplaywarning
isinstancer   _validate_v1_source_info_schemajoin)	b_source_info_path	namespacenameversionsource_info_pathfdmetadataeschema_errorss	            `/home/dcms/DCMS/lib/python3.12/site-packages/ansible/galaxy/dependency_resolution/dataclasses.pyget_validated_source_infor5   .   s   1:OP77>>,-$40 	%B }H	% h/JK[J\\yz{3ItWhWM;<L;MMjkl		-01Z[O'	% 	% >?O>PPST[\]f{T|S}~	
 	s.   C+ CC+ C($C+ +	D$4&DD$c                   t        t        dg      t               t               t               t        t        t        t               t               t               t                           t        |g      t        | g      t        |g            }t        |t               s t        d|  d| d| d	t	        |             t        |      }|j                  |      }|j                  S )
Nz1.0.0)choices)	signaturepubkey_fingerprintsigning_servicepulp_created)type
suboptions)format_versiondownload_urlversion_urlserver
signaturesr-   r,   r.   z Invalid offline source info for .:z, expected a dict and got )dictlistr(   r   r<   r   validateerror_messages)r,   r-   r.   provided_argumentsargument_spec_data	validatorvalidation_results          r4   r)   r)   K   s    WI.VFv&#'6 $!V	
 4&!	{+gY'!& ($/.yk4&'Jdeij|e}d~
 	
 &&89I!**+=>+++    c                    t        | d      }t        j                  j                  t        j                  j	                  |t
                    S Nr   r   )r   r!   r"   r#   r*   _GALAXY_YAMLdir_path
b_dir_paths     r4   _is_collection_src_dirrT   i   s1    (+@AJ77>>"'',,z<@AArM   c                    t        | d      }t        j                  j                  t        j                  j	                  |t
                    S rO   )r   r!   r"   r#   r*   _MANIFEST_JSONrQ   s     r4   _is_installed_collection_dirrW   n   s1    (+@AJ77>>"'',,z>BCCrM   c                2    t        |       xs t        |       S N)rW   rT   )rR   s    r4   _is_collection_dirrZ   s   s    $X. 	)x(rM   c              #    K   t        | d      }t        j                  j                  |d      }t	        |      D ]  }t        j                  j                  t        j                  j                  |t                    r| It        j                  j                  t        j                  j                  |t                    s|  y w)Nr   r      *)r   r!   r"   r*   r   r#   rV   rP   )rR   rS   subdir_glob_patternsubdirs       r4   _find_collections_in_subdirsr_   z   s     (+@AJ'',, +, 77>>"'',,v~>?LWW^^BGGLL>?L	s   CCCc                *    t        t        |             S rY   )anyr_   
tested_strs    r4   _is_collection_namespace_dirrd      s    +J788rM   c                V    t         j                  j                  t        | d            S rO   )r!   r"   r#   r   rb   s    r4   _is_file_pathrf      s    77>>(:6KLMMrM   c                L    t        |       j                  j                         dv S )N>   httphttps)r   schemelowerrb   s    r4   _is_http_urlrl      s"    J&&,,.2CCCrM   c                $    | j                  d      S )N)zgit+zgit@)
startswithrb   s    r4   _is_git_urlro      s      !122rM   c                ^     t         fdt        t        t        t        t
        fD              S )Nc              3  .   K   | ]  } |        y wrY    ).0	predicaterc   s     r4   	<genexpr>z0_is_concrete_artifact_pointer.<locals>.<genexpr>   s      
 	*
s   )ra   ro   rl   rf   rZ   rd   rb   s   `r4   _is_concrete_artifact_pointerrv      s0     
 (

 
 
rM   c                     e Zd ZdZd Zd Zd Zed        Zed        Z	ed        Z
ed        Zedd	       Zd
 Zd Zd Zed        Zd Zd Zed        Zed        Zed        Zed        Zed        Zed        Zed        Zed        Zed        Zed        Zed        Zed        Zed        Z ed        Z!y) r   )fqcnversrcr<   c                    | j                   sd | _        y | j                  t        | j                  d            }t        || j                  | j                  | j                        | _        y rO   )	may_have_offline_galaxy_info_source_infoconstruct_galaxy_info_pathr   rz   r5   r,   r-   ry   )selfargskwargs	info_paths       r4   __init__z_ComputedReqKindsMixin.__init__   sT    00 $D77Rg8hiI 9			!DrM   c                Z     t        t         fdt        j                  D                    S )Nc              3  6   K   | ]  }t        |        y wrY   )getattr)rs   attrr   s     r4   ru   z2_ComputedReqKindsMixin.__hash__.<locals>.<genexpr>   s     ^$'$-^s   )hashtupler   UNIQUE_ATTRSr   s   `r4   __hash__z_ComputedReqKindsMixin.__hash__   s     E^:P:]:]^^__rM   c                0    t        |       t        |      k(  S rY   )r   )r   	candidates     r4   __eq__z_ComputedReqKindsMixin.__eq__   s    DzT)_,,rM   c                    t         j                  j                  |      s$t        dj	                  t        |                  	 | j                  ||      S # t        $ r | j                  |      cY S w xY w)a  Make collection from an unspecified dir type.

        This alternative constructor attempts to grab metadata from the
        given path if it's a directory. If there's no metadata, it
        falls back to guessing the FQCN based on the directory path and
        sets the version to "*".

        It raises a ValueError immediately if the input is not an
        existing directory path.
        z1The collection directory '{path!s}' doesn't existr"   )r!   r"   isdir
ValueErrorformatr   from_dir_pathfrom_dir_path_implicit)clsrR   art_mgrs      r4   from_dir_path_as_unknownz/_ComputedReqKindsMixin.from_dir_path_as_unknown   sm      ww}}X&CIh/0 
	8$$Xw77 	8--h77	8s   A A43A4c                   |j                  t        t        j                  j                              r2|j                  t        t        j                  j                              }t        |      sWt        j                  dj                  t        t              t        t              t        |d                   t        d       | dd|dd      }|j                  |      }	 |j                  |      } | |||dd      S # t         $ rx}t        j                  dj                  t        t              t        t              t        |d                   t        d	j                  t        |d      
            |d}~ww xY w)z0Make collection from an directory with metadata.zrCollection at '{path!s}' does not have a {manifest_json!s} file, nor has it {galaxy_yml!s}: cannot detect version.r   r   )
galaxy_ymlmanifest_jsonr"   zJ`dir_path` argument must be an installed or a source collection directory.NdirziCollection at '{path!s}' has a {manifest_json!s} or {galaxy_yml!s} file but it contains invalid metadata.z-Collection at '{path!s}' has invalid metadatar   )endswithr   r!   r"   seprstriprZ   r&   r'   r   r   rP   rV   r   get_direct_collection_versionget_direct_collection_fqcn	TypeError)r   rR   r   tmp_inst_reqreq_versionreq_nameerrs          r4   r   z$_ComputedReqKindsMixin.from_dir_path   sY    Xbggkk23x'<=H!(+OOK&|4")."9 2GH   ) 
 4x=;;LI	99,GH" 8[(E4@@!  	OOL&|4")."9 2GH   ?GH5JKL 	s   %D 	FA3E>>Fc                v   |j                  t        t        j                  j                              r2|j                  t        t        j                  j                              }t        |d      }|j                  t        j                  j                        }dj                  |dd       } | |d|dd      S )a  Construct a collection instance based on an arbitrary dir.

        This alternative constructor infers the FQCN based on the parent
        and current directory names. It also sets the version to "*"
        regardless of whether any of known metadata files are present.
        r   r   rC   N*r   )	r   r   r!   r"   r   r   r   splitr*   )r   rR   
u_dir_path	path_listr   s        r4   r   z-_ComputedReqKindsMixin.from_dir_path_implicit  s     Xbggkk23x'<=HX.CD
$$RWW[[1	88IbcN+8S(E488rM   c                   i }t        |      st        j                  |      r||d<   nyd|v r$|j                  d      \  |d<   }|d<   |d   sU|d= nQt        st        d      	 t        |      }|j                  |d<   |j                  rt        |j                        |d<   	 ||d<   | j                  ||      S # t        $ r}||d<   Y d }~*d }~ww xY w)Nr-   rD   r.   zGFailed to import packaging, check that a supported version is installedrB   )rv   r   is_valid_collection_name	partitionr   r   r   r-   	specifierr   	Exceptionfrom_requirement_dict)r   collection_inputartifacts_managersupplemental_signaturesreq_seppkg_reqr2   s           r4   from_stringz"_ComputedReqKindsMixin.from_string  s    ()9:>R>k>kl|>}*CK$$0@0J0J30O-CKs9~y>	N "#lmm@ !12
 &llF$$%,W->->%?C	N3L((.?@@  /.F/s   #B9 9	CCCc           	        |j                  dd       }|j                  dd      }|j                  d      }|j                  dd       }|j                  dd       }|;|r|j                  t        d| d      t        |t              s|g}t        |      }|t        r|t        |      r|}	n|t        j                  |      rd	}n|t        |      r|d }}	nd
}
|2t        j                  j                  |      r|
j                  |      }nJ|2t        j                  j                  |      r|
j                  |      }n|rdj                  |      }nd}t        dj                  |            |t        	      rd}|	}nt        |	      rd}|	}nt!        |	      rd}|	}nt#        |	      r]t%        |	      rMt'        |	      rBt        dj                  t)        |	d      t)        t*              t)        t,                          d}|	}nt/        |	      rd }d}|	}nt        d      |dvrt        d      ||d	k(  rt        d      |d	k7  r||d }}|d	k(  rJt        |t0              r:t        |j2                        s%t        dj                  |j2                              |dk(  rR|j5                  t        j                  j6                        r)|j9                  t        j                  j6                        } | |||||      }|dvr||j;                  |      }|dvr|dk(  r|j=                  |      } | |||||      S ) Nr-   r.   r   r<   sourcerB   z#Signatures were provided to verify z but no keyring was configured.galaxyu   

Tip: Make sure you are pointing to the right subdirectory — `{src!s}` looks like a directory but it is neither a collection, nor a namespace dir.)rz   z

Could not find {0}. aM  Neither the collection requirement entry key 'name', nor 'source' point to a concrete resolvable collection artifact. Also 'name' is not an FQCN. A valid collection name must be in the format <namespace>.<collection>. Please make sure that the namespace and the collection name contain characters from [a-zA-Z0-9_] only.{extra_tip!s})	extra_tipgiturlfilezCollection requirement at '{path!s}' has both a {manifest_json!s} file and a {galaxy_yml!s}.
The requirement must either be an installed collection directory or a source collection directory, not both.r   r   )r"   r   r   r   subdirsz?Failed to automatically detect the collection requirement type.>   r   r   r   r   r   r   zcThe collection requirement entry key 'type' must be one of file, galaxy, git, dir, subdirs, or url.znCollections requirement entry should contain the key 'name' if it's requested from a Galaxy-like index server.z}Collections requirement 'source' entry should contain a valid Galaxy API URL but it does not: {not_url!s} is not an HTTP URL.)not_url>   r   r   )getkeyringr   r(   r   	frozenset!_ALLOW_CONCRETE_POINTER_IN_SOURCErv   r   r   r!   r"   r   r   ro   rl   rf   rZ   rW   rT   r   rV   rP   rd   r   
api_serverr   r   r   r   r   )r   collection_reqr   validate_signature_optionsr   r   req_type
req_sourcereq_signature_sourcessrc_pathdir_tip_tmpltipr   s                r4   r   z,_ComputedReqKindsMixin.from_requirement_dict4  s   !%%fd3$((C8!%%f-#''$7
 . 2 2< F ,)goo.E"9(Cbc  3_E)>(?%$-.C$D!5".5jA%(,EEhO#(5h?%-t(  )bggmmJ.G&--*-=C)bggmmH.E&--(-;C3::8DCC"$ %+FSF$9	 	 8$ %
h' %
x(!%
#H-/9>TU]>^ '\ !(:O!P*1.*A'.|'<  		 	 !%
-h7$%
"( 
 MMB 
 H 4   xJ$6#+TJ H$:y1 !6!67& z445	  u!4!4RWW[[!A#**277;;7J8[*hH]^00X5E99,GH00[C5G!??MKk!
 	
rM   c                Z    dj                  | | j                  | j                  xs d      S )Nz-<{self!s} of type {coll_type!r} from {src!s}>Galaxy)r   	coll_typerz   )r   r<   rz   r   s    r4   __repr__z_ComputedReqKindsMixin.__repr__  s'    ;F		txx7K8FL	
rM   c                4    t        | j                               S rY   )r   __unicode__r   s    r4   __str__z_ComputedReqKindsMixin.__str__  s    ))+,,rM   c                    | j                   *| j                  r| j                   dS | j                   dS dj                  t	        | j                         t	        | j
                              S )Nz collection from a Git repoz collection from a namespacez{fqcn!s}:{ver!s})rx   ry   )rx   is_scmr<   r   r   ry   r   s    r4   r   z"_ComputedReqKindsMixin.__unicode__  sd    99=A[[499+89		{">?  F		*0AFB	
rM   c                z    | j                   y| j                  r!| j                  t        | j                        syy)NFT)rx   is_dirrz   rZ   r   s    r4   r|   z3_ComputedReqKindsMixin.may_have_offline_galaxy_info  s1    99 08J4888TrM   c                   | j                   s| j                  dk(  st        d      t        |d      }|j	                  t        t
        j                  j                              dd }t        t
        j                  j                        j                  |      }t        | j                   d| j                   d| j                   d	d      }t
        j                  j                  ||t              S )
Nr   zHOnly installed collections from a Galaxy server have offline Galaxy infor   r   r   r   rC   -z.info)r|   r<   r   r   r   r!   r"   r   r*   r,   r-   ry   _SOURCE_METADATA_FILE)r   b_collection_pathb_srcb_path_partsb_metadata_dir
b_dir_names         r4   r~   z1_ComputedReqKindsMixin.construct_galaxy_info_path  s    00h9Nfgg *3HI{{8BGGKK#89!B?!"''++.33LA  0$))AdhhZuMVkl
 ww||NJ8MNNrM   c                8    | j                   j                  d      S )NrC   )rx   r   r   s    r4   _get_separate_ns_n_namez._ComputedReqKindsMixin._get_separate_ns_n_name  s    yys##rM   c                p    | j                   rt        | j                   d      | j                         d   S )Nz$ collections do not have a namespacer   
is_virtualr   r<   r   r   s    r4   r,   z _ComputedReqKindsMixin.namespace  s4    ??tyyk)MNOO++-a00rM   c                p    | j                   rt        | j                   d      | j                         d   S )Nz collections do not have a namer   r   s    r4   r-   z_ComputedReqKindsMixin.name  s4    ??tyyk)HIJJ++-b11rM   c                    | j                   st        | j                        S dj                  t        | j                        t        | j
                              S )Nz5<virtual namespace from {src!s} of type {src_type!s}>)rz   src_type)r   r   rx   r   rz   r<   r   s    r4   canonical_package_idz+_ComputedReqKindsMixin.canonical_package_id  sC    TYY'' DFy*Ytyy5IFJ	
rM   c                6    | j                   xs | j                  S rY   )r   
is_subdirsr   s    r4   r   z!_ComputedReqKindsMixin.is_virtual  s    {{-doo-rM   c                     | j                   dk(  S )Nr   r<   r   s    r4   is_filez_ComputedReqKindsMixin.is_file  s    yyF""rM   c                     | j                   dk(  S )Nr   r   r   s    r4   r   z_ComputedReqKindsMixin.is_dir      yyE!!rM   c                d    t        | j                        D cg c]  }t        |       c}S c c}w rY   )r_   rz   r   )r   r"   s     r4   namespace_collection_pathsz1_ComputedReqKindsMixin.namespace_collection_paths  s1     5TXX>
 dO
 	
 
s   -c                     | j                   dk(  S )Nr   r   r   s    r4   r   z!_ComputedReqKindsMixin.is_subdirs"  s    yyI%%rM   c                     | j                   dk(  S )Nr   r   r   s    r4   is_urlz_ComputedReqKindsMixin.is_url&  r   rM   c                     | j                   dk(  S )Nr   r   r   s    r4   r   z_ComputedReqKindsMixin.is_scm*  r   rM   c                    | j                   dv S )N>   r   r   r   r   r   r   r   s    r4   is_concrete_artifactz+_ComputedReqKindsMixin.is_concrete_artifact.  s    yyDDDrM   c                    | j                    S rY   )r   r   s    r4   is_online_index_pointerz._ComputedReqKindsMixin.is_online_index_pointer2  s    ,,,,rM   c                v    | j                   d   }|j                         xs |dk(  xs |j                  d       S )a2  Indicate if the version set is considered pinned.

        This essentially computes whether the version field of the current
        requirement explicitly requests a specific version and not an allowed
        version range.

        It is then used to help the resolvelib-based dependency resolver judge
        whether it's acceptable to consider a pre-release candidate version
        despite pre-release installs not being requested by the end-user
        explicitly.

        See https://github.com/ansible/ansible/pull/81606 for extra context.
        r   r   )<>z!=)ry   isdigitrn   )r   version_strings     r4   	is_pinnedz _ComputedReqKindsMixin.is_pinned6  sH     !%%' 
c! 8%%&67,
 	
rM   c                    | j                   S rY   )r}   r   s    r4   source_infoz"_ComputedReqKindsMixin.source_infoK  s       rM   N)T)"__name__
__module____qualname__r   r   r   r   classmethodr   r   r   r   r   r   r   r   propertyr|   r~   r   r,   r-   r   r   r   r   r   r   r   r   r   r   r  r  rr   rM   r4   r   r      s   1L`- 8 84 +A +AZ 9 9$ A A2 N
 N
`
-

  O $ 1 1 2 2 
 
 . . # # " " 
 
 & & " " " " E E - - 
 
( ! !rM   )rx   ry   rz   r<   signature_sources)rx   ry   rz   r<   rB   c                  (     e Zd ZdZd Z fdZ xZS )r   z An abstract requirement request.c                8    t        j                  | g|i |}|S rY   )RequirementNamedTuple__new__r   r   r   r   s       r4   r  zRequirement.__new__\  s!    $,,SB4B6BrM   c                *    t         t        |           y rY   )superr   r   r   r   r   	__class__s      r4   r   zRequirement.__init__`  s    k4)+rM   )r  r	  r
  __doc__r  r   __classcell__r  s   @r4   r   r   V  s     +, ,rM   c                  .     e Zd ZdZd Z fdZd Z xZS )r   z:A concrete collection candidate with its version resolved.c                8    t        j                  | g|i |}|S rY   )CandidateNamedTupler  r  s       r4   r  zCandidate.__new__j  s!    "**3@@@rM   c                *    t         t        |           y rY   )r  r   r   r  s      r4   r   zCandidate.__init__n  s    i')rM   c           
     \   | j                   dk7  rt        d| d      | j                  j                  | j                  | j
                  | j                        }| j                  | j                  | j                  | j                  | j                   t        g | j                  |            S )zPopulate a new Candidate instance with Galaxy signatures.
        :raises AnsibleAssertionError: If the supplied candidate is not sourced from a Galaxy-like index.
        r   zInvalid collection type for z0: unable to get signatures from a galaxy server.)r<   r   rz   get_collection_signaturesr,   r-   ry   r  rx   r   rB   )r   rB   s     r4   with_signatures_repopulatedz%Candidate.with_signatures_repopulatedq  s     99 '*FthN~(  A  AXX77		SWS[S[\
~~dii488TYY	RqTXTcTcRqfpRqHrssrM   )r  r	  r
  r  r  r   r   r  r  s   @r4   r   r   d  s     E*trM   )=r  
__future__r   r!   typingtcollectionsr   collections.abcr   r   globr   urllib.parser   yamlr	   TYPE_CHECKING3ansible.galaxy.collection.concrete_artifact_managerr
   TypeVarr   ansible.errorsr   r   ansible.galaxy.apir   ansible.galaxy.collectionr   r   +ansible.module_utils.common.text.convertersr   r   r   $ansible.module_utils.common.arg_specr   ansible.utils.collection_loaderr   ansible.utils.displayr   r   rP   rV   r   r&   r5   r)   rT   rW   rZ   r_   rd   rf   rl   ro   rv   r   r  r  r   r   rr   rM   r4   <module>r3     s    # 	  " ;  ! ?? ] J ? ( ; T T F @ ) %* !!% 
):,<B
D
 9ND3e! e!P #=2ef  !.Z[ ,,ttrM   