示例#1
0
 def test_resolver(self):
     # clinet = Mock()
     resolver = EndpointResolverRules(None)
     # can not be resolved
     request = ResolveEndpointRequest("foo", "test", "", "")
     endpoint = resolver.resolve(request)
     self.assertEqual(None, endpoint)
示例#2
0
 def test_resolver(self):
     # clinet = Mock()
     resolver = EndpointResolverRules(None)
     # can not be resolved
     request = ResolveEndpointRequest("region_id", "product_code", "", "")
     endpoint = resolver.resolve(request)
     self.assertEqual(None, endpoint)
示例#3
0
 def test_resolver_reginoal(self):
     resolver = EndpointResolverRules(None)
     endpoint_data = EndpointData()
     resolver.endpoint_map = endpoint_data.endpoint_map
     resolver.endpoint_regional = endpoint_data.endpoint_regional
     request = ResolveEndpointRequest("cn-hangzhou", "test", "", "")
     endpoint = resolver.resolve(request)
     self.assertEqual("test.cn-hangzhou.aliyuncs.com", endpoint)
示例#4
0
 def test_resolver_has_endpoint(self):
     resolver = EndpointResolverRules(None)
     request = ResolveEndpointRequest("foo", "test", "", "")
     endpoint_data = EndpointData()
     resolver.endpoint_map = endpoint_data.endpoint_map
     resolver.endpoint_regional = endpoint_data.endpoint_regional
     endpoint = resolver.resolve(request)
     self.assertEqual("bar", endpoint)
示例#5
0
 def test_resolver_has_endpoint(self):
     resolver = EndpointResolverRules(None)
     request = ResolveEndpointRequest("cn-hangzhou", "product_code", "", "")
     endpoint_data = EndpointData()
     request.endpoint_map = endpoint_data.endpoint_map
     request.endpoint_regional = endpoint_data.endpoint_regional
     endpoint = resolver.resolve(request)
     self.assertEqual("mock.endpoint", endpoint)
示例#6
0
 def test_resolver_network_special_endpoint(self):
     resolver = EndpointResolverRules(None)
     endpoint_data = EndpointData()
     resolver.endpoint_map = endpoint_data.endpoint_map
     resolver.endpoint_regional = endpoint_data.endpoint_regional
     request = ResolveEndpointRequest("foo", "test", "", "")
     request.request_network = "vpc"
     endpoint = resolver.resolve(request)
     self.assertEqual("test-vpc.foo.aliyuncs.com", endpoint)
 def test_resolver_central(self):
     resolver = EndpointResolverRules(None)
     endpoint_data = EndpointData()
     endpoint_data.endpoint_regional = "central"
     request = ResolveEndpointRequest("cn-beijing", "test", "", "")
     request.endpoint_map = endpoint_data.endpoint_map
     request.endpoint_regional = endpoint_data.endpoint_regional
     endpoint = resolver.resolve(request)
     self.assertEqual("test.aliyuncs.com", endpoint)
    def __init__(self, client, user_config=None):

        self._user_customized_endpoint_resolver = UserCustomizedEndpointResolver(
        )

        endpoint_resolvers = [
            self.predefined_endpoint_resolver,
            self._user_customized_endpoint_resolver,
            LocalConfigRegionalEndpointResolver(user_config),
            LocalConfigGlobalEndpointResolver(user_config),
            EndpointResolverRules(),
            LocationServiceEndpointResolver(client),
        ]

        self._resolver = ChainedEndpointResolver(endpoint_resolvers)
    def init_env(self, test_local_config=None, client=None):
        resolver_chain = []

        self._user_customized_endpoint_resolver = UserCustomizedEndpointResolver()
        if test_local_config is None:
            self._local_config_regional_endpoint_resolver = LocalConfigRegionalEndpointResolver()
            self._local_config_global_endpoint_resolver = LocalConfigGlobalEndpointResolver()
        else:
            self._local_config_regional_endpoint_resolver = \
                LocalConfigRegionalEndpointResolver(test_local_config)
            self._local_config_global_endpoint_resolver = \
                LocalConfigGlobalEndpointResolver(test_local_config)
        if client is not None:
            self._location_service_endpoint_resolver = LocationServiceEndpointResolver(client)
        else:
            self._location_service_endpoint_resolver = LocationServiceEndpointResolver(self.client)

        resolver_chain.append(self._user_customized_endpoint_resolver)
        resolver_chain.append(self._local_config_regional_endpoint_resolver)
        resolver_chain.append(self._local_config_global_endpoint_resolver)
        resolver_chain.append(EndpointResolverRules())
        resolver_chain.append(self._location_service_endpoint_resolver)

        self._endpoint_resolver = ChainedEndpointResolver(resolver_chain)