HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.109.1.lve.el8.x86_64 #1 SMP Thu Mar 5 20:23:46 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.30
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/__pycache__/boto_iam.cpython-310.pyc
o

�N�gu.�@s�dZddlZddlZddlZddlZddlZddlm	m
Z
ddlZz&ddlZddl
Z
ddlZddlZe�d��ej�e�d��ej�dZWneyTdZYnwe�e�Zdd�Zd	d
�Zd�dd�Zd�d
d�Zd�dd�Zd�dd�Zd�dd�Zd�dd�Z						d�dd�Zd�dd�Z 	d�dd�Z!d�dd�Z"d�dd �Z#	d�d!d"�Z$d�d#d$�Z%d�d%d&�Z&	d�d'd(�Z'	d�d)d*�Z(	d�d+d,�Z)				d�d-d.�Z*	d�d/d0�Z+	d�d1d2�Z,d�d4d5�Z-	d�d6d7�Z.	d�d8d9�Z/d�d:d;�Z0d�d<d=�Z1	d�d>d?�Z2d�d@dA�Z3d�dBdC�Z4	d�dDdE�Z5d�dFdG�Z6													d�dHdI�Z7d�dJdK�Z8						d�dLdM�Z9d�dNdO�Z:dPdQ�Z;	d�dRdS�Z<	d�dTdU�Z=d�dVdW�Z>	d�dXdY�Z?	d�dZd[�Z@	d�d\d]�ZA	d�d^d_�ZBd�d`da�ZCd�dbdc�ZDd�ddde�ZEd�dfdg�ZF						d�dhdi�ZG	d�djdk�ZH	d�dldm�ZI	d�dndo�ZJ						d�dpdq�ZKd�drds�ZLd�dtdu�ZMd�dvdw�ZNd�dxdy�ZOd�dzd{�ZPd�d|d}�ZQd�d~d�ZR						d�d�d��ZSd�d�d��ZTd�d�d��ZU	d�d�d��ZV	d�d�d��ZW					d�d�d��ZX	d�d�d��ZYd�d�d��ZZ	d�d�d��Z[	d�d�d��Z\	d�d�d��Z]	d�d�d��Z^	d�d�d��Z_	d�d�d��Z`	d�d�d��Za						d�d�d��Zb						d�d�d��Zc						d�d�d��Zd						d�d�d��Ze	d�d�d��Zfd�d�d��Zgd�d�d��Zhd�d�d��Zid�d�d��Zj	d�d�d��ZkdS)�aF
Connection module for Amazon IAM

.. versionadded:: 2014.7.0

:configuration: This module accepts explicit iam credentials but can also utilize
    IAM roles assigned to the instance through Instance Profiles. Dynamic
    credentials are then automatically obtained from AWS API and no further
    configuration is necessary. More Information available at:

    .. code-block:: text

        http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html

    If IAM roles are not used you need to specify them either in a pillar or
    in the minion's config file:

    .. code-block:: yaml

        iam.keyid: GKTADJGHEIQSXMKKRBJ08H
        iam.key: askdjghsdfjkghWupUjasdflkdfklgjsdfjajkghs
        iam.region: us-east-1

    It's also possible to specify key, keyid and region via a profile, either
    as a passed in dict, or as a string to pull from pillars or minion config:

    .. code-block:: yaml

        myprofile:
            keyid: GKTADJGHEIQSXMKKRBJ08H
            key: askdjghsdfjkghWupUjasdflkdfklgjsdfjajkghs
            region: us-east-1

:depends: boto
�N�boto�boto3TFcCstjjjdd�S)z,
    Only load if boto libraries exist.
    F)Zcheck_boto3)�salt�utils�versionsZcheck_boto_reqs�rr�I/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/boto_iam.py�__virtual__Csr	cCstr
tdtdtd�dSdS)Nzboto.assign_funcs�iam)�pack)�HAS_BOTO�	__utils__�__name__Z__salt__)�optsrrr�__init__Js�rcC�:t||||d�}z|�|�WdStjjyYdSw)z�
    Check to see if an instance profile exists.

    CLI Example:

    .. code-block:: bash

        salt myminion boto_iam.instance_profile_exists myiprofile
    ��region�key�keyid�profileTF)�	_get_connZget_instance_profiler�	exception�BotoServerError��namerrrr�connrrr�instance_profile_existsOs

�rc
Cs�t||||d�}t|||||�rdSz|�|�t�d|�WdStjjy@}zt�|�t�	d|�WYd}~dSd}~ww)z�
    Create an instance profile.

    CLI Example:

    .. code-block:: bash

        salt myminion boto_iam.create_instance_profile myiprofile
    rTzCreated %s instance profile.z%Failed to create %s instance profile.NF)
rr�create_instance_profile�log�inforrr�debug�error�rrrrrr�errrrds

�
��rc
C�t||||d�}t|||||�sdSz|�|�t�d|�WdStjjy@}zt�|�t�	d|�WYd}~dSd}~ww)z�
    Delete an instance profile.

    CLI Example:

    .. code-block:: bash

        salt myminion boto_iam.delete_instance_profile myiprofile
    rTzDeleted %s instance profile.z%Failed to delete %s instance profile.NF)
rr�delete_instance_profilerr rrrr!r"r#rrrr&~s

�
��r&cCr)z�
    Check to see if an IAM role exists.

    CLI Example:

    .. code-block:: bash

        salt myminion boto_iam.role_exists myirole
    rTF)r�get_rolerrrrrrr�role_exists�s

�r(c
Cs�t||||d�}z?|�|�}|sWdS|jjj}tjj�t	j
�|j��|d<|d�
�D]\}}	|dkrD|	D]
}
d|
vrC|
dsC|
d=q6q,|WStjjyg}zt�|�t�d|�WYd}~dSd}~ww)z�
    Get information for a role.

    CLI Example:

    .. code-block:: bash

        salt myminion boto_iam.describe_role myirole
    rF�assume_role_policy_documentZ	StatementZSidzFailed to get %s information.N)rr'Zget_role_responseZget_role_result�rolerr�json�loads�urllib�parse�unquoter)�itemsrrrrr!r")rrrrrrr r*Z
policy_key�policy�valr$rrr�
describe_role�s,


��
��r3c
Cs�|sd}t|||||�rdSt||||d�}z|�||�t�d|�WdStjjyE}zt�|�t�	d|�WYd}~dSd}~ww)z�
    Create a user.

    .. versionadded:: 2015.8.0

    CLI Example:

    .. code-block:: bash

        salt myminion boto_iam.create_user myuser
    �/TrzCreated IAM user : %s.zFailed to create IAM user %s.NF)
