
    Vh                        d Z dZd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
 Zd ZddZddZddZddZ	 ddZddZd dZ	 	 	 	 	 	 d!dZ	 	 	 	 	 	 d!dZd"dZ	 d#dZ	 d$dZd Zedk(  r e        yy# e$ r Y {w xY w)%a  
---
module: kinesis_stream
version_added: 1.0.0
short_description: Manage a Kinesis Stream.
description:
  - Create or Delete a Kinesis Stream.
  - Update the retention period of a Kinesis Stream.
  - Update Tags on a Kinesis Stream.
  - Enable/disable server side encryption on a Kinesis Stream.
author:
  - Allen Sanabria (@linuxdynasty)
options:
  name:
    description:
      - The name of the Kinesis Stream you are managing.
    required: true
    type: str
  shards:
    description:
      - The number of shards you want to have with this stream.
      - This is required when I(state=present)
    type: int
  retention_period:
    description:
      - The length of time (in hours) data records are accessible after they are added to
        the stream.
      - The default retention period is 24 hours and can not be less than 24 hours.
      - The maximum retention period is 168 hours.
      - The retention period can be modified during any point in time.
    type: int
  state:
    description:
      - Create or Delete the Kinesis Stream.
    default: present
    choices: [ 'present', 'absent' ]
    type: str
  wait:
    description:
      - Wait for operation to complete before returning.
    default: true
    type: bool
  wait_timeout:
    description:
      - How many seconds to wait for an operation to complete before timing out.
    default: 300
    type: int
  tags:
    description:
      - "A dictionary of resource tags of the form: C({ tag1: value1, tag2: value2 })."
    aliases: [ "resource_tags" ]
    type: dict
  encryption_state:
    description:
      - Enable or Disable encryption on the Kinesis Stream.
    choices: [ 'enabled', 'disabled' ]
    type: str
  encryption_type:
    description:
      - The type of encryption.
      - Defaults to C(KMS)
    choices: ['KMS', 'NONE']
    type: str
  key_id:
    description:
      - The GUID or alias for the KMS key.
    type: str
extends_documentation_fragment:
  - amazon.aws.common.modules
  - amazon.aws.region.modules
  - amazon.aws.boto3
a  
# Note: These examples do not set authentication details, see the AWS Guide for details.

# Basic creation example:
- name: Set up Kinesis Stream with 10 shards and wait for the stream to become ACTIVE
  community.aws.kinesis_stream:
    name: test-stream
    shards: 10
    wait: true
    wait_timeout: 600
  register: test_stream

# Basic creation example with tags:
- name: Set up Kinesis Stream with 10 shards, tag the environment, and wait for the stream to become ACTIVE
  community.aws.kinesis_stream:
    name: test-stream
    shards: 10
    tags:
      Env: development
    wait: true
    wait_timeout: 600
  register: test_stream

# Basic creation example with tags and increase the retention period from the default 24 hours to 48 hours:
- name: Set up Kinesis Stream with 10 shards, tag the environment, increase the retention period and wait for the stream to become ACTIVE
  community.aws.kinesis_stream:
    name: test-stream
    retention_period: 48
    shards: 10
    tags:
      Env: development
    wait: true
    wait_timeout: 600
  register: test_stream

# Basic delete example:
- name: Delete Kinesis Stream test-stream and wait for it to finish deleting.
  community.aws.kinesis_stream:
    name: test-stream
    state: absent
    wait: true
    wait_timeout: 600
  register: test_stream

# Basic enable encryption example:
- name: Encrypt Kinesis Stream test-stream.
  community.aws.kinesis_stream:
    name: test-stream
    state: present
    shards: 1
    encryption_state: enabled
    encryption_type: KMS
    key_id: alias/aws/kinesis
    wait: true
    wait_timeout: 600
  register: test_stream

