o
    eg                     @   s&  d Z ddlmZ ddlZddlZddlZ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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 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 ddlmZ ddl m!Z! e"e#Z$G dd deZ%dS )z(
This module provides a client for STS.
    )	iteritemsN)str)bytes)bce_client_configuration)utils)bce_v1_signer)BceBaseClient)BceClientError)BceServerError)BceHttpClientError)bce_http_client)handler)http_content_types)http_headers)http_methods)sts)requiredc                   @   sL   e Zd ZdZdddZdddZedd Zd	d
 Z					dddZ	dS )	StsClientz
    sdk client
    Nc                 C   s   t | | d S N)r   __init__)selfconfig r   PD:\Projects\ConvertPro\env\Lib\site-packages\baidubce/services/sts/sts_client.pyr   3   s   zStsClient.__init__c                 C   s~   d}|durt |trd|i}|du rd}nt |tstdd|v r)t|}ntj|| jd}| jtj	|t
jtji|dS )a#  
        :type duration_seconds: int
        :param duration_seconds: None
        :token effective period

        :type id: string
        :param id: None
        :acl id

        :type acl: dict
        :param acl: None
        :acl

        :return:
            **HttpResponse**
        Ns   durationSecondss   acl should be dictid)default)bodyheadersparams)
isinstanceintdict	TypeErrorjsondumps_dump_acl_object_send_requestr   POSTr   ZCONTENT_TYPEr   JSON)r   aclZduration_secondsr   r   r   r   r   get_session_token6   s"   


zStsClient.get_session_tokenc                 C   s.   i }t | jD ]\}}|ds|||< q|S )N_)r   __dict__
startswith)r)   resultkvr   r   r   r%   ^   s   
zStsClient._dump_acl_objectc                 C   s(   |d u r| j S t| j }|| |S r   )r   copyZmerge_non_none_values)r   r   Z
new_configr   r   r   _merge_configf   s
   
zStsClient._merge_configc              
   C   sB   |  |}tjd }|d u rtj}t|tjtj	|g|||||S )Ns   sessionToken)
r2   r   Z
URL_PREFIXr   Z
parse_jsonr   send_requestr   signZparse_error)r   Zhttp_methodr   r   r   r   Zbody_parserpathr   r   r   r&   n   s   


zStsClient._send_requestr   )NNNNN)
__name__
__module____qualname____doc__r   r*   staticmethodr%   r2   r&   r   r   r   r   r   /   s    

(

r   )&r9   Zfuture.utilsr   r1   http.clienthttposr#   loggingshutilbuiltinsr   r   Zbaidubcer   r   Zbaidubce.authr   Zbaidubce.bce_base_clientr   Zbaidubce.exceptionr	   r
   r   Zbaidubce.httpr   r   r   r   r   Zbaidubce.servicesr   Zbaidubce.utilsr   	getLoggerr6   Z_loggerr   r   r   r   r   <module>   s6   
