
    Vh$                         d dl mZmZmZ eZdZdZd dlZd dl	Z	dZ
	 d dlZdZd dlmZmZ d dlmZ d d	lmZ d
 Zd Zedk(  r e        yy# e$ r  e	j                         Z
dZY Bw xY w)    )absolute_importdivisionprint_functiona	  
---
module: rabbitmq_queue
author: Manuel Sousa (@manuel-sousa)

short_description: Manage rabbitMQ queues
description:
  - This module uses rabbitMQ Rest API to create/delete queues.
  - Due to limitations in the API, it cannot modify existing queues.
requirements: [ "requests >= 1.0.0" ]
options:
    name:
        description:
            - Name of the queue.
        type: str
        required: true
    state:
        description:
            - Whether the queue should be present or absent.
        type: str
        choices: [ "present", "absent" ]
        default: present
    durable:
        description:
            - whether queue is durable or not.
        type: bool
        default: true
    auto_delete:
        description:
            - if the queue should delete itself after all queues/queues unbound from it.
        type: bool
        default: false
    message_ttl:
        description:
            - How long a message can live in queue before it is discarded (milliseconds).
        type: int
    auto_expires:
        description:
            - How long a queue can be unused before it is automatically deleted (milliseconds).
        type: int
    max_length:
        description:
            - How many messages can the queue contain before it starts rejecting.
        type: int
    dead_letter_exchange:
        description:
            - Optional name of an exchange to which messages will be republished if they
            - are rejected or expire.
        type: str
    dead_letter_routing_key:
        description:
            - Optional replacement routing key to use when a message is dead-lettered.
            - Original routing key will be used if unset.
        type: str
    max_priority:
        description:
            - Maximum number of priority levels for the queue to support.
            - If not set, the queue will not support message priorities.
            - Larger numbers indicate higher priority.
        type: int
    arguments:
        description:
            - extra arguments for queue. If defined this argument is a key/value dictionary
            - Arguments here take precedence over parameters. If both are defined, the
              argument will be used.
        type: dict
        default: {}
extends_documentation_fragment:
- community.rabbitmq.rabbitmq

a  
- name: Create a queue
  community.rabbitmq.rabbitmq_queue:
    name: myQueue

- name: Create a queue on remote host
  community.rabbitmq.rabbitmq_queue:
    name: myRemoteQueue
    login_user: user
    login_password: secret
    login_host: remote.example.org

# You may specify different types of queues using the arguments parameter.
- name: Create RabbitMQ stream
  become: yes
  community.rabbitmq.rabbitmq_queue:
    name: test-x
    arguments:
      x-queue-type: stream
      x-max-age: 24h
NTF)AnsibleModulemissing_required_lib)parse)rabbitmq_argument_specc           	          ||vr||v r| j                  d|z         y y ||v r/||   ||   k7  r#| j                  d|d||   d||   d       y y | j                  d|d||   d	       y )
NzwRabbitMQ RESTAPI doesn't support attribute changes for existing queues.Attempting to set %s which is not currently set.)msgz]RabbitMQ RESTAPI doesn't support attribute changes for existing queues.
Attempting to change z from 'z' to ''z[RabbitMQ RESTAPI doesn't support attribute changes for existing queues.Attempting to unset z which is currently set to 'z'.)	fail_json)modulecurrent_argsdesired_argsarg_names       u/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/rabbitmq/plugins/modules/rabbitmq_queue.pycheck_if_arg_changedr   y   s    |#|#HJRS   $ |#H%h)??  HPR^_gRhjvw  kAB !  @ QY[ghp[qs      c                  
   t               } | j                  t        t        dddgd      t        dd      t        dd      t        d	d      t        d d
      t        d d
      t        d d
      t        d d      t        d dd	      t        t               d      t        d d
                   t        | d      }|j                  d   d|j                  d   d|j                  d   dt        j                  |j                  d   d      dt        j                  |j                  d   d      	}t        s |j                  t        d      t               t        d	|j                  d         }t        j                  ||j                  d   |j                  d   f|j                  d   |j                  d   |j                  d    f!      }|j                  d"k(  rd}|j                         }n;|j                  d#k(  rd	}|j                  }n|j                  d$|j                  %       d&d'd(d)d*d+d,}|j!                         D ]4  \  }}	|j                  |   |j                  |   |j                  d-   |	<   6 |j                  d.   dk(  r }