# Basic disable encryption example:
- name: Encrypt Kinesis Stream test-stream.
  community.aws.kinesis_stream:
    name: test-stream
    state: present
    shards: 1
    encryption_state: disabled
    encryption_type: KMS
    key_id: alias/aws/kinesis
    wait: true
    wait_timeout: 600
  register: test_stream
a'  
stream_name:
  description: The name of the Kinesis Stream.
  returned: when state == present.
  type: str
  sample: "test-stream"
stream_arn:
  description: The amazon resource identifier
  returned: when state == present.
  type: str
  sample: "arn:aws:kinesis:east-side:123456789:stream/test-stream"
stream_status:
  description: The current state of the Kinesis Stream.
  returned: when state == present.
  type: str
  sample: "ACTIVE"
retention_period_hours:
  description: Number of hours messages will be kept for a Kinesis Stream.
  returned: when state == present.
  type: int
  sample: 24
tags:
  description: Dictionary containing all the tags associated with the Kinesis stream.
  returned: when state == present.
  type: dict
  sample: {
      "Name": "Splunk",
      "Env": "development"
  }
    N)	to_native)camel_dict_to_snake_dict)boto3_tag_list_to_ansible_dict)compare_aws_tags)AnsibleCommunityAWSModulec                     d}d}d|i}t               }	  | j                  di |d   }d}||t        |      fS # t        j                  j                  $ r}t        |      }Y d}~;d}~ww xY w)a_  Retrieve the tags for a Kinesis Stream.
    Args:
        client (botocore.client.EC2): Boto3 client.
        stream_name (str): Name of the Kinesis stream.

    Basic Usage:
        >>> client = boto3.client('kinesis')
        >>> stream_name = 'test-stream'
        >> get_tags(client, stream_name)

    Returns:
        Tuple (bool, str, dict)
     F
StreamNameTagsTN )dictlist_tags_for_streambotocore
exceptionsClientErrorr   r   )clientstream_nameerr_msgsuccessparamsresultses          p/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/aws/plugins/modules/kinesis_stream.pyget_tagsr      s     GGkF fG-&--77? G;GDDD ** A,s   9 A+A&&A+c                    d}d}d|i}t               }d}t               }	 |rJ | j                  di |d   }|j                  |j	                  d             |d   }|r|d   d	   |d
<   |rJ||d<   t        |D cg c]  }d|d   v s| c}      }	t        |      |	z
  |d<   |	|d<   t        |      |d<   d}|||fS c c}w # t        j                  j                  $ r}
t        |
      }Y d}
~
7d}
~
ww xY w)a)  Retrieve a Kinesis Stream.
    Args:
        client (botocore.client.EC2): Boto3 client.
        stream_name (str): Name of the Kinesis stream.

    Basic Usage:
        >>> client = boto3.client('kinesis')
        >>> stream_name = 'test-stream'

    Returns:
        Tuple (bool, str, dict)
    r	   Fr
   TStreamDescriptionShardsHasMoreShardsShardIdExclusiveStartShardIdEndingSequenceNumberSequenceNumberRangeOpenShardsCountClosedShardsCountShardsCountNr   )
r   listdescribe_streamextendpoplenr   r   r   r   )r   r   r   r   r   r   has_more_shardsshardssnum_closed_shardsr   s              r   find_streamr0      s-    GGkF fGOVF,f,,6v67JKGMM'++h/0%o6O28*Y2G./  #F iq6LPQRgPh6h ij%([3D%D!"'8#$!$V GW$$ !j
 ** A,s6   AC ,C :B=B=-C =C C4C//C4c                    d}t        j                          |z   }d}t               }d}|t        j                          kD  rh	 t        | |      \  }	}
}|rd}nR|dk7  r|	r|r|j                  d      |k(  rd}n2|	sd}n-t        j                  |       |t        j                          kD  rh|sd}nd	| d
}|||fS # t        j
                  j                  $ r}t        |      }Y d}~jd}~ww xY w)a  Wait for the status to change for a Kinesis Stream.
    Args:
        client (botocore.client.EC2): Boto3 client
        stream_name (str): The name of the kinesis stream.
        status (str): The status to wait for.
            examples. status=available, status=deleted

    Kwargs:
        wait_timeout (int): Number of seconds to wait, until this timeout is reached.
        check_mode (bool): This will pass DryRun as one of the parameters to the aws api.
            default=False

    Basic Usage:
        >>> client = boto3.client('kinesis')
        >>> stream_name = 'test-stream'
        >>> wait_for_status(client, stream_name, 'ACTIVE', 300)

    Returns:
        Tuple (bool, str, dict)
       Fr	   TDELETINGStreamStatusNz0Wait time out reached, while waiting for resultszStatus z achieved successfully)	timer   r0   getr   r   r   r   sleep)r   r   statuswait_timeout
