U
    W+d                      @   sx   d dl Z d dlZd dlZd dlmZ G dd deZG dd deZG dd deZ	G d	d
 d
eZ
G dd deZdS )    N)jsonc                   @   s\   e Zd ZdZdddZedd Zedd Zd	d
 Zdd Z	dd Z
dd ZdddZdS )Credentialsa'  
    :ivar access_key: The AccessKeyID.
    :ivar secret_key: The SecretAccessKey.
    :ivar session_token: The session token that must be passed with
                         requests to use the temporary credentials
    :ivar expiration: The timestamp for when the credentials will expire
    Nc                 C   s(   || _ d | _d | _d | _d | _d | _d S N)parent
access_key
secret_keysession_token
expiration
request_idselfr    r   8/tmp/pip-unpacked-wheel-dlxw5sjy/boto/sts/credentials.py__init__'   s    zCredentials.__init__c                 C   s    t |}|  }|j| |S )z
        Create and return a new Session Token based on the contents
        of a JSON document.

        :type json_doc: str
        :param json_doc: A string containing a JSON document with a
            previously saved Credentials object.
        )r   loads__dict__update)clsjson_docdtokenr   r   r   	from_json/   s    

zCredentials.from_jsonc                 C   s"   t |}| }|  | |S )a-  
        Create and return a new Session Token based on the contents
        of a previously saved JSON-format file.

        :type file_path: str
        :param file_path: The fully qualified path to the JSON-format
            file containing the previously saved Session Token information.
        )openreadcloser   )r   	file_pathfpr   r   r   r   load>   s    
zCredentials.loadc                 C   s   d S r   r   r   nameattrs
connectionr   r   r   startElementM   s    zCredentials.startElementc                 C   sT   |dkr|| _ n@|dkr || _n0|dkr0|| _n |dkr@|| _n|dkrP|| _n d S )NZAccessKeyIdZSecretAccessKeyZSessionTokenZ
Expiration	RequestIdr   r   r   r	   r
   r   r   valuer!   r   r   r   
endElementP   s    zCredentials.endElementc                 C   s   | j | j| j| j| jdS )zm
        Return a Python dict containing the important information
        about this Session Token.
        r$   r$   )r   r   r   r   to_dict^   s    zCredentials.to_dictc                 C   s2   t |d}t|  | |  t|d dS )a  
        Persist a Session Token to a file in JSON format.

        :type path: str
        :param path: The fully qualified path to the file where the
            the Session Token data should be written.  Any previous
            data in the file will be overwritten.  To help protect
            the credentials contained in the file, the permissions
            of the file will be set to readable/writable by owner only.
        wi  N)r   r   dumpr(   r   oschmod)r   r   r   r   r   r   savei   s    
zCredentials.saver   c                 C   s@   t j  }|r|t j|d }tj| j}|| }| dkS )a  
        Checks to see if the Session Token is expired or not.  By default
        it will check to see if the Session Token is expired as of the
        moment the method is called.  However, you can supply an
        optional parameter which is the number of seconds of offset
        into the future for the check.  For example, if you supply
        a value of 5, this method will return a True if the Session
        Token will be expired 5 seconds from this moment.

        :type time_offset_seconds: int
        :param time_offset_seconds: The number of seconds into the future
            to test the Session Token for expiration.
        )secondsr   )datetimeutcnow	timedeltabotoutilsZparse_tsr	   total_seconds)r   Ztime_offset_secondsnowtsdeltar   r   r   
is_expiredy   s    
zCredentials.is_expired)N)r   )__name__
__module____qualname____doc__r   classmethodr   r   r"   r'   r(   r-   r8   r   r   r   r   r      s   


r   c                   @   s*   e Zd ZdZd	ddZdd Zdd ZdS )
FederationTokenah  
    :ivar credentials: A Credentials object containing the credentials.
    :ivar federated_user_arn: ARN specifying federated user using credentials.
    :ivar federated_user_id: The ID of the federated user using credentials.
    :ivar packed_policy_size: A percentage value indicating the size of
                             the policy in packed form
    Nc                 C   s(   || _ d | _d | _d | _d | _d | _d S r   )r   credentialsfederated_user_arnfederated_user_idpacked_policy_sizer
   r   r   r   r   r      s    zFederationToken.__init__c                 C   s   |dkrt  | _| jS d S d S )Nr   )r   r?   r   r   r   r   r"      s    zFederationToken.startElementc                 C   sH   |dkr|| _ n4|dkr || _n$|dkr4t|| _n|dkrD|| _n d S )NArnZFederatedUserIdZPackedPolicySizer#   )r@   rA   intrB   r
   r%   r   r   r   r'      s    zFederationToken.endElement)Nr9   r:   r;   r<   r   r"   r'   r   r   r   r   r>      s   
r>   c                   @   s*   e Zd ZdZd	ddZdd Zdd ZdS )
AssumedRolezt
    :ivar user: The assumed role user.
    :ivar credentials: A Credentials object containing the credentials.
    Nc                 C   s   || _ || _|| _d S r   )_connectionr?   user)r   r!   r?   rH   r   r   r   r      s    zAssumedRole.__init__c                 C   s0   |dkrt  | _| jS |dkr,t | _| jS d S )Nr   ZAssumedRoleUser)r   r?   UserrH   r   r   r   r   r"      s    zAssumedRole.startElementc                 C   s   d S r   r   r%   r   r   r   r'      s    zAssumedRole.endElement)NNNrE   r   r   r   r   rF      s   
rF   c                   @   s*   e Zd ZdZd	ddZdd Zdd ZdS )
rI   zy
    :ivar arn: The arn of the user assuming the role.
    :ivar assume_role_id: The identifier of the assumed role.
    Nc                 C   s   || _ || _d S r   arnassume_role_id)r   rK   rL   r   r   r   r      s    zUser.__init__c                 C   s   d S r   r   r   r   r   r   r"      s    zUser.startElementc                 C   s"   |dkr|| _ n|dkr|| _d S )NrC   ZAssumedRoleIdrJ   r%   r   r   r   r'      s    zUser.endElement)NNrE   r   r   r   r   rI      s   
rI   c                   @   s*   e Zd ZdZd	ddZdd Zdd ZdS )
DecodeAuthorizationMessagezw
    :ivar request_id: The request ID.
    :ivar decoded_message: The decoded authorization message (may be JSON).
    Nc                 C   s   || _ || _d S r   r
   decoded_message)r   r
   rO   r   r   r   r      s    z#DecodeAuthorizationMessage.__init__c                 C   s   d S r   r   r   r   r   r   r"      s    z'DecodeAuthorizationMessage.startElementc                 C   s"   |dkr|| _ n|dkr|| _d S )NZ	requestIdZDecodedMessagerN   r%   r   r   r   r'      s    z%DecodeAuthorizationMessage.endElement)NNrE   r   r   r   r   rM      s   
rM   )r+   r/   Z
boto.utilsr2   Zboto.compatr   objectr   r>   rF   rI   rM   r   r   r   r   <module>   s   q%