�get_userr�create_userrr rrrr!r")�	user_name�pathrrrrrr$rrrr6�s
��r6c	
Csht||||d�}z|�|||�WStjjy3}zt�|�t�d|�t|�WYd}~Sd}~ww)z�
    Get all access keys from a user.

    .. versionadded:: 2015.8.0

    CLI Example:

    .. code-block:: bash

        salt myminion boto_iam.get_all_access_keys myuser
    rz*Failed to get access keys for IAM user %s.N)	r�get_all_access_keysrrrrr!r"�str)	r7�marker�	max_itemsrrrrrr$rrrr9�s
��r9c
Csbt||||d�}z|�|�WStjjy0}zt�|�t�d�t|�WYd}~Sd}~ww)z�
    Create access key id for a user.

    .. versionadded:: 2015.8.0

    CLI Example:

    .. code-block:: bash

        salt myminion boto_iam.create_access_key myuser
    rzFailed to create access key.N)	r�create_access_keyrrrrr!r"r:�r7rrrrrr$rrrr=s

��r=c
Csft||||d�}z|�||�WStjjy2}zt�|�t�d|�t|�WYd}~Sd}~ww)z�
    Delete access key id from a user.

    .. versionadded:: 2015.8.0

    CLI Example:

    .. code-block:: bash

        salt myminion boto_iam.delete_access_key myuser
    rz"Failed to delete access key id %s.N)	r�delete_access_keyrrrrr!r"r:)Z
access_key_idr7rrrrrr$rrrr?s
��r?c
Cs�t|||||�s
dSt||||d�}z|�|�t�d|�WdStjjyC}zt�|�t�	d|�t
|�WYd}~Sd}~ww)z�
    Delete a user.

    .. versionadded:: 2015.8.0

    CLI Example:

    .. code-block:: bash

        salt myminion boto_iam.delete_user myuser
    TrzDeleted IAM user : %s .zFailed to delete IAM user %sN)r5r�delete_userrr rrrr!r"r:r>rrrr@.s

��r@c
C�lt||||d�}z
|�|�}|sWdS|WStjjy5}zt�|�t�d|�WYd}~dSd}~ww)z�
    Get user information.

    .. versionadded:: 2015.8.0

    CLI Example:

    .. code-block:: bash

        salt myminion boto_iam.get_user myuser
    rFzFailed to get IAM user %s info.N)rr5rrrrr!r")r7rrrrrr r$rrrr5G�

��r5c
Cs�|sd}t|||||d�rdSt||||d�}z|�||�t�d|�WdStjjyF}zt�|�t�	d|�WYd}~dSd}~ww)z�
    Create a group.

    .. versionadded:: 2015.8.0

    CLI Example:

    .. code-block:: bash

        salt myminion boto_iam.create_group group
    r4rTzCreated IAM group : %s.zFailed to create IAM group %s.NF)
�	get_groupr�create_grouprr rrrr!r")�
group_namer8rrrrrr$rrrrD_s
��rDc
Cs|t||||d�}z|j|dd�}|sWdS|dddWStjjy=}zt�|�t�d|�WYd	}~dSd	}~ww)
z�
    Get group information.

    .. versionadded:: 2015.8.0

    CLI Example:

    .. code-block:: bash

        salt myminion boto_iam.get_group mygroup
    r��r<F�get_group_response�get_group_result�group� Failed to get IAM group %s info.N)rrCrrrrr!r")rErrrrrr r$rrrrC|s
��rCc
Cs�t||||d�}zEd}d}g}|rK|j||dd�}	|	sWdSt|	ddd	�}|r;d
|	ddvr;|	ddd
}nd}d}||	ddd7}|s|WStjjym}
zt�|
�t�d|�WYd}
~
dSd}
~
ww)
z�
    Get group information.

    .. versionadded:: 2016.3.0

    CLI Example:

    .. code-block:: bash

        salt myminion boto_iam.get_group mygroup
    rNTi�)r;r<FrHrIZis_truncatedr;�usersz'Failed to get members for IAM group %s.)	rrC�boolrrrrr!r")rErrrrrr;Z	truncatedrLr r$rrr�get_group_members�s2��

��rNc

Cs�t|||||�}|st�d|�dSt||||||d�rdSt||||d�}z|�||�}|s2WdS|WStjjyU}	zt�	|	�t�d||�WYd}	~	dSd}	~	ww)z�
    Add user to group.

    .. versionadded:: 2015.8.0

    CLI Example:

    .. code-block:: bash

        salt myminion boto_iam.add_user_to_group myuser mygroup
    zUsername : %s does not exist.FrTz&Failed to add IAM user %s to group %s.N)
r5rr"�user_exists_in_groupr�add_user_to_grouprrrr!)
r7rErrrr�userrr r$rrrrP��(�
��rPcCsDt|||||d�}|r |D]}||dkrt�d||�dSq
dS)z�
    Check if user exists in group.

    .. versionadded:: 2015.8.0

    CLI Example:

    .. code-block:: bash

        salt myminion boto_iam.user_exists_in_group myuser mygroup
    )rErrrrr7z'IAM user %s is already in IAM group %s.TF)rNrr!)r7rErrrrrL�_userrrrrO�s
���rOc

Cs�t|||||�}|st�d|�dSt||||||d�sdSt||||d�}z|�||�}|s2WdS|WStjjyU}	zt�	|	�t�d||�WYd}	~	dSd}	~	ww)z�
    Remove user from group.

    .. versionadded:: 2015.8.0

    CLI Example:

    .. code-block:: bash

        salt myminion boto_iam.remove_user_from_group mygroup myuser
    zIAM user %s does not exist.FrTz*Failed to remove IAM user %s from group %sN)
r5rr"rOr�remove_user_from_grouprrrr!)
rEr7rrrrrQrr r$rrrrT�rRrTc
Cs�t|||||d�}|st�d|�dSt||||d�}z't|t�s(tjj�	|�}|�
|||�}	|	r:t�d|�WdSt�d|�WdStj
jyb}
zt�|
�t�d|�WYd}
~
dSd}
~
ww)	z�
    Adds or updates the specified policy document for the specified group.

    .. versionadded:: 2015.8.0

    CLI Example:

    .. code-block:: bash

        salt myminion boto_iam.put_group_policy mygroup policyname policyrules
    rzGroup %s does not existFz Created policy for IAM group %s.Tz(Could not create policy for IAM group %sz(Failed to create policy for IAM group %sN)rCrr"r�
isinstancer:rrr+�dumps�put_group_policyr rrrr!)rE�policy_name�policy_jsonrrrrrJr�createdr$rrrrWs(
�
��rWc	
C�t||||d�}|sdSt||||||�}|sdSz|�||�t�d||�WdStjjyJ}zt�|�t�	d||�WYd}~dSd}~ww)z�
    Delete a group policy.

    CLI Example:

    .. code-block:: bash

        salt myminion boto_iam.delete_group_policy mygroup mypolicy
    rFTz0Successfully deleted policy %s for IAM group %s.z,Failed to delete policy %s for IAM group %s.N)