n}
|
s|j                  d"k(  ru|j                  d.   dk(  rct#        ||j                  d/       t#        |||j                  d0       |j%                         D ]   }t#        ||d-   |j                  d-   |       " |j&                  r.|
|d1<   |d2<   |j                  d-   |d-<    |j(                  d;i | |
r|j                  d.   dk(  rt        j*                  ||j                  d   |j                  d   fd3d4it        j,                  |j                  d/   |j                  d0   |j                  d-   d5      |j                  d   |j                  d   |j                  d    f6      }np|j                  d.   dk(  r^t        j.                  ||j                  d   |j                  d   f|j                  d   |j                  d   |j                  d    f!      }|j                  d7k(  s|j                  d8k(  rd|d1<    |j(                  d;i | y |j                  d9|j                  |j                  :       y |j)                  d	|j                  d          y )<Npresentabsentstr)defaultchoicestypeT)requiredr   bool)r   r   Fint)r   r   no_logdict)statenamedurableauto_deletemessage_ttlauto_expires
max_lengthdead_letter_exchangedead_letter_routing_key	argumentsmax_priority)argument_specsupports_check_modelogin_protocolz://
login_host:
login_portz/api/queues/vhost /r"   requests)r   	exception)changedr"   
login_userlogin_passwordca_certclient_cert
client_key)authverifycert   i  zBInvalid response from RESTAPI when trying to check if queue exists)r   detailszx-message-ttlz	x-expireszx-max-lengthzx-dead-letter-exchangezx-dead-letter-routing-keyzx-max-priority)r%   r&   r'   r(   r)   r+   r*   r!   r#   r$   r7   rA   zcontent-typezapplication/json)r#   r$   r*   )r=   headersdatar>   r?         zError creating queue)r   statusrA    )r	   updater    r   paramsurllib_parsequoteHAS_REQUESTSr   r   REQUESTS_IMP_ERRr5   getstatus_codejsontextitemsr   values
check_mode	exit_jsonputdumpsdelete)r,   r   urlresultrqueue_existsresponsearg_mapkvadd_or_delete_requiredargs               r   mainrc      s   *,My9h2GeTt%0F3U8T6d7Du5!%d!?$(E%$P467d7	
 DQF 	&'l#l#6==1266==0"5C 1*=IYZ%fmmF&;<F 	Sl ;V]]K[=\]"MM)4FMM-<XZ`ZgZghtZu;v	xA 	}}668	
#	66TFF 	 	
 '#$ 8#>(G  =1==',2MM!,<FMM+&q)= }}W*%1!1!- "amms&:v}}W?UYb?bVXv}}iHVXv}}mL>># 	aC +)>k@Z\_`	a 2y$y$mmK8{"6" ==!Y.mmL16==AQ3RS');<ZZ%}}Y7#)==#?!'{!;! 
 }}Y/mmM2FMM,4OPA ]]7#x/6==+FVfHg*h'-}}Y'?v}}UbGcekerers  fA  GBCA ==C1==C#7 $F9F&v&*}}   	v& 	 	
r   __main__)
__future__r   r   r   r   __metaclass__DOCUMENTATIONEXAMPLESrP   	tracebackrM   r5   rL   ImportError
format_excansible.module_utils.basicr   r   %ansible.module_utils.six.moves.urllibr   rJ   Dansible_collections.community.rabbitmq.plugins.module_utils.rabbitmqr	   r   rc   __name__rG   r   r   <module>rp      s    A @FP,   L
 K G g,u
p zF o  +y++-Ls   A
 
A%$A%