check_modepolling_increment_secsstatus_achievedstreamr   find_successfind_msgr   s               r   wait_for_statusr@     s    * 99;-LOVFG

$	#-8-M*L(F"&#Fzz.1V;*. $&*O
 	

)*+ 
$. DF8#9:GV++ "".. 	#lG	#s$    B7 B7 5B7 7C)C$$C)c                 B   d}d}d|i}	 |sD|dk(  r||d<    | j                   di | d}n:|dk(  r||d<    | j                  di | d}nd	| }n|dk(  rd}n|dk(  rd}nd	| }||fS # t        j                  j                  $ r}t        |      }Y d
}~||fS d
}~ww xY w)a  Create or delete multiple tags from a Kinesis Stream.
    Args:
        client (botocore.client.EC2): Boto3 client.
        resource_id (str): The Amazon resource id.
        tags (list): List of dictionaries.
            examples.. [{Name: "", Values: [""]}]

    Kwargs:
        action (str): The action to perform.
            valid actions == create and delete
            default=create
        check_mode (bool): This will pass DryRun as one of the parameters to the aws api.
            default=False

    Basic Usage:
        >>> client = boto3.client('ec2')
        >>> resource_id = 'pcx-123345678'
        >>> tags = {'env': 'development'}
        >>> update_tags(client, resource_id, tags)
        [True, '']

    Returns:
        List (bool, str)
    Fr	   r
   creater   TdeleteTagKeysInvalid action Nr   )add_tags_to_streamremove_tags_from_streamr   r   r   r   )	r   r   tagsactionr:   r   r   r   r   s	            r   tags_actionrJ   E  s    2 GGK(F!!%v)))3F38#$(y!...88+F84!8#+F84
 G ** A,Gs   AA) )BBBc                     d}d}d}t        | |      \  }}}	t        |	|d      \  }
}|rt        | ||d|      \  }}|s|||fS |
rt        | ||
d|      \  }}|rd}|||fS |||fS )a0  Update tags for an amazon resource.
    Args:
        resource_id (str): The Amazon resource id.
        tags (dict): Dictionary of tags you want applied to the Kinesis stream.

    Kwargs:
        check_mode (bool): This will pass DryRun as one of the parameters to the aws api.
            default=False

    Basic Usage:
        >>> client = boto3.client('ec2')
        >>> stream_name = 'test-stream'
        >>> tags = {'env': 'development'}
        >>> update_tags(client, stream_name, tags)
        [True, '']

    Return:
        Tuple (bool, str)
    Fr	   T)
purge_tagsrC   rI   r:   rB   )r   r   rJ   )r   r   rH   r:   r   changedr   tag_successtag_msgcurrent_tagstags_to_settags_to_deletedelete_success
delete_msgcreate_success
create_msgs                   r   update_tagsrX   {  s    ( GGG)1&+)F&K,"2#K
 %0KZ&
"
 !7J66%0KX*&
"
 Gw