r�get_group_policy�delete_group_policyrr rrrr!r")	rErXrrrrr�_policyr$rrrr]@s(�
���r]c	
Cs�t||||d�}z)|�||�}t�d|�|sWdS|jjj}tj�	|�}t
jjj
|tjd�}|WStjjyQ}zt�|�t�d|�WYd}~dSd}~ww)z�
    Retrieves the specified policy document for the specified group.

    .. versionadded:: 2015.8.0

    CLI Example:

    .. code-block:: bash

        salt myminion boto_iam.get_group_policy mygroup policyname
    rzinfo for group policy is : %sF��object_pairs_hookrKN)rr\rr!Zget_group_policy_responseZget_group_policy_result�policy_documentr-r.r/rrr+r,�odict�OrderedDictrrrr")	rErXrrrrrr r$rrrr\`s 

��r\r4c	C�vt||||d�}|sdS|j|d�}|jjj}t|jjdd�}|r9|j||d�}||jjj}t|jjdd�}|s!|S)z�
    Get and return all IAM group details, starting at the optional path.

    .. versionadded:: 2016.3.0

    CLI Example:

    .. code-block:: bash

        salt-call boto_iam.get_all_groups
    rN��path_prefixr;�rfr;)r�get_all_groupsZlist_groups_responseZlist_groups_result�groups�getattr)	rfrrrrrZ_groupsrir;rrrrh~s

��rhc
Csdt||||d�}d}g}|dur0|r|nd}|j||d�}|jj}	||	j7}t|	dd�}|dus|S)z�
    Get and return all IAM instance profiles, starting at the optional path.

    .. versionadded:: 2016.11.0

    CLI Example:

    .. code-block:: bash

        salt-call boto_iam.get_all_instance_profiles
    rFNrgr;)r�list_instance_profilesZlist_instance_profiles_responseZlist_instance_profiles_result�instance_profilesrj)
rfrrrrrr;�profiles�p�resrrr�get_all_instance_profiles�s
�rpcCst|||||�}dd�|D�S)z�
    List all IAM instance profiles, starting at the optional path.

    .. versionadded:: 2016.11.0

    CLI Example:

    .. code-block:: bash

        salt-call boto_iam.list_instance_profiles
    cSsg|]}|d�qS)�instance_profile_namer)�.0�irrr�
<listcomp>�sz*list_instance_profiles.<locals>.<listcomp>)rp)rfrrrrrnrrrrk�srkc	
Csjt||||d�}|sdSz
|�|�}|jj}|jWStjjy4}z
t�	|�gWYd}~Sd}~ww)z�
    Get a list of policy names from a group.

    CLI Example:

    .. code-block:: bash

        salt myminion boto_iam.get_all_group_policies mygroup
    rFN)
r�get_all_group_policiesZlist_group_policies_responseZlist_group_policies_result�policy_namesrrrrr!)	rErrrrr�response�_listr$rrrru�s


��ruc
Cs�t||||d�}|sdSt|||||�}|sdSz|�|�t�d|�WdStjjyF}zt�|�t�	d|�WYd}~dSd}~ww)z�
    Delete a group policy.

    CLI Example:

    .. code-block:: bash

        salt myminion boto_iam.delete_group mygroup
    rFTz"Successfully deleted IAM group %s.zFailed to delete IAM group %s.N)
rrC�delete_grouprr rrrr!r")rErrrrr�_groupr$rrrry�s 


��ryc

Cs�t|||||�}|st�d|�dSt||||d�}z|�||�}t�d|�|WStjjyZ}	z#t�	|	�d|	vrIt�d|�WYd}	~	dSt�d|�WYd}	~	dSd}	~	ww)	a"
    Creates a login profile for the specified user, give the user the
    ability to access AWS services and the AWS Management Console.

    .. versionadded:: 2015.8.0

    CLI Example:

    .. code-block:: bash

        salt myminion boto_iam.create_login_profile user_name password
    �IAM user %s does not existFrz Created profile for IAM user %s.�Conflictz'Profile already exists for IAM user %s.Nz)Failed to update profile for IAM user %s.)
r5rr"r�create_login_profiler rrrr!)
r7�passwordrrrrrQrr r$rrrr}�s$
��r}c	
Cs�t|||||�}|st�d|�dSt||||d�}z|�|�}t�d|�WdStjjyY}z#t�	|�d|vrHt�d|�WYd}~dSt�d	|�WYd}~dSd}~ww)
z�
    Deletes a login profile for the specified user.

    .. versionadded:: 2016.3.0

    CLI Example:

    .. code-block:: bash

        salt myminion boto_iam.delete_login_profile user_name
    r{Frz&Deleted login profile for IAM user %s.T�	Not Foundz.Login profile already deleted for IAM user %s.Nz/Failed to delete login profile for IAM user %s.)
r5rr"r�delete_login_profiler rrrr!)	r7rrrrrQrr r$rrrr�s$

��r�c

Cs�t|||||�}|st�d|�dSt||||d�}z|�|�}|ddd}|WStjjy\}	z$t�|	�d|	vrKt�	d|�gWYd	}	~	St�d
|�WYd	}	~	dSd	}	~	ww)z�
    Get all MFA devices associated with an IAM user.

    .. versionadded:: 2016.3.0

    CLI Example:

    .. code-block:: bash

        salt myminion boto_iam.get_all_mfa_devices user_name
    r{FrZlist_mfa_devices_responseZlist_mfa_devices_resultZmfa_devicesrzCould not find IAM user %s.Nz.Failed to get all MFA devices for IAM user %s.)
r5rr"r�get_all_mfa_devicesrrrr!r )
r7rrrrrQr�resultZdevicesr$rrrr�4s(

�
��r�c	
Cs�t|||||�}|st�d|�dSt||||d�}z|�||�t�d||�WdStjjy]}z%t�	|�d|vrKt�d||�WYd}~dSt�d	||�WYd}~dSd}~ww)
z�
    Deactivates the specified MFA device and removes it from association with
    the user.

    .. versionadded:: 2016.3.0

    CLI Example:

    .. code-block:: bash

        salt myminion boto_iam.deactivate_mfa_device user_name serial_num
    r{Frz*Deactivated MFA device %s for IAM user %s.Trz.MFA device %s not associated with IAM user %s.Nz3Failed to deactivate MFA device %s for IAM user %s.)
