Ejemplo n.º 1
0
    def initialize(self, endpoint):
        static_endpoint = self.config.get('endpoint')

        if static_endpoint:
            endpoint = static_endpoint

        e = parse_endpoint(endpoint)
        self.client = pygrpc.client(
            endpoint=f'{e.get("hostname")}:{e.get("port")}', version='plugin')
Ejemplo n.º 2
0
    def setUpClass(cls):
        super(TestProjectGroup, cls).setUpClass()
        endpoints = cls.config.get('ENDPOINTS', {})
        cls.identity_v1 = pygrpc.client(endpoint=endpoints.get('identity',
                                                               {}).get('v1'),
                                        version='v1')

        cls._create_domain()
        cls._create_domain_owner()
        cls._issue_owner_token()
Ejemplo n.º 3
0
    def setUp(self):
        endpoints = self.config.get('ENDPOINTS', {})
        self.identity_v1 = pygrpc.client(endpoint=endpoints.get('identity', {}).get('v1'),
                                         version='v1')

        self.domain = None
        self.owner_id = 'DomainOwner'
        self.owner_pw = utils.generate_password()
        self.owner = None
        self.owner_token = None
Ejemplo n.º 4
0
 def _init_client(self):
     for k, v in self.config['endpoint'].items():
         # parse endpoint
         e = parse_endpoint(v)
         self.protocol = e['scheme']
         if self.protocol == 'grpc':
             # create grpc client
             self.client = pygrpc.client(endpoint="%s:%s" % (e['hostname'], e['port']), version=k)
         elif self.protocol == 'http':
             # TODO:
             pass
Ejemplo n.º 5
0
    def __init__(self, transaction, config):
        super().__init__(transaction, config)

        if 'endpoint' not in self.config:
            raise ERROR_WRONG_CONFIGURATION(key='endpoint')

        if len(self.config['endpoint']) > 1:
            raise ERROR_WRONG_CONFIGURATION(key='too many endpoint')

        for (k, v) in self.config['endpoint'].items():
            e = parse_endpoint(v)
            self.client = pygrpc.client(endpoint=f'{e.get("hostname")}:{e.get("port")}', version=k)
Ejemplo n.º 6
0
    def __init__(self, transaction, config):
        super().__init__(transaction, config)

        if 'endpoint' not in self.config:
            raise ERROR_WRONG_CONFIGURATION(key='endpoint')

        if len(self.config['endpoint']) > 1:
            raise ERROR_WRONG_CONFIGURATION(key='too many endpoint')

        for version, uri in self.config['endpoint'].items():
            e = parse_grpc_endpoint(uri)
            self.client = pygrpc.client(endpoint=e['endpoint'], ssl_enabled=e['ssl_enabled'])
Ejemplo n.º 7
0
    def initialize(self, endpoint):
        """ Initialize based on endpoint
        Args:
            endpoint (message): endpoint message
        """
        e = parse_grpc_endpoint(endpoint)
        self.client = pygrpc.client(endpoint=e['endpoint'], ssl_enabled=e['ssl_enabled'], max_message_length=1024*1024*32)

        if self.client is None:
            _LOGGER.error(f'[initialize] Cannot access gRPC server. '
                          f'(host: {e.get("hostname")}, port: {e.get("port")}, version: plugin)')
            raise ERROR_GRPC_CONFIGURATION(endpoint=endpoint)
Ejemplo n.º 8
0
    def _init_client(self, service, resource):
        if service not in self.client:
            if service not in self.config:
                raise ERROR_INVALID_RESOURCE_TYPE(
                    resource_type=f'{service}.{resource}')

            e = parse_endpoint(self.config[service])
            if e.get('path') is None:
                raise ERROR_CONNECTOR_CONFIGURATION(
                    backend=self.__class__.__name__)

            self.client[service] = pygrpc.client(
                endpoint=f'{e.get("hostname")}:{e.get("port")}')
Ejemplo n.º 9
0
    def _init_client(self):
        self.client = {}
        for service, endpoint in self.config.items():
            e = parse_endpoint(endpoint)
            # _LOGGER.debug(f'[_init_client] Load endpoint : {endpoint}')
            if e.get('path') is None:
                raise ERROR_CONNECTOR_CONFIGURATION(
                    backend=self.__class__.__name__)

            version = e.get('path').replace('/', '')

            self.client[service] = pygrpc.client(
                endpoint=f'{e.get("hostname")}:{e.get("port")}',
                version=version)
Ejemplo n.º 10
0
    def initialize(self, endpoint):
        _LOGGER.info(f'[initialize] endpoint: {endpoint}')

        endpoint = endpoint.replace('"', '')
        e = parse_endpoint(endpoint)
        protocol = e['scheme']
        if protocol == 'grpc':
            self.client = pygrpc.client(endpoint="%s:%s" %
                                        (e['hostname'], e['port']),
                                        version='plugin')
        elif protocol == 'http':
            # TODO:
            pass

        if self.client is None:
            raise ERROR_GRPC_CONFIGURATION
Ejemplo n.º 11
0
def _get_client(service, api_version):
    endpoint = get_endpoint(service)

    if endpoint is None:
        raise Exception(f'Endpoint is not set. (service={service})')

    try:
        e = parse_endpoint(endpoint)
        client = pygrpc.client(endpoint=f'{e.get("hostname")}:{e.get("port")}',
                               version=api_version,
                               max_message_length=1024 * 1024 * 256)
        client.service = service
        client.api_version = api_version
        return client
    except Exception:
        raise ValueError(f'Endpoint is invalid. (endpoint={endpoint})')
