
    Vhi                     B   d dl Z d dlZ	 d dlZd dlmZ d dlmZ d dlm	Z	 d dl
mZ d dl
mZ d dl
mZ  e	j                         d        Z e	j                  d	g
      d        Z e	j                  d	g
      d        Zd Zd Zd Zd Zd Zd Zd Zd Zy# e$ r Y w xY w)    N)camel_dict_to_snake_dict)is_boto3_error_code)AWSRetry)ansible_dict_to_boto3_tag_list)boto3_tag_list_to_ansible_dict)compare_aws_tagsc                 f    | j                  d      }|j                         j                         d   S )Nlist_topicsTopicsget_paginatorpaginatebuild_full_resultclient	paginators     j/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/aws/plugins/module_utils/sns.py_list_topics_with_backoffr      s/    $$]3I113H==    NotFound)catch_extra_error_codesc                 j    | j                  d      }|j                  |      j                         d   S )Nlist_subscriptions_by_topicTopicArnSubscriptionsr   )r   	topic_arnr   s      r   &_list_topic_subscriptions_with_backoffr      s5    $$%BCIy1CCEoVVr   c                 f    | j                  d      }|j                         j                         d   S )Nlist_subscriptionsr   r   r   s     r    _list_subscriptions_with_backoffr!   #   s0    $$%9:I113ODDr   c                    	 t        | |      S # t        d      $ r 	 t        |       D cg c]  }|d   |k(  s| nc c}w c}cY S # t        j                  j
                  t        j                  j                  f$ r!}|j                  |d|        Y d }~Y y d }~ww xY wt        j                  j
                  t        j                  j                  f$ r }|j                  |d|        Y d }~y d }~ww xY w)NAuthorizationErrorr   z*Couldn't get subscriptions list for topic msg)r   r   r!   botocore
exceptionsClientErrorBotoCoreErrorfail_json_aws)r   moduler   subes        r   list_topic_subscriptionsr.   )   s    ^5fiHH34 b	b#CF#KlCsS]bkOkClll##//1D1D1R1RS 	b  *TU^T_(` aa	b 	'')) ^ 	Q&PQZP[$\]]	^sK    C8A==AC87B>BC8B9C8C33C8c                     	 t        |       }D cg c]  }|d   	 c}S # t        j                  j                  t        j                  j                  f$ r}|j                  |d       Y d }~bd }~ww xY wc c}w )NzCouldn't get topic listr$   r   )r   r&   r'   r(   r)   r*   )r   r+   topicsr-   ts        r   r
   r
   9   sp    ?*62 $**aAjM** ++X-@-@-N-NO ?Q$=>>?*s     A77A4A//A4c                 ^    t        | |      }d| }|D ]  }|j                  |      s|c S  y )N:)r
   endswith)r   r+   name
all_topicslookup_topictopics         r   topic_arn_lookupr9   A   s9    VV,Jtf:L >>,'Lr   c                     t        j                  |       }t        j                  |      }d| v rd| d   vrd|d   d<   d|v rd|d   vrd|d   d<   ||k7  }|S )NhttpdisableSubscriptionOverridesF)copydeepcopy)policy_apolicy_b	_policy_a	_policy_b
comparisons        r   compare_delivery_policiesrD   J   sz    h'Ih'I )&1AA@EIf<=)&1AA@EIf<=i'Jr   c                 >    | dk(  rt        j                  dd|      S |S )Nsmsz[^0-9+]* )rer,   )protocolendpoints     r   canonicalize_endpointrK   Y   s$     5vvj"h//Or   c                 2   	 t        | j                  |      d         S # t        d      $ r |j                  d       i cY S t        j
                  j                  t        j
                  j                  f$ r}|j                  |d       Y d }~y d }~ww xY w)N)ResourceArnTagsr#   z Permission denied accessing tagszCouldn't obtain topic tagsr$   )	r   list_tags_for_resourcer   warnr&   r'   r(   r)   r*   )r   r+   r   r-   s       r   get_tagsrQ   b   s    B-f.K.KXa.K.bci.jkk34 67	++X-@-@-N-NO BQ$@AABs     !B6B9BBc                 *   |j                   j                  d      }|j                   j                  d      }|j                   j                  d      }|j                   j                  d      }|j                   j                  d      }|j                   j                  d      }|j                   j                  dg       }	|j                   j                  dg       }
|j                   j                  d	g       }|j                   j                  d	g       }|j                   j                  d
d      }|j                   j                  dd      }|j                   j                  dg       }|j                  }|||||	|
|||||||d}|dk7  r|t        | |      v rA|j	                  t        | j                  |      d                |j                  d      |d<   t        | ||      D cg c]  }t        |       c}|d<   t        | ||      |d<   |S c c}w )Nr5   
topic_typestatesubscriptionspurge_subscriptionscontent_based_deduplicationsubscriptions_existingsubscriptions_deletedsubscriptions_addedtopic_createdFtopic_deletedattributes_set)r5   rS   rT   subscriptions_newrX   rY   rZ   subscriptions_purgerW   
check_moder[   r\   r]   absentr   
Attributeseffective_delivery_policydelivery_policytags)
paramsgetr`   r
   updater   get_topic_attributespopr.   rQ   )
connectionr+   r   r5   rS   rT   rU   rV   rW   rX   rY   rZ   r[   r\   r]   r`   infor,   s                     r   get_inform   l   s   ==V$D""<0JMMg&EMM%%o6M --++,AB"(--"3"34Q"R#]]../GL"MM--.ErJ --++,A2F --++,A2FMM%%ou=MMM%%ou=M]]&&'7<N""J  *"8!622'B &&(D J77KK01P1PZc1P1deq1rst&*hh/J&KD"#5MjZ`bk5l!
.1$S)!
_  
FI>VK	!
s   &Hc                    |j                   j                  d      yt        | ||      }t        ||j                   d   |j                   d         \  }}t	        |xs |      sy|j
                  ry|r	 | j                  |t        |             |r	 | j                  ||       yy# t        j                  j                  t        j                  j                  f$ r}|j                  |d       Y d }~gd }~ww xY w# t        j                  j                  t        j                  j                  f$ r}|j                  |d	       Y d }~yd }~ww xY w)
Nre   F
purge_tagsT)rM   rN   zCouldn't add tags to topicr$   )rM   TagKeyszCouldn't remove tags from topic)rf   rg   rQ   r   boolr`   tag_resourcer   r&   r'   r(   r)   r*   untag_resource)r   r+   r   existing_tags	to_update	to_deleter-   s          r   update_tagsrw      sE   }} (VVY7M+M6==;PRXR_R_`lRmnIy	&Y'	FI<Z[d<ef 	K!!i!K  ##//1D1D1R1RS 	F  (D EE	F
 ##//1D1D1R1RS 	K  (I JJ	Ks0   4B( C? (7C<C77C<?7E6EE)r=   rH   r&   ImportError0ansible.module_utils.common.dict_transformationsr   <ansible_collections.amazon.aws.plugins.module_utils.botocorer   ;ansible_collections.amazon.aws.plugins.module_utils.retriesr   ;ansible_collections.amazon.aws.plugins.module_utils.taggingr   r   r   jittered_backoffr   r   r!   r.   r
   r9   rD   rK   rQ   rm   rw    r   r   <module>r      s     		 V \ P f f X > >
 J<@W AW
 J<@E AE
^ +B'TW  		s   B BB