def __init__(self, client_config, credentials_provider):
        AlibabaCloudClient.__init__(self, client_config, credentials_provider)

        self.product_code = "Location"
        self.api_version = "2015-06-12"
        self.location_service_code = None
        self.location_endpoint_type = "openAPI"
 def __init__(_self):
     AlibabaCloudClient.__init__(_self, client_config,
                                 self.init_credentials_provider())
     self.product_code = product
     self.location_service_code = location_service_code
     self.api_version = version
     self.location_endpoint_type = endpoint_type
 def __init__(self, client_config, credentials_provider=None, retry_policy=None,
              endpoint_resolver=None):
     AlibabaCloudClient.__init__(self, client_config,
                                 credentials_provider=credentials_provider,
                                 retry_policy=retry_policy,
                                 endpoint_resolver=endpoint_resolver)
     self.product_code = 'polardb'
     self.api_version = '2017-08-01'
     self.location_service_code = 'polardb'
     self.location_endpoint_type = 'openAPI'
    def test_call_roa_request_with_secret_error(self):
        def init_credentials_provider():
            from alibabacloud.credentials import AccessKeyCredentials

            credentials = AccessKeyCredentials(
                access_key_id=self.access_key_id,
                access_key_secret="BadAccessKeySecret")
            from alibabacloud.credentials.provider import StaticCredentialsProvider
            credentials_provider = StaticCredentialsProvider(credentials)
            return credentials_provider

        client = AlibabaCloudClient(
            self.client_config,
            credentials_provider=init_credentials_provider())
        client.product_code = "ROS"
        client.api_version = "2015-09-01"
        client.location_service_code = 'ros'
        client.location_endpoint_type = "openAPI"
        api_request = APIRequest('DescribeResourceTypes', 'GET', 'https',
                                 'ROA')
        with self.assertRaises(ServerException) as e:
            client._handle_request(api_request)
        self.assertEqual(e.exception.service_name, "ROS")
        self.assertEqual(e.exception.http_status, 404)
        self.assertEqual(e.exception.endpoint, "ros.aliyuncs.com")
        self.assertEqual(e.exception.error_code, "InvalidAction.NotFound")
        self.assertEqual(
            e.exception.error_message,
            "Specified api is not found, please check your url and method.")
 def __init__(self,
              client_config,
              credentials_provider=None,
              retry_policy=None,
              endpoint_resolver=None):
     AlibabaCloudClient.__init__(self,
                                 client_config,
                                 credentials_provider=credentials_provider,
                                 retry_policy=retry_policy,
                                 endpoint_resolver=endpoint_resolver)
     self.product_code = 'ImageSearch'
     self.api_version = '2019-03-25'
     self.location_service_code = 'imagesearch'
     self.location_endpoint_type = 'openAPI'
Пример #6
0
 def __init__(self,
              client_config,
              credentials_provider=None,
              retry_policy=None,
              endpoint_resolver=None):
     AlibabaCloudClient.__init__(self,
                                 client_config,
                                 credentials_provider=credentials_provider,
                                 retry_policy=retry_policy,
                                 endpoint_resolver=endpoint_resolver)
     self.product_code = 'cusanalytic_sc_online'
     self.api_version = '2019-05-24'
     self.location_service_code = None
     self.location_endpoint_type = 'openAPI'
