
    Vh{                     N    d dl mZmZmZ eZd dlZd dlmZm	Z	 d dl
mZ d ZddZy)    )absolute_importdivisionprint_functionN)	fetch_urlurl_argument_spec)	to_nativec                      t               } | j                  t        t        dd      t        dd      t        ddd                   | S )	zw
    Creates an argument spec that can be used with any module
    that will be requesting content via Rundeck API
    Tstr)requiredtypeint'   )r   default)r   r   no_log)urlapi_version	api_token)r   updatedict)api_argument_specs    r/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/module_utils/rundeck.pyr   r      sJ    
 *+T$U+eR05>      c           
         t        | | j                  d   d| j                  d   d|t        j                  |      ||d| j                  d   d      \  }}|d	   d
k(  r*| j	                  dt        j
                  |d                no|d	   dk(  rd|fS |d	   dk(  r*| j	                  dt        j
                  |d                n1|d	   dk\  r)| j	                  dt        j
                  |d                	 |j                         }|sd|fS t        j
                  |      }||fS # t        $ r'}	| j	                  dt        |	      |       Y d}	~	yd}	~	wt        $ r'}	| j	                  dt        |	             Y d}	~	yd}	~	ww xY w)a  Manages Rundeck API requests via HTTP(S)

    :arg module:   The AnsibleModule (used to get url, api_version, api_token, etc).
    :arg endpoint: The API endpoint to be used.
    :kwarg data:   The data to be sent (in case of POST/PUT).
    :kwarg method: "POST", "PUT", etc.

    :returns: A tuple of (**response**, **info**). Use ``response.read()`` to read the data.
        The **info** contains the 'status' and other meta data. When a HttpError (status >= 400)
        occurred then ``info['body']`` contains the error response data::

    Example::

        data={...}
        resp, info = fetch_url(module,
                               "http://rundeck.example.org",
                               data=module.jsonify(data),
                               method="POST")
        status_code = info["status"]
        body = resp.read()
        if status_code >= 400 :
            body = info['body']
    r   z/api/r   /application/jsonr   )zContent-TypeAcceptzX-Rundeck-Auth-Token)moduler   datamethodheadersstatusi  zToken authorization failedbody)msgexecution_infoi  Ni  zJob executions limit reachedi  zRundeck API errorzRundeck API request error)r#   	exceptionr$   zNo valid JSON response)
r   paramsjsondumps	fail_jsonloadsreadAttributeErrorr   
ValueError)
r   endpointr   r   content_typeresponseinfocontentjson_responseerrors
             r   api_requestr5      s   2 MM% MM-(

 ZZ(($*MM+$>
NHd  H~9(,

4<(@ 	 	B	h3	Tz	h3	;(,

4<(@ 	 	B	h3	0(,

4<(@ 	 	B
--/: JJw/M $&& 
+& 	 	
 	

  
(&" 	 	
 	

s*   <D+ D+ +	F	4EF	"FF	)NGETr   )
__future__r   r   r   r   __metaclass__r'   ansible.module_utils.urlsr   r   +ansible.module_utils.common.text.convertersr   r   r5    r   r   <module>r<      s'    A @  B AH
r   