
    Vh                         d Z dZd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	 Zed
k(  r e        yy# e$ r Y $w xY w)a
  
module: sns
short_description: Send Amazon Simple Notification Service messages
version_added: 1.0.0
description:
  - Sends a notification to a topic on your Amazon SNS account.
author:
  - Michael J. Schultz (@mjschultz)
  - Paul Arthur (@flowerysong)
options:
  msg:
    description:
      - Default message for subscriptions without a more specific message.
    required: true
    aliases: [ "default" ]
    type: str
  subject:
    description:
      - Message subject
    type: str
  topic:
    description:
      - The name or ARN of the topic to publish to.
    required: true
    type: str
  email:
    description:
      - Message to send to email subscriptions.
    type: str
  email_json:
    description:
      - Message to send to email-json subscriptions.
    type: str
  sqs:
    description:
      - Message to send to SQS subscriptions.
    type: str
  sms:
    description:
      - Message to send to SMS subscriptions.
    type: str
  http:
    description:
      - Message to send to HTTP subscriptions.
    type: str
  https:
    description:
      - Message to send to HTTPS subscriptions.
    type: str
  application:
    description:
      - Message to send to application subscriptions.
    type: str
  lambda:
    description:
      - Message to send to Lambda subscriptions.
    type: str
  message_attributes:
    description:
      - Dictionary of message attributes. These are optional structured data entries to be sent along to the endpoint.
      - This is in AWS's distinct Name/Type/Value format; see example below.
    type: dict
  message_structure:
    description:
      - The payload format to use for the message.
      - This must be C(json) to support protocol-specific messages (C(http), C(https), C(email), C(sms), C(sqs)).
      - It must be C(string) to support I(message_attributes).
    default: json
    choices: ['json', 'string']
    type: str
  message_group_id:
    description:
      - A tag which is used to process messages that belong to the same group in a FIFO manner.
      - Has to be included when publishing a message to a fifo topic.
      - Can contain up to 128 alphanumeric characters and punctuation.
    type: str
    version_added: 5.4.0
  message_deduplication_id:
    description:
      - Only in connection with the message_group_id.
      - Overwrites the auto generated MessageDeduplicationId.
      - Can contain up to 128 alphanumeric characters and punctuation.
      - Messages with the same deduplication id getting recognized as the same message.
      - Gets overwritten by an auto generated token, if the topic has ContentBasedDeduplication set.
    type: str
    version_added: 5.4.0

extends_documentation_fragment:
  - amazon.aws.region.modules
  - amazon.aws.common.modules
  - amazon.aws.boto3
a  
- name: Send default notification message via SNS
  community.aws.sns:
    msg: '{{ inventory_hostname }} has completed the play.'
    subject: Deploy complete!
    topic: deploy
  delegate_to: localhost

- name: Send notification messages via SNS with short message for SMS
  community.aws.sns:
    msg: '{{ inventory_hostname }} has completed the play.'
    sms: deployed!
    subject: Deploy complete!
    topic: deploy
  delegate_to: localhost

- name: Send message with message_attributes
  community.aws.sns:
    topic: "deploy"
    msg: "message with extra details!"
    message_attributes:
      channel:
        data_type: String
        string_value: "mychannel"
      color:
        data_type: String
        string_value: "green"
  delegate_to: localhost

- name: Send message to a fifo topic
  community.aws.sns:
    topic: "deploy"
    msg: "Message with message group id"
    subject: Deploy complete!
    message_group_id: "deploy-1"
  delegate_to: localhost
a  
msg:
  description: Human-readable diagnostic information
  returned: always
  type: str
  sample: OK
message_id:
  description: The message ID of the submitted message
  returned: when success
  type: str
  sample: 2f681ef0-6d76-5c94-99b2-4ae3996ce57b
sequence_number:
  description: A 128 bits long sequence number which gets assigned to the message in fifo topics
  returned: when success
  type: str
    N)BotoCoreError)ClientError)AnsibleCommunityAWSModule)topic_arn_lookupc            
         g d} t        t        ddg      t               t        d      t        d      t        dd	gd
      t               t                     }| D ]  }t               ||<    t        |      }t        |j                  d   |j                  d   |j                  d         }|j                  d   r6|j                  d   d	k7  r|j                  d       |j                  d   |d<   |j                  d   r3|j                  d   |d<   |j                  d   r|j                  d   |d<   d|d   i}| D ]N  }|j                  |   s|d   dk7  r|j                  d       |j                  |   ||j	                  dd      <   P |j                  d      }|j                  d   }d |v r||d!<   nt        |||      |d!<   |d!   s|j                  d"|        |d   dk(  rt        j                  |      |d<   	  |j                  d)i |}t        d$d%   &      }
|j                  d   r|d'   |
d(<    |j                  d)i |
 y # t        t        f$ r}	|j                  |	d#       Y d }	~	ad }	~	ww xY w)*N)httphttpsemail
email_jsonsmssqsapplicationlambdaTdefault)requiredaliases)r   dict)typejsonstring)choicesr   )msgsubjecttopicmessage_attributesmessage_structuremessage_group_idmessage_deduplication_id)argument_specr   r   r   )MessageSubjectMessageStructurer   zLmessage_attributes is only supported when the message_structure is "string".)r   MessageAttributesr   MessageGroupIdr   MessageDeduplicationIdr    r"   zOProtocol-specific messages are only supported when message_structure is "json"._-snsr   :TopicArnzCould not find topic: zFailed to publish messageOK	MessageId)r   
message_idSequenceNumbersequence_number )r   AnsibleAWSModuleparams	fail_jsonreplaceclientr   r   dumpspublishr   r   fail_json_aws	exit_json)	protocolsr   pmodule
sns_kwargsdict_msgr5   r   resulte
sns_results              e/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/aws/plugins/modules/sns.pymainrC      s   	I $4D!V,'96J!%M  "6a" M:Fe$i(':;J }})*==,-9!op*0--8L*M
&'}}'('-}}5G'H
#$==3439==A[3\J/0:i01H ===,-7  %v w,2MM!,<HQYYsC()	= ]]5!FMM'"E
e|!&
:!1&&%!H
:j!5eW=>$%/ $

8 4
9A-*- $6++>?J}}'((./?(@
$%F"z" ;' AQ$?@@As   I I?"I::I?__main__)DOCUMENTATIONEXAMPLESRETURNr   botocore.exceptionsr   r   ImportError>ansible_collections.community.aws.plugins.module_utils.modulesr   r1   :ansible_collections.community.aws.plugins.module_utils.snsr   rC   __name__r0       rB   <module>rN      sf   [z$L
" 	1/ y WL#^ zF m  		s   5 ==