22GW$$    c                 8   d}d}d|i}	 |s?|dk(  r||d<    | j                   d
i | d}n5|dk(  r | j                  d
i | d}nd| }n|dk(  rd}n|dk(  rd}nd| }||fS # t        j                  j                  $ r}	t        |	      }Y d	}	~	||fS d	}	~	ww xY w)a  Create or Delete an Amazon Kinesis Stream.
    Args:
        client (botocore.client.EC2): Boto3 client.
        stream_name (str): The name of the kinesis stream.

    Kwargs:
        shard_count (int): Number of shards this stream will use.
        action (str): The action to perform.
            valid actions == create and delete
            default=create
        check_mode (bool): This will pass DryRun as one of the parameters to the aws api.
            default=False

    Basic Usage:
        >>> client = boto3.client('kinesis')
        >>> stream_name = 'test-stream'
        >>> shard_count = 20
        >>> stream_action(client, stream_name, shard_count, action='create')

    Returns:
        List (bool, str)
    Fr	   r
   rB   
ShardCountTrC   rE   Nr   )create_streamdelete_streamr   r   r   r   )
r   r   shard_countrI   timeoutr:   r   r   r   r   s
             r   stream_actionr`     s    . GGK(F!'2|$$$$.v.8#$$$.v.+F84!8#+F84
 G ** A,Gs   AA$ $BBBc                 V   d}d}d|i}		 |sN|dk(  r||	d<   ||	d<    | j                   di |	 d}n?|dk(  r||	d<   ||	d<    | j                  di |	 d}nd	| }n|dk(  rd}n|dk(  rd}nd	| }||fS # t        j                  j                  $ r}
t        |
      }Y d
}
~
||fS d
}
~
ww xY w)ap  Create, Encrypt or Delete an Amazon Kinesis Stream.
    Args:
        client (botocore.client.EC2): Boto3 client.
        stream_name (str): The name of the kinesis stream.

    Kwargs:
        shard_count (int): Number of shards this stream will use.
        action (str): The action to perform.
            valid actions == create and delete
            default=create
        encryption_type (str): NONE or KMS
        key_id (str): The GUID or alias for the KMS key
        check_mode (bool): This will pass DryRun as one of the parameters to the aws api.
            default=False

    Basic Usage:
        >>> client = boto3.client('kinesis')
        >>> stream_name = 'test-stream'
        >>> shard_count = 20
        >>> stream_action(client, stream_name, shard_count, action='create', encryption_type='KMS',key_id='alias/aws')

    Returns:
        List (bool, str)
    Fr	   r
   start_encryptionEncryptionTypeKeyIdTstop_encryptionzInvalid encryption action Nr   )start_stream_encryptionstop_stream_encryptionr   r   r   r   )r   r   rI   encryption_typekey_idr_   r:   r   r   r   r   s              r   stream_encryption_actionrj     s    6 GGK(F+++:'("(w...88,,+:'("(w---776vh?++,,6vh?
 G ** A,G   A%A3 3B(B##B(c                 V   d}d}d|i}	 |sN|dk(  r||d<    | j                   di | d}d| }n?|dk(  r||d<    | j                  di | d}d	| }nd
| }n|dk(  rd}n|dk(  rd}nd
| }||fS # t        j                  j                  $ r}t        |      }Y d}~||fS d}~ww xY w)aU  Increase or Decrease the retention of messages in the Kinesis stream.
    Args:
        client (botocore.client.EC2): Boto3 client.
        stream_name (str): The name of the kinesis stream.

    Kwargs:
        retention_period (int): This is how long messages will be kept before
            they are discarded. This can not be less than 24 hours.
        action (str): The action to perform.
            valid actions == create and delete
            default=create
        check_mode (bool): This will pass DryRun as one of the parameters to the aws api.
            default=False

    Basic Usage:
        >>> client = boto3.client('kinesis')
        >>> stream_name = 'test-stream'
        >>> retention_period = 48
        >>> retention_action(client, stream_name, retention_period, action='increase')

    Returns:
        Tuple (bool, str)
    Fr	   r
   increaseRetentionPeriodHoursTz+Retention Period increased successfully to decreasez+Retention Period decreased successfully to rE   Nr   ) increase_stream_retention_period decrease_stream_retention_periodr   r   r   r   )	r   r   retention_periodrI   r:   r   r   r   r   s	            r   retention_actionrs     s   0 GGK(F#1A-.777A&AGHXGYZ:%1A-.777A&AGHXGYZ+F84#:%+F84
 G ** A,Grk   c                     d}d}|dd}|s||d<   	  | j                   di | ||fS ||fS # t        j                  j                  $ r}dt	        |      fcY d}~S d}~ww xY w)	a  Increase or Decrease the number of shards in the Kinesis stream.
    Args:
        client (botocore.client.EC2): Boto3 client.
        stream_name (str): The name of the kinesis stream.

    Kwargs:
        number_of_shards (int): Number of shards this stream will use.
            default=1
        check_mode (bool): This will pass DryRun as one of the parameters to the aws api.
            default=False

    Basic Usage:
        >>> client = boto3.client('kinesis')
        >>> stream_name = 'test-stream'
        >>> number_of_shards = 3
        >>> update_shard_count(client, stream_name, number_of_shards)

    Returns:
        Tuple (bool, str)
    Tr	   UNIFORM_SCALING)r
   ScalingTypeTargetShardCountFNr   )update_shard_countr   r   r   str)r   r   number_of_shardsr:   r   r   r   r   s           r   rx   rx   O  s    * GG'8IJF%5!"	!%F%%// G7G "".. 	!#a&= 	!s   , A 	AA A c	                 D   d}	d}
d}|r|rt        | |d||      \  }}}|s|d|fS |j                  d      dk(  rd}||d   kD  rt        | ||d|	      \  }}n1||d   k  rt        | ||d
|	      \  }}n||d   k(  rd| d|d    }d}	|rd}	d}
}|
r|rt        | |d||      \  }}}|sH|d|fS |
rA|s?t        | |      \  }}}|r-|d   dk7  r%d| d}|	|
|fS d|j                  dd       }|	|
|fS |d   |k7  r]t	        | |||      \  }	}|	s|	|
|fS d}
|rt        | |d||      \  }}}|s*||
|fS t        | |      \  }}}|r|d   dk7  rd| d}|	|
|fS |rt        | |||      \  }}}|
|z  }
|rt        | |d||      \  }	}}|	r	|
rd| d}n
|	r|
sd| d}|	|
|fS )au  Update an Amazon Kinesis Stream.
    Args:
        client (botocore.client.EC2): Boto3 client.
        stream_name (str): The name of the kinesis stream.

    Kwargs:
        number_of_shards (int): Number of shards this stream will use.
            default=1
        retention_period (int): This is how long messages will be kept before
            they are discarded. This can not be less than 24 hours.
        tags (dict): The tags you want applied.
        wait (bool): Wait until Stream is ACTIVE.
            default=False
        wait_timeout (int): How long to wait until this operation is considered failed.
            default=300
        check_mode (bool): This will pass DryRun as one of the parameters to the aws api.
            default=False

    Basic Usage:
        >>> client = boto3.client('kinesis')
        >>> current_stream = {
            'ShardCount': 3,
            'HasMoreShards': True,
            'RetentionPeriodHours': 24,
            'StreamName': 'test-stream',
            'StreamARN': 'arn:aws:kinesis:us-west-2:123456789:stream/test-stream',
            'StreamStatus': "ACTIVE'
        }
        >>> stream_name = 'test-stream'
        >>> retention_period = 48
        >>> number_of_shards = 10
        >>> update(client, current_stream, stream_name,
                   number_of_shards, retention_period )

    Returns:
        Tuple (bool, bool, str)
    TFr	   ACTIVEr:   r4   rn   rm   rM   ro   z
Retention z is the same as zRetention Period for z is in the process of updatingYStreamStatus has to be ACTIVE in order to modify the retention period. Current status is UNKNOWNr$   zNumber of shards for Kinesis Stream z updated successfully.z did not change.)r@   r6   rs   r0   rx   rX   )r   current_streamr   rz   rr   rH   waitr9   r:   r   rN   r   wait_successwait_msgretention_changedretention_msgstream_found
stream_msgrO   tag_changedstatus_streams                        r   updater   q  s   ` GGG5DX|
62L(N  #UH44n-9 %.1G"HH3CK)9*Yc40!= "N3I$JJ3CK)9*Yc40!= "^4J%KK",-=,>>N~^tOuNv w #G49HK<J:6h $'88;Fv{;[8j.%n5A$9+Fd"e&88&&4&8&8&S%TV  GW,,'(,<<-fkCS`jkGW,,5DX|
62L(N  #Wh667B6;7W4L*n~ >( J1+>\]00,7T^h,i)[';*9K<J+
'- 7#K=0FG	#K=0@AGW$$rY   c                 "   d}d}	d}
t               }t        | |      \  }}}|r*|j                  d      dk(  r|rt        | |d||      \  }}}|r-|j                  d      dk7  rt	        | ||||||||	      \  }}	}
nt        | ||d|      \  }}|sd	}	d
| }
dd	|
i fS d	}	|r"t        | |d||      \  }}}d| d}
|s|d	||fS d| d}
|rt        | ||d|      \  }	}
|	rd	}|s||	|
|fS t        | |      \  }}}|r3|j                  d      dk(  rt        | ||d|      \  }	}
|	rd	}|s||	|
|fS d|j                  dd       }
|}d	}	|r@t        | |      \  }}}t        | |      \  }}}|r|}|s
t               }t        |      }||d<   ||	|
|fS )a  Create an Amazon Kinesis Stream.
    Args:
        client (botocore.client.EC2): Boto3 client.
        stream_name (str): The name of the kinesis stream.

    Kwargs:
        number_of_shards (int): Number of shards this stream will use.
            default=1
        retention_period (int): Can not be less than 24 hours
            default=None
        tags (dict): The tags you want applied.
            default=None
        wait (bool): Wait until Stream is ACTIVE.
            default=False
        wait_timeout (int): How long to wait until this operation is considered failed.
            default=300
        check_mode (bool): This will pass DryRun as one of the parameters to the aws api.
            default=False

    Basic Usage:
        >>> client = boto3.client('kinesis')
        >>> stream_name = 'test-stream'
        >>> number_of_shards = 10
        >>> tags = {'env': 'test'}
        >>> create_stream(client, stream_name, number_of_shards, tags=tags)

    Returns:
        Tuple (bool, bool, str, dict)
    Fr	   r4   r3   r|   r}   rB   rM   Tz!Failed to create Kinesis stream: r   z# is in the process of being createdz created successfullyrm   r~   r   rH   )