r5rr"r�deactivate_mfa_devicer rrrr!)	r7�serialrrrrrQrr$rrrr�Ts,
����r�c
Cs�tdd��}z|j|d�t�d|�WdStjjyI}z%t�|�dt|�vr8t�d|�WYd}~dSt�	d	|�WYd}~d
Sd}~ww)z�
    Deletes the specified virtual MFA device.

    CLI Example:

    .. code-block:: bash

        salt myminion boto_iam.delete_virtual_mfa_device serial_num
    zboto3.get_connection_funcr
)ZSerialNumberzDeleted virtual MFA device %s.TZNoSuchEntityz Virtual MFA device %s not found.Nz'Failed to delete virtual MFA device %s.F)
r
�delete_virtual_mfa_devicerr �botocore�
exceptionsZClientErrorr!r:r")r�rrrrrr$rrrr�ys

��r�c
Cs~t|	|
||d�}
z|
�|||||||||�	t�d�WdStjjy>}zt�|�d}t�|�WYd}~dSd}~ww)z�
    Update the password policy for the AWS account.

    .. versionadded:: 2015.8.0

    CLI Example:

    .. code-block:: bash

        salt myminion boto_iam.update_account_password_policy True
    rz%The password policy has been updated.Tz$Failed to update the password policyNF)	r�update_account_password_policyrr rrrr!r")Zallow_users_to_change_passwordZhard_expiryZmax_password_ageZminimum_password_lengthZpassword_reuse_preventionZrequire_lowercase_charactersZrequire_numbersZrequire_symbolsZrequire_uppercase_charactersrrrrrr$�msgrrrr��s,�


��r�c
Csht||||d�}z
|��}|jjjWStjjy3}zt�	|�d}t�
|�WYd}~dSd}~ww)z�
    Get account policy for the AWS account.

    .. versionadded:: 2015.8.0

    CLI Example:

    .. code-block:: bash

        salt myminion boto_iam.get_account_policy
    rz%Failed to update the password policy.NF)rZget_account_password_policyZ$get_account_password_policy_responseZ"get_account_password_policy_resultZpassword_policyrrrrr!r")rrrrrr r$r�rrr�get_account_policy�s�

��r�c	
Cs�t||||d�}t|||||�rdS|sd}z|j|||d�t�d|�WdStjjyG}zt�|�t�d|�WYd}~dSd}~ww)z�
    Create an instance role.

    CLI Example:

    .. code-block:: bash

        salt myminion boto_iam.create_role myrole
    rTN)r)r8zCreated IAM role %s.zFailed to create IAM role %s.F)	rr(�create_rolerr rrrr")	rrar8rrrrrr$rrrr��s
��r�c
Cr%)z}
    Delete an IAM role.

    CLI Example:

    .. code-block:: bash

        salt myminion boto_iam.delete_role myirole
    rTzDeleted %s IAM role.zFailed to delete %s IAM role.NF)
rr(�delete_rolerr rrrr!r"r#rrrr��s


��r�c	
Cs�t||||d�}z|�|�}Wntjjy)}zt�|�WYd}~dSd}~ww|j}|j}|j	}|D]
}|j
|kr?dSq5dS)z�
    Check to see if an instance profile is associated with an IAM role.

    CLI Example:

    .. code-block:: bash

        salt myminion boto_iam.profile_associated myirole myiprofile
    rNFT)rZlist_instance_profiles_for_rolerrrrr!Z(list_instance_profiles_for_role_responseZ&list_instance_profiles_for_role_resultrlrq)	�	role_name�profile_namerrrrrrmr$rrr�profile_associateds 

��
�r�c	
Cs�t||||d�}t|||||�st�d|�dSt|||||�s(t�d|�dSt||||||�}|r5dSz|�||�t�d||�WdStj	j
yf}zt�|�t�d||�WYd}~dSd}~ww)	z�
    Associate an instance profile with an IAM role.

    CLI Example:

    .. code-block:: bash

        salt myminion boto_iam.associate_profile_to_role myirole myiprofile
    r�IAM role %s does not exist.F�#Instance profile %s does not exist.Tz)Added %s instance profile to IAM role %s.z0Failed to add %s instance profile to IAM role %sN)rr(rr"rr�Zadd_role_to_instance_profiler rrrr!�	r�r�rrrrrZ
associatedr$rrr�associate_profile_to_role0�8��
���r�c	
Cs�t||||d�}t|||||�st�d|�dSt|||||�s(t�d|�dSt||||||�}|s5dSz|�||�t�d||�WdStj	j
yf}zt�|�t�d||�WYd}~dSd}~ww)	z�
    Disassociate an instance profile from an IAM role.

    CLI Example:

    .. code-block:: bash

        salt myminion boto_iam.disassociate_profile_from_role myirole myiprofile
    rr�Fr�Tz-Removed %s instance profile from IAM role %s.z6Failed to remove %s instance profile from IAM role %s.N)rr(rr"rr�Z!remove_role_from_instance_profiler rrrr!r�rrr�disassociate_profile_from_roleZr�r�c	
Csbt||||d�}z
|�|�}|jj}|jWStjjy0}z
t�	|�gWYd}~Sd}~ww)z�
    Get a list of policy names from a role.

    CLI Example:

    .. code-block:: bash

        salt myminion boto_iam.list_role_policies myirole
    rN)
r�list_role_policies�list_role_policies_response�list_role_policies_resultrvrrrrr!)	r�rrrrrrwrxr$rrrr��s


��r�cCsft||||d�}z|�||�}|jj}tj�|�}tjj	j
|tjd�}|WSt
jjy2iYSw)z�
    Get a role policy.

    CLI Example:

    .. code-block:: bash

        salt myminion boto_iam.get_role_policy myirole mypolicy
    rr_)r�get_role_policy�get_role_policy_responserar-r.r/rrr+r,rbrcrrr)r�rXrrrrrr^rrrr��s�r�c