Ejemplo n.º 12
0
def _get_resources_from_client(endpoints, api_version='v1'):
    resources = {}
    for service, endpoint in endpoints.items():
        try:
            e = parse_endpoint(endpoint)
            client = pygrpc.client(
                endpoint=f'{e.get("hostname")}:{e.get("port")}',
                version=api_version)

            resources[service] = {}
            for api_resource, verb in client.api_resources.items():
                resources[service][api_resource] = {'alias': [], 'verb': verb}

        except Exception:
            raise ValueError(f'Endpoint is invalid. (endpoint={endpoint})')

    return resources
Ejemplo n.º 13
0
    def __init__(self, transaction, config, **kwargs):
        super().__init__(transaction, config, **kwargs)
        """ Overwrite configuration

        Remote Repository has different authentication.
        So do not use your token at meta.
        Use another authentication algorithm like token

        Args:
            conn: dict (endpoint, version, ...)

        """
        #_LOGGER.debug("[RemoteRepositoryConnector] meta: %s" % self.transaction.meta)
        #_LOGGER.debug("[RemoteRepositoryConnector] self.conn: %s" % self.conn)

        e = parse_grpc_endpoint(self.conn['endpoint'])
        self.client = pygrpc.client(endpoint=e['endpoint'],
                                    ssl_enabled=e['ssl_enabled'])

        # Update meta (like domain_id)
        # TODO: change meta to marketplace token
        meta = self.transaction.get_connection_meta()
        new_meta = []
        if 'credential' in self.conn:
            credential = self.conn['credential']
            if 'token' in credential:
                # self.meta = [('token',credential['token'])]
                self._token = credential['token']
            else:
                # TODO: raise ERROR
                raise ERROR_CONFIGURATION(key='credential')

            for (k, v) in meta:
                if k != 'token' and v is not None:
                    new_meta.append((k, v))
                elif k == 'token':
                    new_meta.append(('token', self._token))
            self.meta = new_meta

        # Update domain_id
        # This repository is not our domain.
        # find domain_id from token
        decoded_token = JWTUtil.unverified_decode(self._token)
        self.domain_id = decoded_token['did']
Ejemplo n.º 14
0
    def initialize(self, endpoint):
        if endpoint is None:
            raise ERROR_GRPC_CONFIGURATION
        endpoint = endpoint.replace('"', '')
        e = parse_endpoint(endpoint)
        protocol = e['scheme']
        if protocol == 'grpc':
            self.client = pygrpc.client(endpoint="%s:%s" %
                                        (e['hostname'], e['port']),
                                        version='plugin')
        elif protocol == 'http':
            # TODO:
            pass

        if self.client is None:
            _LOGGER.error(
                f'[initialize] Cannot access gRPC server. '
                f'(host: {e.get("hostname")}, port: {e.get("port")}, version: plugin)'
            )
            raise ERROR_GRPC_CONFIGURATION
Ejemplo n.º 15
0
    def __init__(self, transaction, config):
        super().__init__(transaction, config)
        _LOGGER.debug("config: %s" % self.config)
        if 'endpoint' not in self.config:
            raise ERROR_WRONG_CONFIGURATION(key='endpoint')

        if len(self.config['endpoint']) > 1:
            raise ERROR_WRONG_CONFIGURATION(key='too many endpoint')

        for (k, v) in self.config['endpoint'].items():
            # parse endpoint
            e = parse_endpoint(v)
            self.protocol = e['scheme']
            if self.protocol == 'grpc':
                # create grpc client
                self.client = pygrpc.client(endpoint="%s:%s" %
                                            (e['hostname'], e['port']),
                                            version=k)
            elif self.protocol == 'http':
                # TODO:
                pass
Ejemplo n.º 16
0
 def _init_client(self):
     for version, uri in self.config['endpoint'].items():
         e = parse_endpoint(uri)
         self.client = pygrpc.client(endpoint=f'{e.get("hostname")}:{e.get("port")}', version=version)
Ejemplo n.º 17
0
 def initialize(self, endpoint):
     e = parse_endpoint(endpoint)
     self.client = pygrpc.client(
         endpoint=f'{e.get("hostname")}:{e.get("port")}', version='plugin')
Ejemplo n.º 18
0
 def _init_client(self):
     for version, uri in self.config['endpoint'].items():
         e = parse_grpc_endpoint(uri)
         self.client = pygrpc.client(endpoint=e['endpoint'],
                                     ssl_enabled=e['ssl_enabled'])
Ejemplo n.º 19
0
    def initialize(self, endpoint):
        _LOGGER.info(f'[initialize] endpoint: {endpoint}')

        e = parse_endpoint(endpoint)
        self.client = pygrpc.client(endpoint=f'{e.get("hostname")}:{e.get("port")}', version='plugin')
Ejemplo n.º 20
0
 def _init_client(self):
     e = parse_grpc_endpoint(self._endpoints[self._service])
     self._client = pygrpc.client(endpoint=e['endpoint'],
                                  ssl_enabled=e['ssl_enabled'])