r   r0   r6   r@   r   r`   rJ   rs   r   r   )r   r   rz   rr   rH   r   r9   r:   r   rN   r   r   r   r   r   r   r   rV   rW   rO   rP   rQ   s                         r   r\   r\     s^   N GGGfG/:6;/O,L*n**>:jHT1@K<J2
.h **>:jH$*!
%
!' &3K!1(z&
"
 G9*FG$++G2AK<J3/h ,K=8[\#'x@@+K=8MN#.v{DQYfp#q "G"GWg==7B6;7W4L*nN$6$6~$F($R#3K)9*Yc$  "G"GWg==**8*<*<^Y*W)XZ  ),7,L)j'-5fk-J*WlL6L*73&GWg--rY   c                     d}d}d}t               }t        | |      \  }	}
}|	rAt        | |d|      \  }}|r7d}|r"t        | |d||      \  }}}d| d	}|s|d||fS d| d
}n
d}d}d| d}||||fS )a  Delete an Amazon Kinesis Stream.
    Args:
        client (botocore.client.EC2): Boto3 client.
        stream_name (str): The name of the kinesis stream.

    Kwargs:
        wait (bool): Wait until Stream is ACTIVE.
            default=False
        wait_timeout (int): How long to wait until this operation is considered failed.
            default=300
        check_mode (bool): This will pass DryRun as one of the parameters to the aws api.
            default=False

    Basic Usage:
        >>> client = boto3.client('kinesis')
        >>> stream_name = 'test-stream'
        >>> delete_stream(client, stream_name)

    Returns:
        Tuple (bool, bool, str, dict)
    Fr	   rC   rM   Tr3   r}   Stream z deleted successfullyz# is in the process of being deleted does not exist)r   r0   r`   r@   )r   r   r   r9   r:   r   rN   r   r   r   r   r   s               r   r]   r]   q  s    , GGGfG/:6;/O,L*n(XZdeG,;K\j-)' $K=0EF"D'7::#K=0STK=8GWg--rY   c                    d}d}d}	t               }