Пример #7
0
 def __init__(self,
              client_config,
              credentials_provider=None,
              retry_policy=None,
              endpoint_resolver=None):
     AlibabaCloudClient.__init__(self,
                                 client_config,
                                 credentials_provider=credentials_provider,
                                 retry_policy=retry_policy,
                                 endpoint_resolver=endpoint_resolver)
     self.product_code = 'ARMS4FINANCE'
     self.api_version = '2017-11-30'
     self.location_service_code = 'arms4finance'
     self.location_endpoint_type = 'openAPI'
 def __init__(self,
              client_config,
              credentials_provider=None,
              retry_policy=None,
              endpoint_resolver=None):
     AlibabaCloudClient.__init__(self,
                                 client_config,
                                 credentials_provider=credentials_provider,
                                 retry_policy=retry_policy,
                                 endpoint_resolver=endpoint_resolver)
     self.product_code = 'TeslaMaxCompute'
     self.api_version = '2018-01-04'
     self.location_service_code = 'teslamaxcompute'
     self.location_endpoint_type = 'openAPI'
    def test_call_rpc_request_with_secret_error(self):
        def init_credentials_provider():
            from alibabacloud.credentials import AccessKeyCredentials

            credentials = AccessKeyCredentials(
                access_key_id=self.access_key_id,
                access_key_secret="BadAccessKeySecret")
            from alibabacloud.credentials.provider import StaticCredentialsProvider
            credentials_provider = StaticCredentialsProvider(credentials)
            return credentials_provider

        client = AlibabaCloudClient(
            self.client_config,
            credentials_provider=init_credentials_provider())
        client.product_code = "Ecs"
        client.api_version = "2014-05-26"
        client.location_service_code = 'ecs'
        client.location_endpoint_type = "openAPI"
        api_request = APIRequest('DescribeRegions', 'GET', 'https', 'RPC')
        with self.assertRaises(ServerException) as e:
            client._handle_request(api_request)
        self.assertEqual(e.exception.service_name, "Ecs")
        self.assertEqual(e.exception.http_status, 400)
        self.assertEqual(e.exception.endpoint, "ecs-cn-hangzhou.aliyuncs.com")
        self.assertEqual(e.exception.error_code, "InvalidAccessKeySecret")
        self.assertEqual(
            e.exception.error_message, "The AccessKeySecret is incorrect. "
            "Please check your AccessKeyId and AccessKeySecret.")
    def test_call_request_with_client_env_priority(self):
        self._create_default_ram_user()
        self._create_access_key()
        self._create_default_ram_role()

        ram_role_arn_credential = RamRoleCredentialsProvider(
            self.client_config,
            AccessKeyCredentials(self.ram_user_access_key_id,
                                 self.ram_user_access_key_secret),
            self.ram_role_arn, "alice_test")
        client = AlibabaCloudClient(self.client_config,
                                    ram_role_arn_credential)
        client.product_code = "Ecs"
        client.api_version = "2014-05-26"
        client.location_service_code = 'ecs'
        client.location_endpoint_type = "openAPI"
        api_request = APIRequest('DescribeRegions', 'GET', 'https', 'RPC')

        os.environ["ALIBABA_CLOUD_ACCESS_KEY_ID"] = self.access_key_id
        os.environ["ALIBABA_CLOUD_ACCESS_KEY_SECRET"] = self.access_key_secret

        response = client._handle_request(api_request)
        response_credential = response.http_request.credentials
        self.assertTrue(response_credential.access_key_id.startswith("STS."))
        response = response.http_response.content
        ret = self.get_dict_response(response)
        self.assertTrue(ret.get("Regions"))
        self.assertTrue(ret.get("RequestId"))
    def test_call_request_with_env_config_priority(self):
        os.environ.setdefault("ALIBABA_CLOUD_ACCESS_KEY_ID",
                              self.access_key_id)
        os.environ.setdefault("ALIBABA_CLOUD_ACCESS_KEY_SECRET",
                              self.access_key_secret)

        client_config = ClientConfig(region_id=self.region_id)

        client = AlibabaCloudClient(
            client_config,
            credentials_provider=self.init_credentials_provider())
        client.product_code = "Ecs"
        client.api_version = "2014-05-26"
        client.location_service_code = 'ecs'
        client.location_endpoint_type = "openAPI"
        api_request = APIRequest('DescribeRegions', 'GET', 'https', 'RPC')
        response = client._handle_request(api_request)

        env_credential_id = os.environ.get("ALIBABA_CLOUD_ACCESS_KEY_ID")
        env_credential_secret = os.environ.get(
            "ALIBABA_CLOUD_ACCESS_KEY_SECRET")
        response_key_id = response.http_request.credentials.access_key_id
        response_key_secret = response.http_request.credentials.access_key_secret
        self.assertEqual(env_credential_id, response_key_id)
        self.assertEqual(env_credential_secret, response_key_secret)

        response = response.http_response.content
        ret = self.get_dict_response(response)
        self.assertTrue(ret.get("Regions"))
        self.assertTrue(ret.get("RequestId"))
        os.environ.pop("ALIBABA_CLOUD_ACCESS_KEY_ID")
        os.environ.pop("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
Пример #12
0
    def test_rpc_assume_role_request_with_sts_token(self):
        self._create_default_ram_user()
        # self._attach_default_policy()
        self._create_access_key()
        self._create_default_ram_role()

        acs_client = ClientConfig(region_id=self.region_id)
        ram_role_arn_credential = RamRoleCredentialsProvider(
            acs_client,
            AccessKeyCredentials(self.ram_user_access_key_id,
                                 self.ram_user_access_key_secret),
            self.ram_role_arn, "alice_test")
        client = AlibabaCloudClient(acs_client, ram_role_arn_credential)
        client.product_code = "Ecs"
        client.api_version = "2014-05-26"
        client.location_service_code = 'ecs'
        client.location_endpoint_type = "openAPI"
        api_request = APIRequest('DescribeRegions', 'GET', 'https', 'RPC')
        response = client._handle_request(api_request)

        response_credentials = response.http_request.credentials
        self.assertTrue(response_credentials.access_key_id.startswith("STS."))

        response = response.http_response.content
        ret = self.get_dict_response(response)
        self.assertTrue(ret.get("Regions"))
        self.assertTrue(ret.get("RequestId"))
    def test_faas_resolve(self):
        temp_client = self.temp_client("faas")
        resolver = DefaultEndpointResolver(temp_client.config,
                                           temp_client.credentials_provider)
        request = ResolveEndpointRequest("cn-hangzhou", "faas", None, None)
        self.assertEqual("faas.cn-hangzhou.aliyuncs.com",
                         resolver.resolve(request))

        client = AlibabaCloudClient(self.client_config,
                                    self.init_credentials_provider())
        client.product_code = "faas"
        client.api_version = "2017-08-24"
        client.location_endpoint_type = "openAPI"
        api_request = APIRequest('DescribeLoadTaskStatus', 'POST', 'https',
                                 'RPC')
        api_request._params = {
            "FpgaUUID": "blah",
            "InstanceId": "blah",
            "RoleArn": "blah"
        }

        try:
            client._handle_request(api_request)
            assert False
        except ServerException as e:
            self.assertEqual(e.error_code, "EntityNotExist.RoleError")
            self.assertEqual(e.error_message, "The specified Role not exists")
Пример #14
0
    def test_roa_assume_role_request_with_sts_token(self):
        self._create_default_ram_user()
        # self._attach_default_policy()
        self._create_access_key()
        self._create_default_ram_role()

        roa_client = ClientConfig(region_id=self.region_id)
        ram_role_arn_credential = RamRoleCredentialsProvider(
            roa_client,
            AccessKeyCredentials(self.ram_user_access_key_id,
                                 self.ram_user_access_key_secret),
            self.ram_role_arn, "alice_test")
        client = AlibabaCloudClient(roa_client, ram_role_arn_credential)
        client.product_code = "ROS"
        client.api_version = "2015-09-01"
        client.location_service_code = 'ros'
        client.location_endpoint_type = "openAPI"
        api_request = APIRequest('DescribeResourceTypes', 'GET', 'https',
                                 'ROA')
        api_request.uri_pattern = '/resource_types'
        api_request.path_params = None
        response = client._handle_request(api_request)

        response_credentials = response.http_request.credentials
        self.assertTrue(response_credentials.access_key_id.startswith("STS."))

        response = response.http_response.content
        ret = self.get_dict_response(response)
        self.assertTrue(ret.get("ResourceTypes"))
 def test_products_with_location_service(self):
     client = AlibabaCloudClient(self.client_config,
                                 self.init_credentials_provider())
     client.product_code = "Ecs"
     client.api_version = "2014-05-26"
     client.location_service_code = 'ecs'
     client.location_endpoint_type = "openAPI"
     api_request = APIRequest('DescribeRegions', 'GET', 'https', 'RPC')
     response = client._handle_request(api_request)
 def test_location_service_code_not_equals_product_code(self):
     client = AlibabaCloudClient(self.client_config,
                                 self.init_credentials_provider())
     client.product_code = "CloudAPI"
     client.api_version = "2016-07-14"
     client.location_service_code = 'apigateway'
     client.location_endpoint_type = "openAPI"
     api_request = APIRequest('DescribeApis', 'GET', 'https', 'RPC')
     context = client._handle_request(api_request)
     response = json.loads(str(context.http_response.text))
     self.assertTrue(response.get('RequestId'))
Пример #17
0
 def test_server_unreachable(self):
     client_config = self.client_config
     client_config.region_id = 'cn-abc'
     client = AlibabaCloudClient(client_config, self.init_credentials_provider())
     client.product_code = "Ecs"
     client.api_version = "2014-05-26"
     client.location_service_code = 'ecs'
     client.location_endpoint_type = "openAPI"
     api_request = APIRequest('DescribeRegions', 'GET', 'https', 'RPC')
     try:
         client._handle_request(api_request)
         assert False
     except InvalidRegionIDException as e:
         self.assertTrue(e.error_message.startswith(
             "No such region 'cn-abc'. Please check your region ID."))
 def test_call_rpc_request_with_config_default(self):
     client = AlibabaCloudClient(
         self.client_config,
         credentials_provider=self.init_credentials_provider())
     client.product_code = "Ecs"
     client.api_version = "2014-05-26"
     client.location_service_code = 'ecs'
     client.location_endpoint_type = "openAPI"
     api_request = APIRequest('DescribeRegions', 'GET', 'https', 'RPC')
     response = client._handle_request(api_request)
     response = response.http_response.content
     ret = self.get_dict_response(response)
     self.assertTrue(ret.get("Regions"))
     self.assertTrue(ret.get("RequestId"))
 def test_call_roa_request_with_config_default(self):
     client = AlibabaCloudClient(
         self.client_config,
         credentials_provider=self.init_credentials_provider())
     client.product_code = "ROS"
     client.api_version = "2015-09-01"
     client.location_service_code = 'ros'
     client.location_endpoint_type = "openAPI"
     api_request = APIRequest('DescribeResourceTypes', 'GET', 'https',
                              'ROA')
     api_request.uri_pattern = '/resource_types'
     api_request.path_params = None
     response = client._handle_request(api_request)
     response = response.http_response.content
     ret = self.get_dict_response(response)
     self.assertTrue(ret.get("ResourceTypes"))
Пример #20
0
    def test_request_with_listkeys(self):

        client = AlibabaCloudClient(
            self.client_config,
            credentials_provider=self.init_credentials_provider())
        client.product_code = "Kms"
        client.api_version = "2016-01-20"
        client.location_service_code = 'kms'
        client.location_endpoint_type = "openAPI"
        api_request = APIRequest('ListKeys', 'GET', 'https', 'RPC')
        try:
            context = client._handle_request(api_request)
        except ServerException as e:
            self.assertEqual(e.http_status, 403)
        else:
            response = context.result
            self.assertTrue(response.get("PageNumber"))
    def test_location_service_code_not_equals_product_code2(self):
        # The product changed from api_gateway to edas
        temp_client = self.temp_client('Edas', '2017-08-01', 'openAPI',
                                       'BindSlb')
        self.init_env(temp_client.config, temp_client.credentials_provider,
                      "{}")
        client = AlibabaCloudClient(self.client_config,
                                    self.init_credentials_provider())
        client.product_code = "CloudAPI"
        client.api_version = "2016-07-14"
        client.location_service_code = 'apigateway'
        client.location_endpoint_type = "openAPI"
        client._endpoint_resolver = self._endpoint_resolver

        with patch.object(self._location_service_endpoint_resolver,
                          '_call_location_service',
                          wraps=self._location_service_endpoint_resolver.
                          _call_location_service) as monkey:
            for i in range(3):
                api_request = APIRequest('DescribeApis', 'GET', 'https', 'RPC')
                response = client._handle_request(api_request)
        self.assertEqual(0, monkey.call_count)

        client._endpoint_resolver = self._endpoint_resolver
    def test_call_rpc_request_with_env_ak(self):
        os.environ["ALIBABA_CLOUD_ACCESS_KEY_ID"] = self.access_key_id
        os.environ["ALIBABA_CLOUD_ACCESS_KEY_SECRET"] = self.access_key_secret

        client_config = ClientConfig(region_id=self.region_id)
        client = AlibabaCloudClient(
            client_config,
            credentials_provider=self.init_credentials_provider())
        client.product_code = "Ecs"
        client.api_version = "2014-05-26"
        client.location_service_code = 'ecs'
        client.location_endpoint_type = "openAPI"
        api_request = APIRequest('DescribeRegions', 'GET', 'https', 'RPC')
        response = client._handle_request(api_request)
        response = response.http_response.content
        ret = self.get_dict_response(response)
        self.assertTrue(ret.get("Regions"))
        self.assertTrue(ret.get("RequestId"))
    def test_call_roa_request_with_client(self):
        client = AlibabaCloudClient(self.client_config,
                                    self.init_credentials_provider())
        client.product_code = "ROS"
        client.api_version = "2015-09-01"
        client.location_service_code = 'ros'
        client.location_endpoint_type = "openAPI"
        api_request = APIRequest('DescribeResourceTypes', 'GET', 'https',
                                 'ROA')
        api_request.uri_pattern = '/stacks/[StackName]/[StackId]/resources'
        api_request.path_params = None
        api_request._params = {"StackId": "StackId", "StackName": "StackName"}

        try:
            response = client._handle_request(api_request)
            assert False
        except ServerException as e:
            self.assertEqual("InvalidUrl", e.error_code)
            self.assertTrue(
                e.error_message.startswith("Request url is invalid"))
    def test_call_roa_request_with_env_ak(self):
        os.environ["ALIBABA_CLOUD_ACCESS_KEY_ID"] = self.access_key_id
        os.environ["ALIBABA_CLOUD_ACCESS_KEY_SECRET"] = self.access_key_secret

        client_config = ClientConfig(region_id=self.region_id)
        client = AlibabaCloudClient(
            client_config,
            credentials_provider=self.init_credentials_provider())
        client.product_code = "ROS"
        client.api_version = "2015-09-01"
        client.location_service_code = 'ros'
        client.location_endpoint_type = "openAPI"
        api_request = APIRequest('DescribeResourceTypes', 'GET', 'https',
                                 'ROA')
        api_request.uri_pattern = '/resource_types'
        api_request.path_params = None
        response = client._handle_request(api_request)
        response = response.http_response.content
        ret = self.get_dict_response(response)
        self.assertTrue(ret.get("ResourceTypes"))
        os.environ.pop("ALIBABA_CLOUD_ACCESS_KEY_ID")
        os.environ.pop("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
    def test_call_request_with_config_role_name_priority(self):
        os.environ["ALIBABA_CLOUD_ROLE_NAME"] = self.default_ram_role_name

        client_config = ClientConfig(region_id=self.region_id)
        client = AlibabaCloudClient(
            client_config,
            credentials_provider=self.init_credentials_provider())

        client.product_code = "Ecs"
        client.api_version = "2014-05-26"
        client.location_service_code = 'ecs'
        client.location_endpoint_type = "openAPI"
        api_request = APIRequest('DescribeRegions', 'GET', 'https', 'RPC')
        response = client._handle_request(api_request)

        response_key_id = response.http_request.credentials.access_key_id
        self.assertFalse(response_key_id.startswith("TST."))

        response = response.http_response.content
        ret = self.get_dict_response(response)
        self.assertTrue(ret.get("Regions"))
        self.assertTrue(ret.get("RequestId"))
        os.environ.pop("ALIBABA_CLOUD_ROLE_NAME")
Пример #26
0
 def __init__(self, client_config, credentials_provider=None):
     AlibabaCloudClient.__init__(self, client_config, credentials_provider)
     self.product_code = 'ROS'
     self.api_version = '2015-09-01'
     self.location_service_code = 'ros'
     self.location_endpoint_type = 'openAPI'