Ejemplo n.º 1
0
class ServerConfig(object):
    def __init__(self, service_dir_client=None):
        self.service_dir_client = service_dir_client
        if self.service_dir_client is None:
            from servicedir import ServiceDirClient

            self.service_dir_client = ServiceDirClient()

    def _get_current_environment(self):
        # first, try to get environment from request_meta,
        # then from server_meta, then use default
        return get_request_meta().get("environment", get_server_meta().get("environment", DEFAULT_ENVIRONMENT))

    def get_endpoint(self, service, environment=None):
        environment = environment or self._get_current_environment()
        is_custom_endpoint = False
        endpoint = self.service_dir_client.get_endpoint(environment, service)
        custom_endpoint = get_request_meta().get("custom_endpoints", {}).get(service, None)
        if custom_endpoint:
            is_custom_endpoint = True
            # custom_endpoint could be an environment name
            # or an endpoint url
            if custom_endpoint in self.get_environments():
                endpoint = self.endpoints[custom_endpoint].get(service)
            else:
                endpoint = custom_endpoint
        return endpoint, is_custom_endpoint

    def get_services(self, environment=DEFAULT_ENVIRONMENT):
        return self.service_dir_client.get_services(environment)

    def get_environments(self):
        return self.service_dir_client.get_environments()
Ejemplo n.º 2
0
class ServerConfig(object):
    def __init__(self, service_dir_client=None):
        self.service_dir_client = service_dir_client
        if self.service_dir_client is None:
            from servicedir import ServiceDirClient
            self.service_dir_client = ServiceDirClient()

    def _get_current_environment(self):
        # first, try to get environment from request_meta,
        # then from server_meta, then use default
        return get_request_meta().get(
            'environment',
            get_server_meta().get('environment', DEFAULT_ENVIRONMENT))

    def get_endpoint(self, service, environment=None):
        environment = environment or self._get_current_environment()
        is_custom_endpoint = False
        endpoint = self.service_dir_client.get_endpoint(environment, service)
        custom_endpoint = get_request_meta().get('custom_endpoints',
                                                 {}).get(service, None)
        if custom_endpoint:
            is_custom_endpoint = True
            # custom_endpoint could be an environment name
            # or an endpoint url
            if custom_endpoint in self.get_environments():
                endpoint = self.endpoints[custom_endpoint].get(service)
            else:
                endpoint = custom_endpoint
        return endpoint, is_custom_endpoint

    def get_services(self, environment=DEFAULT_ENVIRONMENT):
        return self.service_dir_client.get_services(environment)

    def get_environments(self):
        return self.service_dir_client.get_environments()
Ejemplo n.º 3
0
 def set_service_dir_client(self,
                            service_dir_client=None,
                            service_dir_endpoint=None):
     if service_dir_client is not None:
         self.service_dir_client = service_dir_client
     else:
         from servicedir import ServiceDirClient
         self.service_dir_client = ServiceDirClient(service_dir_endpoint)
Ejemplo n.º 4
0
    def __init__(self, service_dir_client=None):
        self.service_dir_client = service_dir_client
        if self.service_dir_client is None:
            from servicedir import ServiceDirClient

            self.service_dir_client = ServiceDirClient()
Ejemplo n.º 5
0
 def __init__(self, service_dir_client=None):
     self.service_dir_client = service_dir_client
     if self.service_dir_client is None:
         from servicedir import ServiceDirClient
         self.service_dir_client = ServiceDirClient()