t        | |      \  }}}|rv|j                  d      |k(  r|j                  d      |k(  rd}d}d| d}	nMt        | |d|||	      \  }}	|r7d}|r"t	        | |d
||      \  }}	}
d| d}	|s|d|	|
fS d| d}	n
d}d}d| d}	|r<t        | |      \  }}}
t        | |      \  }}}|s
t               }t        |
      }
||
d<   |||	|
fS )ao  Start encryption on an Amazon Kinesis Stream.
    Args:
        client (botocore.client.EC2): Boto3 client.
        stream_name (str): The name of the kinesis stream.

    Kwargs:
        encryption_type (str): KMS or NONE
        key_id (str): KMS key GUID or alias
        wait (bool): Wait until Stream is ACTIVE.
            default=False
        wait_timeout (int): How long to wait until this operation is considered failed.
            default=300
        check_mode (bool): This will pass DryRun as one of the parameters to the aws api.
            default=False

    Basic Usage:
        >>> client = boto3.client('kinesis')
        >>> stream_name = 'test-stream'
        >>> key_id = 'alias/aws'
        >>> encryption_type = 'KMS'
        >>> start_stream_encryption(client, stream_name,encryption_type,key_id)

    Returns:
        Tuple (bool, bool, str, dict)
    Fr	   rc   rd   Tr   z encryption already configured.rb   )rI   rh   ri   r:   r|   r}   z! encryption started successfully.z* is in the process of starting encryption.r   rH   r   r0   r6   rj   r@   r   r   r   r   rh   ri   r   r9   r:   r   rN   r   r   r   r   r   rO   rP   rQ   s                    r   rf   rf     s[   8 GGGfG/:6;/O,L*n./?B~GYGYZaGbflGlGG'}4STG7) /% GW 0?X|PZ1-GWg !0}<]^G"&gw>> /}<fgG#K=@,7,L)j'-5fk-J*Wl6L*73&GWg--rY   c                    d}d}d}	t               }
