Exemple #1
0
 def describe_rtc_channel_list(self,
                               sort_type=None,
                               user_id=None,
                               service_area=None,
                               page_size=None,
                               owner_id=None,
                               page_no=None,
                               app_id=None,
                               channel_id=None,
                               time_point=None):
     api_request = APIRequest('DescribeRtcChannelList', 'GET', 'http',
                              'RPC', 'query')
     api_request._params = {
         "SortType": sort_type,
         "UserId": user_id,
         "ServiceArea": service_area,
         "PageSize": page_size,
         "OwnerId": owner_id,
         "PageNo": page_no,
         "AppId": app_id,
         "ChannelId": channel_id,
         "TimePoint": time_point
     }
     return self._handle_request(api_request).result
Exemple #2
0
 def start_mpu_task(self,
                    list_of_user_panes=None,
                    background_color=None,
                    crop_mode=None,
                    task_profile=None,
                    list_of_layout_ids=None,
                    task_id=None,
                    stream_url=None,
                    owner_id=None,
                    app_id=None,
                    media_encode=None,
                    channel_id=None):
     api_request = APIRequest('StartMPUTask', 'GET', 'http', 'RPC', 'query')
     api_request._params = {
         "UserPanes": list_of_user_panes,
         "BackgroundColor": background_color,
         "CropMode": crop_mode,
         "TaskProfile": task_profile,
         "LayoutIds": list_of_layout_ids,
         "TaskId": task_id,
         "StreamURL": stream_url,
         "OwnerId": owner_id,
         "AppId": app_id,
         "MediaEncode": media_encode,
         "ChannelId": channel_id
     }
     repeat_info = {
         "UserPanes": ('UserPanes', 'list', 'dict', [
             ('PaneId', 'str', None, None),
             ('UserId', 'str', None, None),
             ('SourceType', 'str', None, None),
         ]),
         "LayoutIds": ('LayoutIds', 'list', 'str', None),
     }
     verify_params(api_request._params, repeat_info)
     return self._handle_request(api_request).result
 def describe_train_datas(self,
                          next_page_token=None,
                          tag_status=None,
                          page_size=None,
                          project_id=None,
                          show_log=None,
                          tag_id=None,
                          current_page=None,
                          owner_id=None,
                          iteration_id=None):
     api_request = APIRequest('DescribeTrainDatas', 'GET', 'http', 'RPC',
                              'query')
     api_request._params = {
         "NextPageToken": next_page_token,
         "TagStatus": tag_status,
         "PageSize": page_size,
         "ProjectId": project_id,
         "ShowLog": show_log,
         "TagId": tag_id,
         "CurrentPage": current_page,
         "OwnerId": owner_id,
         "IterationId": iteration_id
     }
     return self._handle_request(api_request).result
 def set_password_policy(self,
                         require_numbers=None,
                         password_reuse_prevention=None,
                         require_uppercase_characters=None,
                         max_password_age=None,
                         max_login_attemps=None,
                         hard_expiry=None,
                         minimum_password_length=None,
                         require_lowercase_characters=None,
                         require_symbols=None):
     api_request = APIRequest('SetPasswordPolicy', 'GET', 'https', 'RPC',
                              'query')
     api_request._params = {
         "RequireNumbers": require_numbers,
         "PasswordReusePrevention": password_reuse_prevention,
         "RequireUppercaseCharacters": require_uppercase_characters,
         "MaxPasswordAge": max_password_age,
         "MaxLoginAttemps": max_login_attemps,
         "HardExpiry": hard_expiry,
         "MinimumPasswordLength": minimum_password_length,
         "RequireLowercaseCharacters": require_lowercase_characters,
         "RequireSymbols": require_symbols
     }
     return self._handle_request(api_request).result
 def describe_data_hub_subscriptions(self,
                                     topic_id=None,
                                     source_ip=None,
                                     feature_type=None,
                                     page_size=None,
                                     depart_id=None,
                                     current_page=None,
                                     lang=None,
                                     project_id=None,
                                     key=None):
     api_request = APIRequest('DescribeDataHubSubscriptions', 'GET', 'http',
                              'RPC', 'query')
     api_request._params = {
         "TopicId": topic_id,
         "SourceIp": source_ip,
         "FeatureType": feature_type,
         "PageSize": page_size,
         "DepartId": depart_id,
         "CurrentPage": current_page,
         "Lang": lang,
         "ProjectId": project_id,
         "Key": key
     }
     return self._handle_request(api_request).result