Cs�t||||d�}t||||||�}d}	|r||krdSd}	t|t�r,tjjj|tj	d�}z!tjj�
|�}|�|||�|	dkrBd}
nd}
t�
|
||�WdStjjyo}zt�|�t�d|	||�WYd	}~d
Sd	}~ww)a
    Create or modify a role policy.

    CLI Example:

    .. code-block:: bash

        salt myminion boto_iam.create_role_policy myirole mypolicy '{"MyPolicy": "Statement": [{"Action": ["sqs:*"], "Effect": "Allow", "Resource": ["arn:aws:sqs:*:*:*"], "Sid": "MyPolicySqs1"}]}'
    r�createT�modifyr_z,Successfully added policy %s to IAM role %s.z0Successfully modified policy %s for IAM role %s.z'Failed to %s policy %s for IAM role %s.NF)rr�rUr:rrr+r,rbrcrVZput_role_policyrr rrrr")r�rXr1rrrrrr^�moder�r$rrr�create_role_policy�s2

���r�c	
Cs�t||||d�}t||||||�}|sdSz|�||�t�d||�WdStjjyF}zt�|�t�	d||�WYd}~dSd}~ww)z�
    Delete a role policy.

    CLI Example:

    .. code-block:: bash

        salt myminion boto_iam.delete_role_policy myirole mypolicy
    rTz/Successfully deleted policy %s for IAM role %s.z+Failed to delete policy %s for IAM role %s.NF)
rr��delete_role_policyrr rrrr!r")	r�rXrrrrrr^r$rrrr��s �
��r�c	
Cs�t||||d�}t|t�rtjjj|tjd�}ztjj�	|�}|�
||�t�d|�WdSt
jjyM}zt�|�t�d|�WYd}~dSd}~ww)z�
    Update an assume role policy for a role.

    .. versionadded:: 2015.8.0

    CLI Example:

    .. code-block:: bash

        salt myminion boto_iam.update_assume_role_policy myrole '{"Statement":"..."}'
    rr_z8Successfully updated assume role policy for IAM role %s.Tz4Failed to update assume role policy for IAM role %s.NF)rrUr:rrr+r,rbrcrV�update_assume_role_policyrr rrrr")	r�rarrrrrZ_policy_documentr$rrrr��s 
�
��r�cCs�t||||d�}t|d�rtjj�|���}nt|d�r&tjj�|���}niS|��D]?\}}|D]8}t	|dt
�rKt|d�dkrK|dd|d<t	|ddt
�rjt|dd�dkrj|ddd|dd<q2q,d	|d
<|S)z�
    Build a default assume role policy.

    .. versionadded:: 2015.8.0

    CLI Example:

    .. code-block:: bash

        salt myminion boto_iam.build_policy
    r�build_policy�
_build_policy�ActionrFrZ	PrincipalZServicez
2008-10-17ZVersion)r�hasattrrrr+r,r�r�r0rU�list�len)rrrrrr1Z
policy_valZ	statementrrrr�s$

���
r�cCs�d}|tvrdt||||d�}z|��}|dddd}|�d�d}Wn:tjjy_tj�d	d
d�}	tj�	d	dd
�}
tj
j|	|
d�}z|dd}Wnty\t
�d�YnwYnw|t|<t|S)z�
    Get a the AWS account id associated with the used credentials.

    CLI Example:

    .. code-block:: bash

        salt myminion boto_iam.get_account_id
    zboto_iam.account_idrZget_user_responseZget_user_resultrQ�arn�:�ZBotoZmetadata_service_timeoutg�?Zmetadata_service_num_attemptsrF)�timeoutZnum_retries�documentZ	accountIdzKFailed to get account id from instance_identity in boto_iam.get_account_id.)�__context__rr5�splitrrrZconfigZgetfloatZgetintrZget_instance_identity�KeyErrorrr")rrrrZ	cache_keyr�retr��
account_idr�Zattempts�identityrrr�get_account_id;s0
�����r�c	Crd)z�
    Get and return all IAM role details, starting at the optional path.

    .. versionadded:: 2016.3.0

    CLI Example:

    .. code-block:: bash

        salt-call boto_iam.get_all_roles
    rNrer;rg)rZ