t        | |      \  }}}|rs|j                  d      dk(  rBt        | |d|||      \  }}	|}|r#t	        | |d||      \  }}	}
|s|d	|	|
fS d
| d}	n.d| d}	n'|j                  d      dk(  rd	}d
| d}	n
d	}d}d| d}	|r<t        | |      \  }}}
t        | |      \  }}}|s
t               }t        |
      }
||
d<   |||	|
fS )a)  Stop encryption on an Amazon Kinesis Stream.
    Args:
        client (botocore.client.EC2): Boto3 client.
        stream_name (str): The name of the kinesis stream.

    Kwargs:
        encryption_type (str): KMS or NONE
        key_id (str): KMS key GUID or alias
        wait (bool): Wait until Stream is ACTIVE.
            default=False
        wait_timeout (int): How long to wait until this operation is considered failed.
            default=300
        check_mode (bool): This will pass DryRun as one of the parameters to the aws api.
            default=False

    Basic Usage:
        >>> client = boto3.client('kinesis')
        >>> stream_name = 'test-stream'
        >>> stop_stream_encryption(client, stream_name,encryption_type, key_id)

    Returns:
        Tuple (bool, bool, str, dict)
    Fr	   rc   KMSre   )rI   ri   rh   r:   r|   r}   Tr   z! encryption stopped successfully.r   z* is in the process of stopping encryption.NONEz encryption already stopped.z does not exist.rH   r   r   s                    r   rg   rg     sS   4 GGGfG/:6;/O,L*n./587( /% GW G,;K<J-)' "D'7::+K=8YZ#K=0Z[ 01V;G'}4PQGK=(89,7,L)j'-5fk-J*Wl6L*73&GWg--rY   c                     t        t        d      t        d dd      t        d dd      t        d dddg      t        ddd	      t        d