Exemple #6
0
 def update_omni_sec_check_config(self,
                                  conf_id=None,
                                  valid=None,
                                  list_of_check_detail_dto_list=None,
                                  name=None,
                                  extras=None):
     api_request = APIRequest('UpdateOmniSecCheckConfig', 'POST', 'http',
                              'RPC', 'body')
     api_request._params = {
         "ConfId": conf_id,
         "Valid": valid,
         "CheckDetailDTOList": list_of_check_detail_dto_list,
         "Name": name,
         "Extras": extras
     }
     repeat_info = {
         "CheckDetailDTOList": ('CheckDetailDTOList', 'list', 'dict', [
             ('CheckIntervalUnit', 'str', None, None),
             ('CheckExtras', 'str', None, None),
             ('CheckIntervalVal', 'str', None, None),
         ]),
     }
     verify_params(api_request._params, repeat_info)
     return self._handle_request(api_request).result
    def test_throttled_backoff(self):
        def _handle_response(context):
            context.exception = ServerException("Throttling", "some error")

        config = self.client_config
        config.max_retry_times = 10
        config.endpoint = "somewhere.you.will.never.get"
        client = EcsClient(config, self.init_credentials_provider())
        api_request = APIRequest('DescribeInstances', 'GET', 'http', 'RPC')
        globals()["_test_compute_delay"] = []

        def record_sleep(delay):
            global _test_compute_delay
            _test_compute_delay.append(delay)

        from alibabacloud.handlers.api_protocol_handler import APIProtocolHandler
        from alibabacloud.handlers.credentials_handler import CredentialsHandler
        from alibabacloud.handlers.signer_handler import SignerHandler
        from alibabacloud.handlers.timeout_config_reader import TimeoutConfigReader
        from alibabacloud.handlers.endpoint_handler import EndpointHandler
        from alibabacloud.handlers.retry_handler import RetryHandler
        from alibabacloud.handlers.server_error_handler import ServerErrorHandler
        from alibabacloud.handlers.http_handler import HttpHandler
        DEFAULT_HANDLERS = [
            RetryHandler(),
            APIProtocolHandler(),
            CredentialsHandler(),
            SignerHandler(),
            TimeoutConfigReader(),
            EndpointHandler(),
            ServerErrorHandler(),
            HttpHandler(),
        ]

        client.handlers = DEFAULT_HANDLERS
        client.config = config

        with patch.object(time, "sleep", wraps=record_sleep) as monkey:
            with patch.object(ServerErrorHandler,
                              "handle_response",
                              wraps=_handle_response):
                try:
                    client._handle_request(api_request)
                    assert False
                except ServerException as e:
                    self.assertEqual("Throttling", e.error_code)
        self.assertEqual(10, monkey.call_count)
        self.assertEqual(10, len(_test_compute_delay))
