Esempio n. 1
0
def load_certificates(path, certs=None):
    """load all the certificates stored in the given path.

    In case some certificates are already loaded with the same hostname,
    they will be replaced with the new ones.
    """
    logger.info('loading the certificates located in %s' % path)
    if certs is None:
        certs = {}

    for filename in [os.path.join(path, f) for f in os.listdir(path)
                     if os.path.isfile(os.path.join(path, f))
                     and f.endswith('.crt')]:
        # the files have to be named by the hostname
        algo, hostname = parse_filename(filename)
        cert = get_certificate(algo, filename)
        certs[hostname] = cert
    return certs
Esempio n. 2
0
    def __call__(self, msg):
        """proxy to the functions exposed by the worker"""
        logger.info('worker called with the message %s' % msg)
        try:
            try:
                function_id, serialized_data = msg.split('::', 1)
                obj = PROTOBUF_CLASSES[function_id]()
                obj.ParseFromString(serialized_data)
                data = {}
                for field, value in obj.ListFields():
                    data[field.name] = value

            except ValueError:
                raise ValueError('could not parse data')

            if not hasattr(self, function_id):
                raise ValueError('the function does not exists')

            res = getattr(self, function_id)(**data)
            return Response(value=res).SerializeToString()
        except Exception as e:
            return Response(error=e.message).SerializeToString()
Esempio n. 3
0
    def __call__(self, job):
        """proxy to the functions exposed by the worker"""
        logger.info('worker called with the message %s' % job)
        function_id, serialized_data = job.data.split('::', 1)
        req_cls, resp_cls = PROTOBUF_CLASSES[function_id]
        obj = req_cls()

        if not hasattr(self, function_id):
            raise ValueError('the function %s does not exists' % function_id)

        try:
            obj.ParseFromString(serialized_data)
            data = {}
            for field, value in obj.ListFields():
                data[field.name] = value
        except ValueError:
            raise ValueError('could not parse data')

        try:
            res = getattr(self, function_id)(**data)
            return resp_cls(value=res).SerializeToString()
        except ConnectionError as e:
            return resp_cls(error_type="connection_error", error=e.message)
Esempio n. 4
0
    def __call__(self, job):
        """proxy to the functions exposed by the worker"""
        logger.info('worker called with the message %s' % job)
        function_id, serialized_data = job.data.split('::', 1)
        req_cls, resp_cls = PROTOBUF_CLASSES[function_id]
        obj = req_cls()

        if not hasattr(self, function_id):
            raise ValueError('the function %s does not exists' % function_id)

        try:
            obj.ParseFromString(serialized_data)
            data = {}
            for field, value in obj.ListFields():
                data[field.name] = value
        except ValueError:
            raise ValueError('could not parse data')

        try:
            res = getattr(self, function_id)(**data)
            return resp_cls(value=res).SerializeToString()
        except ConnectionError as e:
            return resp_cls(error_type="connection_error", error=e.message)
Esempio n. 5
0
 def __init__(self, supportdocs=None, **kwargs):
     logger.info('starting a crypto worker')
     if supportdocs is None:
         supportdocs = SupportDocumentManagerWithCache(**kwargs)
     self.supportdocs = supportdocs
Esempio n. 6
0
 def __init__(self, path):
     logger.info('starting a crypto worker')
     self.serialize = json.dumps
     self.certs = []
     self.certs = load_certificates(path)
Esempio n. 7
0
 def __init__(self, supportdocs=None, **kwargs):
     logger.info('starting a crypto worker')
     if supportdocs is None:
         supportdocs = SupportDocumentManagerWithCache(**kwargs)
     self.supportdocs = supportdocs