dd      t        dddg      t        dddg      t        dd      t        dddg      
      } t        | d      }|j                  j                  d      }|j                  j                  d      }|j                  j                  d      }|j                  j                  d      }|j                  j                  d      }|j                  j                  d      }|j                  j                  d      }|j                  j                  d      }	|j                  j                  d      }
|j                  j                  d       }|dk(  r|s|j	                  d!"       |r|d#k  r|j	                  d$"       |j
                  }	 |j                  d%      }|dk(  rOt        |||||||      \  }}}}|dk(  rt        |||	|
|||      \  }}}}n5|dk(  r0t        |||	|
|||      \  }}}}n|dk(  rt        ||||      \  }}}}r |j                   d)|d' y |j	                  |(       y # t        j                  j                  t        j                  j                  f$ r}|j                  |d&"       Y d }~d }~ww xY w)*NT)requiredFint)defaultr   typer   resource_tags)r   r   r   aliasesbool,  presentabsent)r   choicesr   r   )r   r   ry   )r   r   enableddisabled)
namer-   rr   rH   r   r9   staterh   ri   encryption_state)argument_specsupports_check_moderr   r   r-   r   rH   r   r9   rh   ri   r   z)Shards is required when state == present.)msg   z/Retention period can not be less than 24 hours.kinesiszFailed to connect to AWS)r   rN   r   )r   rN   r   resultr   )r   AnsibleAWSModuler   r6   	fail_jsonr:   r   r   r   r   BotoCoreErrorfail_json_awsr\   rf   rg   r]   	exit_json)r   modulerr   r   r-   r   rH   r   r9   rh   ri   r   r:   r   r   r   rN   r   r   s                      r   mainr   5  s   4 D5u=dUG$VoEVW$V<#EB9y(.CDefe_EU/uy*6MNM # F
 }}(();<--##F+K]]x(FMMg&E==V$D==V$D==$$^4Lmm''(9:O]]x(F}}(();<	&HIb !RS""J@y) 	-:K)94|U_.
*'7 y(1H_fdLR\2.GWgw +1G_fdLR\2.GWgw 
(	-:6;PTVbdn-o*'7R'wR'R'wwW+ ++X-@-@-N-NO @Q$>??@s   *J 7K+K&&K+__main__)r   F)rB   F)F)   rB   r   F)rb   r	   r	   r   F)r   rm   F)r   F)r   NNFr   F)Fr   F)r	   r	   Fr   F)r	   r	   Tr   F) DOCUMENTATIONEXAMPLESRETURNr5   r   ImportErroransible.module_utils._textr   0ansible.module_utils.common.dict_transformationsr   ;ansible_collections.amazon.aws.plugins.module_utils.taggingr   r   >ansible_collections.community.aws.plugins.module_utils.modulesr   r   r   r0   r@   rJ   rX   r`   rj   rs   rx   r   r\   r]   rf   rg   r   __name__r   rY   r   <module>r      s  GREN
> 	 1 U f X xE:%%P7,t3l-%`0h lq7t4nL 		C%R 		w.t-.b bgI.Z afE.P<X~ zF u  		s   B BB