Exemple #8
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_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_rpc_request_with_introduction_ak(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_credentials = response.http_request.credentials
        from alibabacloud.credentials import AccessKeyCredentials
        self.assertEqual(type(response_credentials), AccessKeyCredentials)

        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_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")
    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 mopen_create_group(self, creator=None):
     api_request = APIRequest('MopenCreateGroup', 'POST', 'https', 'RPC',
                              'body')
     api_request._params = {"Creator": creator}
     return self._handle_request(api_request).result
 def query_customer_sale_info(self, region_name=None):
     api_request = APIRequest('QueryCustomerSaleInfo', 'GET', 'http', 'RPC',
                              'query')
     api_request._params = {"RegionName": region_name}
     return self._handle_request(api_request).result
 def mo_pen_send_mqtt_message(self, payload=None, device_name=None):
     api_request = APIRequest('MoPenSendMqttMessage', 'POST', 'https',
                              'RPC', 'body')
     api_request._params = {"Payload": payload, "DeviceName": device_name}
     return self._handle_request(api_request).result
Exemple #16
0
 def describe_dcdn_refresh_quota(self, security_token=None, owner_id=None):
     api_request = APIRequest('DescribeDcdnRefreshQuota', 'GET', 'http', 'RPC', 'query')
     api_request._params = {"SecurityToken": security_token, "OwnerId": owner_id}
     return self._handle_request(api_request).result
Exemple #17
0
    def get_account_info(self, ):
        api_request = APIRequest('GetAccountInfo', 'GET', 'http', 'RPC', '')

        return self._handle_request(api_request).result
    def test_retry_conditions(self):
        import alibabacloud.retry.retry_policy as retry_policy
        from alibabacloud.retry.retry_condition import RetryCondition
        from alibabacloud.retry.retry_policy_context import RetryPolicyContext

        config = self.client_config
        client = EcsClient(config, self.init_credentials_provider())

        default_retry_policy = retry_policy.get_default_retry_policy()

        def HE():
            return HttpErrorException(http_error="some error")

        def SE(code):
            return ServerException(code, "some error")

        def _get_retryable(*conditions):
            context = RetryPolicyContext(*conditions)
            return default_retry_policy.should_retry(context)

        def _assert_not_retryable(*conditions):
            retryable = _get_retryable(*conditions)
            self.assertTrue(retryable & RetryCondition.NO_RETRY)

        def _assert_retryable(*conditions):
            retryable = _get_retryable(*conditions)
            self.assertFalse(retryable & RetryCondition.NO_RETRY)

        def _assert_retryable_with_client_token(request):
            conditions = [
                request,
                SE("InternalError"), 0, 500, 'ecs', '2014-05-26'
            ]
            retryable = _get_retryable(*conditions)
            self.assertTrue(
                retryable
                & RetryCondition.SHOULD_RETRY_WITH_THROTTLING_BACKOFF)

        def _assert_not_retryable_with_client_token(request):
            conditions = [
                request,
                SE("InternalError"), 0, 500, 'ecs', '2014-05-26'
            ]
            retryable = _get_retryable(*conditions)
            self.assertFalse(
                retryable
                & RetryCondition.SHOULD_RETRY_WITH_THROTTLING_BACKOFF)

        # retryable
        api_request = APIRequest('DescribeInstances', 'GET', 'http', 'RPC')
        timeout_exception = HE()
        invalid_param_excpetion = SE("MissingParameter")
        unknown_error = SE("SDK_UNKNOWN_SERVER_ERROR")
        internal_error = SE("InternalError")
        product_code = client.product_code.lower()
        api_version = client.api_version
        _assert_retryable(api_request, timeout_exception, 0, 500, product_code,
                          api_version)
        _assert_retryable(api_request, timeout_exception, 2, 500, product_code,
                          api_version)
        _assert_retryable(api_request, unknown_error, 0, 500, product_code,
                          api_version)
        _assert_retryable(api_request, unknown_error, 0, 502, product_code,
                          api_version)
        _assert_retryable(api_request, unknown_error, 0, 503, product_code,
                          api_version)
        _assert_retryable(api_request, unknown_error, 0, 504, product_code,
                          api_version)
        _assert_retryable(api_request, internal_error, 0, 500, product_code,
                          api_version)
        _assert_retryable(api_request, SE("Throttling"), 0, 400, product_code,
                          api_version)
        _assert_retryable(api_request, SE("ServiceUnavailable"), 0, 503,
                          product_code, api_version)
        _assert_not_retryable(api_request, invalid_param_excpetion, 0, 400,
                              product_code, api_version)
        _assert_not_retryable(api_request, timeout_exception, 3, 500,
                              product_code, api_version)
        _assert_not_retryable(api_request, SE("InvalidAccessKeyId.NotFound"),
                              0, 404, product_code, api_version)

        request1 = APIRequest('DescribeInstanceHistoryEvents', 'GET', 'http',
                              'RPC')

        _assert_retryable(request1, SE("ServiceUnavailable"), 0, 503,
                          product_code, api_version)

        request2 = APIRequest('DescribeDisks', 'GET', 'http', 'RPC')

        _assert_retryable(request2, SE("ServiceUnavailable"), 0, 503,
                          product_code, api_version)
        # no_retry
        no_retry_request = APIRequest('AttachDisk', 'GET', 'http', 'RPC')

        _assert_not_retryable(no_retry_request, timeout_exception, 0, 500,
                              product_code, api_version)
        _assert_not_retryable(no_retry_request, unknown_error, 0, 504,
                              product_code, api_version)
        _assert_not_retryable(no_retry_request, invalid_param_excpetion, 0,
                              400, product_code, api_version)
        request1 = APIRequest('CreateInstance', 'GET', 'http', 'RPC')

        _assert_retryable_with_client_token(request1)

        request1 = APIRequest('RunInstances', 'GET', 'http', 'RPC')
        _assert_retryable_with_client_token(request1)

        request1 = APIRequest('AttachDisk', 'GET', 'http', 'RPC')

        _assert_not_retryable_with_client_token(request1)

        request1 = APIRequest('DescribeInstances', 'GET', 'http', 'RPC')
        _assert_not_retryable_with_client_token(request1)
Exemple #19
0
 def get_trail_status(self, name=None):
     api_request = APIRequest('GetTrailStatus', 'GET', 'http', 'RPC',
                              'query')
     api_request._params = {"Name": name}
     return self._handle_request(api_request).result
Exemple #20
0
 def query_customer_by_id(self, id_=None):
     api_request = APIRequest('QueryCustomerById', 'GET', 'http', 'ROA',
                              'query')
     api_request.uri_pattern = '/customer'
     api_request._params = {"Id": id_}
     return self._handle_request(api_request).result
 def mo_pen_add_group_member(self, group_id=None, device_name=None):
     api_request = APIRequest('MoPenAddGroupMember', 'POST', 'https', 'RPC',
                              'body')
     api_request._params = {"GroupId": group_id, "DeviceName": device_name}
     return self._handle_request(api_request).result
 def describe_fpga_images(self, caller_uid=None):
     api_request = APIRequest('DescribeFpgaImages', 'POST', 'http', 'RPC',
                              'query')
     api_request._params = {"callerUid": caller_uid}
     return self._handle_request(api_request).result
    def pull_create_task(self, ):
        api_request = APIRequest('PullCreateTask', 'POST', 'http', 'RPC', '')

        return self._handle_request(api_request).result
Exemple #24
0
 def delete_user(self, uid=None, tid=None):
     api_request = APIRequest('DeleteUser', 'GET', 'http', 'RPC', 'query')
     api_request._params = {"Uid": uid, "Tid": tid}
     return self._handle_request(api_request).result
 def mo_pen_delete_group(self, group_id=None):
     api_request = APIRequest('MoPenDeleteGroup', 'POST', 'https', 'RPC',
                              'body')
     api_request._params = {"GroupId": group_id}
     return self._handle_request(api_request).result
Exemple #26
0
 def describe_user_dcdn_status(self, security_token=None, owner_id=None):
     api_request = APIRequest('DescribeUserDcdnStatus', 'GET', 'http', 'RPC', 'query')
     api_request._params = {"SecurityToken": security_token, "OwnerId": owner_id}
     return self._handle_request(api_request).result
Exemple #27
0
 def query_customer_by_phone(self, phone=None):
     api_request = APIRequest('QueryCustomerByPhone', 'GET', 'http', 'ROA',
                              'query')
     api_request.uri_pattern = '/customerbyphone'
     api_request._params = {"Phone": phone}
     return self._handle_request(api_request).result
Exemple #28
0
 def describe_dcdn_ipa_service(self, security_token=None, owner_id=None):
     api_request = APIRequest('DescribeDcdnIpaService', 'GET', 'http', 'RPC', 'query')
     api_request._params = {"SecurityToken": security_token, "OwnerId": owner_id}
     return self._handle_request(api_request).result
Exemple #29
0
 def describe_dcdn_domain_cname(self, domain_name=None, owner_id=None):
     api_request = APIRequest('DescribeDcdnDomainCname', 'GET', 'http', 'RPC', 'query')
     api_request._params = {"DomainName": domain_name, "OwnerId": owner_id}
     return self._handle_request(api_request).result
Exemple #30
0
 def describe_dcdn_user_resource_package(self, security_token=None, owner_id=None):
     api_request = APIRequest('DescribeDcdnUserResourcePackage', 'GET', 'http', 'RPC', 'query')
     api_request._params = {"SecurityToken": security_token, "OwnerId": owner_id}
     return self._handle_request(api_request).result