
    VhT                     z    d dl mZmZmZ eZdZdZdZd dl	m
Z
 d dlmZmZ  G d de      Zd	 Zed
k(  r e        yy)    )absolute_importdivisionprint_functionaE  
module: rundeck_project

short_description: Manage Rundeck projects
description:
  - Create and remove Rundeck projects through HTTP API.
author: "Loic Blot (@nerzhul)"
attributes:
  check_mode:
    support: full
  diff_mode:
    support: none
options:
  state:
    type: str
    description:
      - Create or remove Rundeck project.
    choices: ['present', 'absent']
    default: 'present'
  name:
    type: str
    description:
      - Sets the project name.
    required: true
  api_token:
    description:
      - Sets the token to authenticate against Rundeck API.
    aliases: ["token"]
  client_cert:
    version_added: '0.2.0'
  client_key:
    version_added: '0.2.0'
  force:
    version_added: '0.2.0'
  force_basic_auth:
    version_added: '0.2.0'
  http_agent:
    version_added: '0.2.0'
  url_password:
    version_added: '0.2.0'
  url_username:
    version_added: '0.2.0'
  use_proxy:
    version_added: '0.2.0'
  validate_certs:
    version_added: '0.2.0'
extends_documentation_fragment:
  - ansible.builtin.url
  - community.general.attributes
  - community.general.rundeck
a  
- name: Create a rundeck project
  community.general.rundeck_project:
    name: "Project_01"
    label: "Project 01"
    description: "My Project 01"
    url: "https://rundeck.example.org"
    api_version: 39
    api_token: "mytoken"
    state: present

- name: Remove a rundeck project
  community.general.rundeck_project:
    name: "Project_01"
    url: "https://rundeck.example.org"
    api_token: "mytoken"
    state: absent
aU  
rundeck_response:
  description: Rundeck response when a failure occurs.
  returned: failed
  type: str
before:
  description: Dictionary containing project information before modification.
  returned: success
  type: dict
after:
  description: Dictionary containing project information after modification.
  returned: success
  type: dict
)AnsibleModule)api_argument_specapi_requestc                   $    e Zd Zd Zd Zd Zd Zy)RundeckProjectManagerc                     || _         y )N)module)selfr   s     u/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/modules/rundeck_project.py__init__zRundeckProjectManager.__init__o   s	        c                 n    t        | j                  d| j                  j                  d   z        \  }}|S )N
project/%sname)r   endpoint)r   r   params)r   respinfos      r   get_project_factsz'RundeckProjectManager.get_project_factsr   s5     ;;!DKK$6$6v$>>

d
 r   c                 :   | j                         }|| j                  j                  r7| j                  j                  di d| j                  j                  d   i       t        | j                  dd| j                  j                  d   i d      \  }}|d   d	k(  r-| j                  j                  di | j                                y | j                  j                  d
|d   z  i | j                                y | j                  j                  d||       y )NTr   changedbeforeafterprojectsPOST)r   config)r   r   methoddatastatus   z/Unhandled HTTP status %d, please report the bug)msgr   r   F)r   r   
check_mode	exit_jsonr   r   	fail_json)r   factsr   r   s       r   create_or_update_projectz.RundeckProjectManager.create_or_update_projectz   s   &&(={{%%%%  2 26 : &  %{{# KK..v6 	JD$ H~$%%d2TE[E[E]%^%%*[^bck^l*l-/t7M7M7O & Q KK!!%U!Kr   c                 2   | j                         }|| j                  j                  di i        y | j                  j                  s2t	        | j                  d| j                  j
                  d   z  d       | j                  j                  d|i        y )NFr   r   r   DELETE)r   r   r!   T)r   r   r'   r&   r   r   )r   r)   s     r   remove_projectz$RundeckProjectManager.remove_project   s    &&(=KK!!%"!E ;;));;)DKK,>,>v,FF# KK!!$uB!Gr   N)__name__
__module____qualname__r   r   r*   r-    r   r   r
   r
   n   s    L@Hr   r
   c            	         t               } | j                  t        t        dddgd      t        dd                   dg| d	   d
<   t        | d      }|j                  d   dk  r|j                  d       t        |      }|j                  d   dk(  r|j                          y |j                  d   dk(  r|j                          y y )Nstrpresentabsent)typechoicesdefaultT)requiredr6   )stater   token	api_tokenaliases)argument_specsupports_check_modeapi_version   z!API version should be at least 14)r%   r:   )	r   updatedictr   r   r(   r
   r*   r-   )r>   r   rundecks      r   mainrE      s    %'M	8'<iP4e, 
 .5IM+y)# F
 }}]#b(@A#F+G}}W*((*	w	8	+  
,r   __main__N)
__future__r   r   r   r6   __metaclass__DOCUMENTATIONEXAMPLESRETURNansible.module_utils.basicr   Bansible_collections.community.general.plugins.module_utils.rundeckr   r   objectr
   rE   r.   r1   r   r   <module>rO      s[    A @2h&
  59HF 9Hx!2 zF r   