
    Vh?                     @   d dl mZmZmZ eZd dlm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Zd ZdZ	 d dlZd dlZd	Z eej2                        ZddZd Zd ZddZ ddZ!d Z"d Z#y# e$ r	 d dlmZ Y Lw xY w# e$ r dZ ej8                         Zd
Zi ZY Hw xY w)    )absolute_importdivisionprint_function)missing_required_lib)	to_native)integer_typesstring_typesLooseVersion)urljoinNc                 r    t        |       }|t        d      k\  rdddS |t        d      k\  rddddS ddddS )	Nz4.0.0Td   )iteratorper_pagez3.7.0F)as_listget_allr   )r   allr   r
   )versiongitlab_versions     q/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/module_utils/gitlab.py_determine_list_all_kwargsr      sK    !'*Ng.. c22	<0	0 TsCC 3??    TFc           	          t        t        d      t        dd      t        dd      t        dd            }| r|j                  |        |S )Nstr)typeT)r   no_log)ca_path	api_tokenapi_oauth_tokenapi_job_token)dictupdate)specarg_specs     r   auth_argument_specr%   2   sH    % E$/%5d3	H Or   c                    	 | j                   j                  |      }|S # t        $ r^}| j                  }	 | j                   j                  |j                  dz   |z         }n# t        $ r}Y d }~Y d }~y d }~ww xY wY d }~|S d }~ww xY w)N/)projectsget	Exceptionuserusername)gitlab_instance
identifierprojectecurrent_users        r   find_projectr2   >   s    !**..z: N  &++	%..22<3H3H33NQ[3[\G 	4	  Ns7    	BB+A! B!	A8*B3A88BBc                 j    	 | j                   j                  |      }|S # t        $ r
}Y d }~y d }~ww xY wN)groupsr)   r*   )r-   r.   groupr0   s       r   
find_groupr7   K   s9    &&**:6 L  s    	22c           	          t         s"| j                  t        dd      t               t        j
                  }|5t        |      t        |      k  r| j                  d|d|d|d	       y y y )
Nzpython-gitlabz/https://python-gitlab.readthedocs.io/en/stable/)url)msg	exceptionz4This module requires python-gitlab Python module >= z (installed version: z+). Please upgrade python-gitlab to version z
 or above.r:   )HAS_GITLAB_PACKAGE	fail_jsonr   GITLAB_IMP_ERRgitlab__version__r   )modulemin_versionr   s      r   ensure_gitlab_packagerD   T   st    $_:kl$ 	 	
 ''N<#?,{B[#[ = 	 	
 $\r   c                 D   t        | |       | j                  d   }| j                  d   }| j                  d   }| j                  d   }| j                  d   }| j                  d   }| j                  d   }| j                  d	   }	|r|r|n|}
	 |r=d
||d}t        j                  t	        |d      ||
      }|j                         }|d   }t        j                  ||
|||	d      }|j                          |S # t        j                  j                  t        j                  j                  f$ r)}| j                  dt        |      z         Y d }~S d }~wt        j                  j                  $ r)}| j                  dt        |      z         Y d }~S d }~ww xY w)N)rC   api_urlvalidate_certsr   api_usernameapi_passwordr   r   r    password)
grant_typer,   rJ   zoauth/token)dataverifyaccess_token   )r9   
ssl_verifyprivate_tokenoauth_token	job_tokenapi_versionz&Failed to connect to GitLab server: %sr<   zFailed to connect to GitLab server: %s.             GitLab remove Session API now that private tokens are removed from user API endpoints since version 10.2.)rD   paramsrequestspostr   jsonr@   Gitlabauth
exceptionsGitlabAuthenticationErrorGitlabGetErrorr>   r   GitlabHttpError)rB   rC   
gitlab_urlrG   r   gitlab_usergitlab_passwordgitlab_tokengitlab_oauth_tokengitlab_job_tokenrM   rL   resp	resp_datar-   r0   s                   r   gitlab_authenticationrg   c   s   &k:y)J]]#34NmmI&G--/KmmN3O==-L'89}}_5&7WFG ",+SbcD==]!C$W]^D		I!*>!: --J6Ye4FRbpqs  779J9J9Y9YZ VE	RSTUU
 	 -- G w zC  DE  zFF 	G 	G 	Gs%   A*C; ;7F2E F6FFc                     | D cg c]  }t        |j                         }}g d}|D ]6  }t        |j                               D ]  }||vs|j	                  |        8 |S c c}w )N)keyvaluemasked	protectedvariable_typeenvironment_scoperaw)r!   
attributeslistkeyspop)gitlab_variablesxexisting_variablesKNOWNitemri   s         r   filter_returned_variablesry      sn    6FG$q||,GG`E" 		$ 	C%	  Hs   A$c           
         t               }| j                         D ]  \  }}t        |t        t        t
        f      r"|j                  |t        |      ddddd       Ct        |t              r||j                  d      |j                  d      |j                  d      |j                  d      |j                  d      d}|j                  d	      r|j                  d	      |d	<   |j                  |       |j                  d
        |S )NFenv_var)namerj   rk   rl   ro   rm   rj   rk   rl   ro   rm   rn   z4value must be of type string, integer, float or dictr<   )rq   items
isinstancer	   r   floatappendr   r!   r)   r>   )varsrB   	variablesrx   rj   new_items         r   vars_to_variablesr      s    Izz| YeelM5AB  Z#!& %.	 t$7+))H-"YY{3yy'!&?!;H yy,-05		:M0N,-X& !WX;Y> r   r4   )$
__future__r   r   r   r   __metaclass__ansible.module_utils.basicr   +ansible.module_utils.common.text.convertersr   ansible.module_utils.sixr   r	   Bansible_collections.community.general.plugins.module_utils.versionr   urlparser   ImportErrorurllib.parse	tracebackr   r?   r@   rV   r=   rA   list_all_kwargsr*   
format_excr%   r2   r7   rD   rg   ry   r    r   r   <module>r      s    C B ; A @ [%  	@ 	01C1CDO	

 F"}  %$%0  F)Y))+NO	s"   A- A> -A;:A;>BB