list_rolesZlist_roles_responseZlist_roles_result�rolesrj)	rfrrrrrZ_rolesr�r;rrr�
get_all_roles`�
�r�c	Crd)z�
    Get and return all IAM user details, starting at the optional path.

    .. versionadded:: 2016.3.0

    CLI Example:

    .. code-block:: bash

        salt-call boto_iam.get_all_users
    rNrer;rg)r�
get_all_usersZlist_users_responseZlist_users_resultrLrj)	rfrrrrrZ_usersrLr;rrrr�yr�r�c
Cszt||||d�}z|�|||�}|sWdS|jj}	|	jWStjjy<}
zt�	|
�t�
d|�WYd}
~
dSd}
~
ww)z�
    Get all user policies.

    .. versionadded:: 2015.8.0

    CLI Example:

    .. code-block:: bash

        salt myminion boto_iam.get_all_user_policies myuser
    rFz#Failed to get policies for user %s.N)r�get_all_user_policies�list_user_policies_response�list_user_policies_resultrvrrrrr!r")r7r;r<rrrrrr rxr$rrrr��s
��r�c	
Cs�t||||d�}z+|�||�}t�d|||�|sWdS|jjj}tj�	|�}t
jjj
|tjd�}|WStjjyT}zt�|�t�d||�WYd}~dSd}~ww)z�
    Retrieves the specified policy document for the specified user.

    .. versionadded:: 2015.8.0

    CLI Example:

    .. code-block:: bash

        salt myminion boto_iam.get_user_policy myuser mypolicyname
    rz#Info for IAM user %s policy %s: %s.Fr_z(Failed to get policy %s for IAM user %s.N)r�get_user_policyrr!�get_user_policy_response�get_user_policy_resultrar-r.r/rrr+r,rbrcrrrr")	r7rXrrrrrr r$rrrr��s 

��r�c
Cs�t|||||�}|st�d|�dSt||||d�}z)t|t�s'tjj�	|�}|�
|||�}	|	r:t�d||�WdSt�d||�WdStj
jyd}
zt�|
�t�d||�WYd}
~
dSd}
~
ww)	z�
    Adds or updates the specified policy document for the specified user.

    .. versionadded:: 2015.8.0

    CLI Example:

    .. code-block:: bash

        salt myminion boto_iam.put_user_policy myuser policyname policyrules
    r{Frz"Created policy %s for IAM user %s.Tz+Could not create policy %s for IAM user %s.z+Failed to create policy %s for IAM user %s.N)r5rr"rrUr:rrr+rV�put_user_policyr rrrr!)r7rXrYrrrrrQrrZr$rrrr��s(
�
��r�c	
Cr[)z�
    Delete a user policy.

    CLI Example:

    .. code-block:: bash

        salt myminion boto_iam.delete_user_policy myuser mypolicy
    rFTz/Successfully deleted policy %s for IAM user %s.z+Failed to delete policy %s for IAM user %s.N)
rr��delete_user_policyrr rrrr!r")	r7rXrrrrrr^r$rrrr��s$�
��r�c	

Cs�t|||||�}	|	rdSt||||d�}
z|
�||||�}t�d|�|WStjjyE}zt�|�t�	d|�WYd}~dSd}~ww)a�
    Upload a certificate to Amazon.

    .. versionadded:: 2015.8.0

    CLI Example:

    .. code-block:: bash

        salt myminion boto_iam.upload_server_cert mycert_name crt priv_key

    :param cert_name: The name for the server certificate. Do not include the path in this value.
    :param cert_body: The contents of the public key certificate in PEM-encoded format.
    :param private_key: The contents of the private key in PEM-encoded format.
    :param cert_chain:  The contents of the certificate chain. This is typically a concatenation of the PEM-encoded public key certificates of the chain.
    :param path: The path for the server certificate.
    :param region: The name of the region to connect to.
    :param key: The key to be used in order to connect
    :param keyid: The keyid to be used in order to connect
    :param profile: The profile that contains a dict of region, key, keyid
    :return: True / False
    TrzCreated certificate %s.z*Failed to failed to create certificate %s.NF)
�get_server_certificater�upload_server_certrr rrrr!r")
�	cert_nameZ	cert_bodyZprivate_keyZ
cert_chainr8rrrr�existsrr r$rrrr�s"
��r�c
CrA)z�
    Returns certificate information from Amazon

    .. versionadded:: 2015.8.0

    CLI Example:

    .. code-block:: bash

        salt myminion boto_iam.get_server_certificate mycert_name
    rFz)Failed to get certificate %s information.N)rr�rrrrr!r")r�rrrrrr r$rrrr�@rBr�c
Cs^t||||d�}z|�|�WStjjy.}zt�|�t�d|�WYd}~dSd}~ww)z�
    Deletes a certificate from Amazon.

    .. versionadded:: 2015.8.0

    CLI Example:

    .. code-block:: bash

        salt myminion boto_iam.delete_server_cert mycert_name
    rz Failed to delete certificate %s.NF)r�delete_server_certrrrrr!r")r�rrrrrr$rrrr�Xs
��r�cCs�t||||d�}|sdSt��}t|||||�}|D]P}|j}	|j|	dd�}
|
jjj}
i}|
D]}|�	|	|�}
t
jj�
tj�|
jjj��}
|
||<q/g}|�d|	i�|�d|i�|�d|ji�d|i|d	|	<qtd
|ddd
�S)a
    Get all IAM user details. Produces results that can be used to create an
    sls file.

    .. versionadded:: 2016.3.0

    CLI Example:

    .. code-block:: bash

        salt-call boto_iam.export_users --out=txt | sed "s/local: //" > iam_users.sls
    rN�drGr�policiesr8zboto_iam.user_presentzmanage user �yaml.safe_dumpF��Zdefault_flow_style�indent)rrbrcr�r7r�r�r�rvr�rrr+r,r-r.r/r�r�ra�appendr8r
)rfrrrrr�resultsrLrQr�	_policiesr�rXr^Zuser_slsrrr�export_usersms2
���
r�c	Cs
t||||d�}|sdSt��}t|||||�}|D]a}|j}	|j|	dd�}
|
jjj}
i}|
D]}|�	|	|�}
t
jj�
tj�|
jjj��}
|
||<q/g}|�d|	i�|�d|i�|�dt
jj�
tj�|j��i�|�d|ji�d	|i|d
|	<qtd|dd
d�S)z�
    Get all IAM role details. Produces results that can be used to create an
    sls file.

    CLI Example:

    .. code-block:: bash

        salt-call boto_iam.export_roles --out=txt | sed "s/local: //" > iam_roles.sls
    rNr�rGrr�rar8zboto_iam_role.presentzmanage role r�Fr�r�)rrbrcr�r�r�r�r�rvr�rrr+r,r-r.r/r�Zget_role_policy_resultrar�r)r8r
)rfrrrrrr�r�r*rr�r�rXr^Zrole_slsrrr�export_roles�s>���

���r�cCs.|�d�r|St||||d�}d|�d|��S)Nzarn:aws:iam:rz
arn:aws:iam::z:policy/)�
startswithr�)rrrrrr�rrr�_get_policy_arn�s
r�c	CsHt||||d�}z|�t|||||d��WdStjjy#YdSw���
    Check to see if policy exists.

    CLI Example:

    .. code-block:: bash

        salt myminion boto_iam.instance_profile_exists myiprofile
    rTF)r�
get_policyr�rrr)rXrrrrrrrr�
policy_exists�s

���r�c	CsXt||||d�}z|�t|||||d��}|�di��di�WStjjy+YdSw)r�rZget_policy_responseZget_policy_resultN)rr�r��getrrr)rXrrrrrr�rrrr��s

���r�c
Cs�t||||d�}t|t�stjj�|�}i}	dD]}
t�|
dur(t�|
|	|
<qt|||||�r3dSz|j	||fi|	��t
�d|�WdStj
jyf}zt
�|�t
�d|�WYd}~dSd}~ww)a
    Create a policy.

    CLI Example:

    .. code-block:: bash

        salt myminios boto_iam.create_policy mypolicy '{"Version": "2012-10-17", "Statement": [{ "Effect": "Allow", "Action": ["s3:Get*", "s3:List*"], "Resource": ["arn:aws:s3:::my-bucket/shared/*"]},]}'
    r)r8�descriptionNTzCreated IAM policy %s.zFailed to create IAM policy %s.F)rrUr:rrr+rV�localsr��
create_policyrr rrrr!r")rXrar8r�rrrrr�params�argr$rrrr��s(
��
��r�c	
Cs�t||||d�}t|||||�}t|||||�sdSz|�|�t�d|�WdStjjyR}zt	d|�}t�
|�t�d||�d��WYd}~dSd}~ww)	z}
    Delete a policy.

    CLI Example:

    .. code-block:: bash

        salt myminion boto_iam.delete_policy mypolicy
    rTzDeleted %s policy.�boto.get_errorzFailed to delete %s policy: %s.�messageNF)
rr�r��
delete_policyrr rrrr
r!r"r�)	rXrrrrr�
policy_arnr$�awsrrrr�!s

�
��r�c	
Cs�t||||d�}zg}td|j�D]}|�|�di��di��d��q|WStjjyI}zt�	|�d}t�
|�gWYd}~Sd}~ww)zr
    List policies.

    CLI Example:

    .. code-block:: bash

        salt myminion boto_iam.list_policies
    r�boto.paged_callZlist_policies_responseZlist_policies_resultr�zFailed to list policy versions.N)rr
�
list_policiesr�r�rrrrr!r")	rrrrrr�r�r$r�rrrr�;s"

�

��r�cCsLt||||d�}t|||||�}z	|�||�WdStjjy%YdSwr�)rr��get_policy_versionrrr)rX�
version_idrrrrrr�rrr�policy_version_existsWs�r�c		Cs�t||||d�}z+|�t|||||d�|�}|�di��di��di�}tj�|�d��|d<d|iWStjj	y?YdSw)r�rZget_policy_version_responseZget_policy_version_result�policy_versionr�N)
rr�r�r�r-r.r/rrr)	rXr�rrrrrr��retvalrrrr�ms"
��
�
�r�c
Cst||||d�}t|t�stjj�|�}i}dD]}	t�|	dur(t�|	||	<qt|||||�}
z(|j	|
|fi|��}|�
di��
di��
di��
d�}t�d||�d	|d
�WSt
jjy�}
zt�|
�t�d||�dtd
|
�d�WYd}
~
Sd}
~
ww)a#
    Create a policy version.

    CLI Example:

    .. code-block:: bash

        salt myminios boto_iam.create_policy_version mypolicy '{"Version": "2012-10-17", "Statement": [{ "Effect": "Allow", "Action": ["s3:Get*", "s3:List*"], "Resource": ["arn:aws:s3:::my-bucket/shared/*"]},]}'
    r)�set_as_defaultNZcreate_policy_version_responseZcreate_policy_version_resultr�r�z!Created IAM policy %s version %s.T)rZr�z*Failed to create IAM policy %s version %s.Fr�)rZr")rrUr:rrr+rVr�r��create_policy_versionr�rr rrrr!r"r
)rXrar�rrrrrr�r�r�r�Zvidr$rrrr��s0
�
�
��r�c
Cs�t||||d�}t|||||�}t||||||�sdSz|�||�t�d||�WdStjjyV}zt	d|�}	t�
|	�t�d|||	�d��WYd}~dSd}~ww)	z�
    Delete a policy version.

    CLI Example:

    .. code-block:: bash

        salt myminion boto_iam.delete_policy_version mypolicy v1
    rTz!Deleted IAM policy %s version %s.r�z-Failed to delete IAM policy %s version %s: %sr�NF)
rr�r��delete_policy_versionrr rrrr
r!r"r��
rXr�rrrrrr�r$r�rrrr��s(�
���r�c	
Cs�t||||d�}t|||||�}z|�|�}|�di��di��d�WStjjyD}zt�|�t�	d|�gWYd}~Sd}~ww)z�
    List versions of a policy.

    CLI Example:

    .. code-block:: bash

        salt myminion boto_iam.list_policy_versions mypolicy
    rZlist_policy_versions_responseZlist_policy_versions_resultrz*Failed to list versions for IAM policy %s.N)
rr��list_policy_versionsr�rrrrr!r")	rXrrrrrr�r�r$rrrr��s


�
��r�c
Cs�t||||d�}t|||||�}z|�||�t�d||�WdStjjyK}ztd|�}	t�	|	�t�
d|||	�d��WYd}~dSd}~ww)	z�
    Set the default version of  a policy.

    CLI Example:

    .. code-block:: bash

        salt myminion boto_iam.set_default_policy_version mypolicy v1
    rzSet %s policy to version %s.r�z)Failed to set %s policy to version %s: %sr�NFT)rr��set_default_policy_versionrr rrrr
r!r"r�r�rrrr��s$�
���r�c	
C�t||||d�}t|||||�}z|�||�t�d||�WdStjjyA}zt�|�t�	d||�WYd}~dSd}~ww)z�
    Attach a managed policy to a user.

    CLI Example:

    .. code-block:: bash

        salt myminion boto_iam.attach_user_policy mypolicy myuser
    rz"Attached policy %s to IAM user %s.z*Failed to attach %s policy to IAM user %s.NFT)
rr��attach_user_policyrr rrrr!r"�	rXr7rrrrrr�r$rrrr���
��r�c	
Cr�)z�
    Detach a managed policy to a user.

    CLI Example:

    .. code-block:: bash

        salt myminion boto_iam.detach_user_policy mypolicy myuser
    rz$Detached %s policy from IAM user %s.z,Failed to detach %s policy from IAM user %s.NFT)
rr��detach_user_policyrr rrrr!r"r�rrrr�+��
���r�c	
Cr�)z�
    Attach a managed policy to a group.

    CLI Example:

    .. code-block:: bash

        salt myminion boto_iam.attach_group_policy mypolicy mygroup
    rz#Attached policy %s to IAM group %s.z+Failed to attach policy %s to IAM group %s.NFT)
rr��attach_group_policyrr rrrr!r"�	rXrErrrrrr�r$rrrr�Fr�r�c	
Cr�)z�
    Detach a managed policy to a group.

    CLI Example:

    .. code-block:: bash

        salt myminion boto_iam.detach_group_policy mypolicy mygroup
    rz%Detached policy %s from IAM group %s.z-Failed to detach policy %s from IAM group %s.NFT)
rr��detach_group_policyrr rrrr!r"r�rrrr�ar�r�c	
Cr�)z�
    Attach a managed policy to a role.

    CLI Example:

    .. code-block:: bash

        salt myminion boto_iam.attach_role_policy mypolicy myrole
    rz"Attached policy %s to IAM role %s.z*Failed to attach policy %s to IAM role %s.NFT)
rr��attach_role_policyrr rrrr!r"�	rXr�rrrrrr�r$rrrr�|r�r�c	
Cr�)z�
    Detach a managed policy to a role.

    CLI Example:

    .. code-block:: bash

        salt myminion boto_iam.detach_role_policy mypolicy myrole
    rz$Detached policy %s from IAM role %s.z,Failed to detach policy %s from IAM role %s.NFT)
rr��detach_role_policyrr rrrr!r"r�rrrr��r�r�c
Cs*t||||d�}d}i}	dD]}
t�|
durt�|
|	|
<qt|||||�}|r�z2gggd�}td|jfd|i|	��D]}
|��D]\}}|�|
�di��d	i��|��qCq=|WStj	j
y�}z)|jd
kr~t�
d�t�d�|d
8}WYd}~q't�d||j�iWYd}~Sd}~wwiS)z�
    List entities that a policy is attached to.

    CLI Example:

    .. code-block:: bash

        salt myminion boto_iam.list_entities_for_policy mypolicy
    r�)rf�
entity_filterN)Z
policy_groupsZpolicy_usersZpolicy_rolesr�r�Z!list_entities_for_policy_responseZlist_entities_for_policy_resultZ
Throttlingz0Throttled by AWS API, will retry in 5 seconds...�rFz-Failed to list entities for IAM policy %s: %s)rr�r�r
�list_entities_for_policyr0�extendr�rrrZ
error_coderr!�time�sleepr"r�)rXrfr�rrrrrZretriesr�r�r�Zallretr��k�vr$rrrr��sT����
�
��


���
r�c
C�t||||d�}d|i}|dur||d<g}	z"td|jd|dd�D]}
|	�|
�d	i��d
i��dg��q"|	WStjjyY}zt�	|�t�
d|�gWYd}~Sd}~ww)
z�
    List entities attached to the given user.

    CLI Example:

    .. code-block:: bash

        salt myminion boto_iam.list_entities_for_policy mypolicy
    rZUserNameN�
PathPrefixr�ZListAttachedUserPolicies�AttachedPolicies�Zlist_markerZ$list_attached_user_policies_responseZ"list_attached_user_policies_result�attached_policiesz1Failed to list attached policies for IAM user %s.�rr
Zget_responser�r�rrrrr!r")r7rfr�rrrrrr�r�r�r$rrr�list_attached_user_policies��0
�
�
��rc
Cr)
z�
    List entities attached to the given group.

    CLI Example:

    .. code-block:: bash

        salt myminion boto_iam.list_entities_for_policy mypolicy
    rZ	GroupNameNrr�ZListAttachedGroupPoliciesrrZ%list_attached_group_policies_responseZ#list_attached_group_policies_resultrz2Failed to list attached policies for IAM group %s.r)rErfr�rrrrrr�r�r�r$rrr�list_attached_group_policies	r	r
c
Cr)
z�
    List entities attached to the given role.

    CLI Example:

    .. code-block:: bash

        salt myminion boto_iam.list_entities_for_policy mypolicy
    rZRoleNameNrr�ZListAttachedRolePoliciesrrZ$list_attached_role_policies_responseZ"list_attached_role_policies_resultrz1Failed to list attached policies for IAM role %s.r)r�rfr�rrrrrr�r�r�r$rrr�list_attached_role_policiesE	r	rc	
Cs|t||||d�}z|�||�t�d|�WdStjjy=}ztd|�}t�|�t�	d|�WYd}~dSd}~ww)z�
    Create SAML provider

    CLI Example:

    .. code-block:: bash

        salt myminion boto_iam.create_saml_provider my_saml_provider_name saml_metadata_document
    rz&Successfully created %s SAML provider.Tr�z"Failed to create SAML provider %s.NF)
r�create_saml_providerrr rrrr
r!r")	r�saml_metadata_documentrrrrrr$r�rrrrs	s
��rc

Cs�t||||d�}z|��}|jjjD]}|d�d|�r$|dWSqWdStjjyM}zt	d|�}	t
�|	�t
�d|�WYd}~dSd}~ww)z�
    Get SAML provider

    CLI Example:

    .. code-block:: bash

        salt myminion boto_iam.get_saml_provider_arn my_saml_provider_name
    rr�z:saml-provider/Fr�z&Failed to get ARN of SAML provider %s.N)
r�list_saml_providers�list_saml_providers_response�list_saml_providers_result�saml_provider_list�endswithrrrr
rr!r")
rrrrrrrwZ
saml_providerr$r�rrr�get_saml_provider_arn�	s"
��
��rc	
Cs�t||||d�}z"t|||||d�}|st�d|�WdS|�|�t�d|�WdStjjyP}ztd|�}t�	|�t�
d|�WYd}~dSd}~ww)	z�
    Delete SAML provider

    CLI Example:

    .. code-block:: bash

        salt myminion boto_iam.delete_saml_provider my_saml_provider_name
    r�SAML provider %s not found.Tz&Successfully deleted SAML provider %s.r�z"Failed to delete SAML provider %s.NF)rrrr �delete_saml_providerrrrr
r!r")	rrrrrr�saml_provider_arnr$r�rrrr�	s$

�

��rc	
Cs�t||||d�}z!g}|��}|dddD]}|�|d�dd�d�q|WStjjyL}zt�t	d|��t�
d	�WYd
}~dSd
}~ww)z~
    List SAML providers.

    CLI Example:

    .. code-block:: bash

        salt myminion boto_iam.list_saml_providers
    rrrrr�r4rFr�z%Failed to get list of SAML providers.NF)rrr��rsplitrrrrr!r
r")	rrrrrZ	providersr r�r$rrrr�	s

�
��rc
Csvt||||d�}z|�|�}|dddWStjjy:}zt�td|��t�d|�WYd}~dSd}~ww)	z�
    Get SAML provider document.

    CLI Example:

    .. code-block:: bash

        salt myminion boto_iam.get_saml_provider arn
    rZget_saml_provider_responseZget_saml_provider_resultr
r�z(Failed to get SAML provider document %s.NF)	r�get_saml_providerrrrrr!r
r")rrrrrrZproviderr$rrrr�	s


���rc	
Cs�t||||d�}z t|||||d�}|st�d|�WdS|�||�r&WdSWdStjjyL}zt�t	d|��t�
d|�WYd}~dSd}~ww)z�
    Update SAML provider.

    CLI Example:

    .. code-block:: bash

        salt myminion boto_iam.update_saml_provider my_saml_provider_name saml_metadata_document
    rrFTr�z"Failed to update SAML provider %s.N)rrrr �update_saml_providerrrrr!r
r")	rr
rrrrrrr$rrrr�	s"
���r)NNNN)NNNNN)NNNNNN)r4NNNN)
NNNNNNNNNNNNN)l�__doc__�loggingr��urllib.parser-Zsalt.utils.compatrZsalt.utils.jsonZsalt.utils.odictrrbZsalt.utils.versionsrrZboto.iamr��	getLogger�setLevel�CRITICALr�ImportErrorrrr	rrrr&r(r3r6r9r=r?r@r5rDrCrNrPrOrTrWr]r\rhrprkruryr}r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rr
rrrrrrrrrrr�<module>s�(�






"
�

�


�

&
�#
�
�&
�(
�!
�

�
�


�
!
!
�
%
�
0
�
"
�+
�
*
�
�(
�
�

%
%

�"
�
�"
�"
�
0


)
.


�
'

�
�#
�,
�
!
� 
�
�
�
�
�
�
�;
�0
�0
�/
�



