示例#1
0
文件: client.py 项目: aliyun/tea-rpc
 def __init__(
     self,
     config: rpc_models.Config,
 ):
     """
     Init client with Config
     @param config: config contains the necessary information to create a client
     """
     if UtilClient.is_unset(config):
         raise TeaException({
             'code': 'ParameterMissing',
             'message': "'config' can not be unset"
         })
     UtilClient.validate_model(config)
     if not UtilClient.empty(config.access_key_id) and not UtilClient.empty(
             config.access_key_secret):
         if not UtilClient.empty(config.security_token):
             config.type = 'sts'
         else:
             config.type = 'access_key'
         credential_config = credential_models.Config(
             access_key_id=config.access_key_id,
             type=config.type,
             access_key_secret=config.access_key_secret,
             security_token=config.security_token)
         self._credential = CredentialClient(credential_config)
     elif not UtilClient.is_unset(config.credential):
         self._credential = config.credential
     else:
         raise TeaException({
             'code':
             'ParameterMissing',
             'message':
             "'accessKeyId' and 'accessKeySecret' or 'credential' can not be unset"
         })
     self._network = config.network
     self._suffix = config.suffix
     self._endpoint = config.endpoint
     self._protocol = config.protocol
     self._region_id = config.region_id
     self._user_agent = config.user_agent
     self._read_timeout = config.read_timeout
     self._connect_timeout = config.connect_timeout
     self._http_proxy = config.http_proxy
     self._https_proxy = config.https_proxy
     self._no_proxy = config.no_proxy
     self._socks_5proxy = config.socks_5proxy
     self._socks_5net_work = config.socks_5net_work
     self._max_idle_conns = config.max_idle_conns
     self._endpoint_type = config.endpoint_type
     self._open_platform_endpoint = config.open_platform_endpoint
示例#2
0
        async def main():
            prov = providers.EcsRamRoleCredentialProvider("roleName")
            self.assertIsNotNone(prov)
            self.assertEqual("roleName", prov.role_name)

            cfg = models.Config()
            cfg.role_name = "roleNameConfig"
            cfg.timeout = 1100
            cfg.connect_timeout = 1200
            prov = providers.EcsRamRoleCredentialProvider(config=cfg)
            self.assertIsNotNone(prov)
            self.assertEqual("roleNameConfig", prov.role_name)
            self.assertEqual(2300, prov.timeout)
            cred = await prov._create_credential_async(url='127.0.0.1:8888')
            self.assertEqual('ak', cred.access_key_id)

            await prov._get_role_name_async(url='127.0.0.1:8888')
            self.assertIsNotNone(prov.role_name)
示例#3
0
        async def main():
            access_key_id, access_key_secret, region_id = \
                'access_key_id', 'access_key_secret', 'region_id'
            prov = providers.RsaKeyPairCredentialProvider(
                access_key_id, access_key_secret, region_id)
            self.assertEqual('access_key_id', prov.access_key_id)
            self.assertEqual('access_key_secret', prov.access_key_secret)
            self.assertEqual('region_id', prov.region_id)

            conf = models.Config(access_key_id=access_key_id,
                                 access_key_secret=access_key_secret)
            prov = providers.RsaKeyPairCredentialProvider(config=conf)
            self.assertEqual('access_key_id', prov.access_key_id)
            self.assertEqual('access_key_secret', prov.access_key_secret)
            self.assertEqual('cn-hangzhou', prov.region_id)

            cred = await prov._create_credential_async(
                turl='http://127.0.0.1:8888')
            self.assertEqual('SessionAccessKeyId', cred.access_key_id)
 def __init__(
     self,
     config: open_search_models.Config,
 ):
     if UtilClient.is_unset(config):
         raise TeaException({
             'name': 'ParameterMissing',
             'message': "'config' can not be unset"
         })
     if UtilClient.empty(config.type):
         config.type = 'access_key'
     credential_config = credential_models.Config(
         access_key_id=config.access_key_id,
         type=config.type,
         access_key_secret=config.access_key_secret,
         security_token=config.security_token)
     self._credential = CredentialClient(credential_config)
     self._endpoint = config.endpoint
     self._protocol = config.protocol
     self._user_agent = config.user_agent
示例#5
0
    def __init__(self,
                 config,
                 _endpoint=None,
                 _region_id=None,
                 _protocol=None,
                 _user_agent=None,
                 _endpoint_rule=None,
                 _endpoint_map=None,
                 _suffix=None,
                 _read_timeout=None,
                 _connect_timeout=None,
                 _http_proxy=None,
                 _https_proxy=None,
                 _socks_5proxy=None,
                 _socks_5net_work=None,
                 _no_proxy=None,
                 _network=None,
                 _product_id=None,
                 _max_idle_conns=None,
                 _endpoint_type=None,
                 _open_platform_endpoint=None,
                 _credential=None):
        """
        Init client with Config

        :param config: config contains the necessary information to create a client
        """
        self._endpoint = _endpoint
        self._region_id = _region_id
        self._protocol = _protocol
        self._user_agent = _user_agent
        self._endpoint_rule = _endpoint_rule
        self._endpoint_map = _endpoint_map
        self._suffix = _suffix
        self._read_timeout = _read_timeout
        self._connect_timeout = _connect_timeout
        self._http_proxy = _http_proxy
        self._https_proxy = _https_proxy
        self._socks_5proxy = _socks_5proxy
        self._socks_5net_work = _socks_5net_work
        self._no_proxy = _no_proxy
        self._network = _network
        self._product_id = _product_id
        self._max_idle_conns = _max_idle_conns
        self._endpoint_type = _endpoint_type
        self._open_platform_endpoint = _open_platform_endpoint
        self._credential = _credential
        if UtilClient.is_unset(config):
            raise TeaException({
                "code": "ParameterMissing",
                "message": "'config' can not be unset"
            })
        if not UtilClient.empty(config.access_key_id) and not UtilClient.empty(
                config.access_key_secret):
            if not UtilClient.empty(config.security_token):
                config.type = "sts"
            else:
                config.type = "access_key"
            credential_config = credential_models.Config(
                access_key_id=config.access_key_id,
                type=config.type,
                access_key_secret=config.access_key_secret,
                security_token=config.security_token)
            self._credential = CredentialClient(credential_config)
        elif not UtilClient.is_unset(config.credential):
            self._credential = config.credential
        self._endpoint = config.endpoint
        self._protocol = config.protocol
        self._region_id = config.region_id
        self._user_agent = config.user_agent
        self._read_timeout = config.read_timeout
        self._connect_timeout = config.connect_timeout
        self._http_proxy = config.http_proxy
        self._https_proxy = config.https_proxy
        self._no_proxy = config.no_proxy
        self._socks_5proxy = config.socks_5proxy
        self._socks_5net_work = config.socks_5net_work
        self._max_idle_conns = config.max_idle_conns