コード例 #1
0
ファイル: auth.py プロジェクト: credativ/gofer
def sign(authenticator, message):
    """
    Sign the message using the specified validator.
    signed document:
      {
        message: <message>,
        signature: <signature>
      }
    :param authenticator: A message authenticator.
    :type authenticator: Authenticator
    :param message: A (signed) json encoded AMQP message.
    :rtype message: str
    """
    if not authenticator:
        return message
    try:
        h = sha256()
        h.update(message)
        digest = h.hexdigest()
        signature = authenticator.sign(digest)
        signed = Document(message=message, signature=encode(signature))
        message = signed.dump()
    except Exception, e:
        log.info(utf8(e))
        log.debug(message, exc_info=True)
コード例 #2
0
ファイル: auth.py プロジェクト: stbenjam/gofer
def sign(authenticator, message):
    """
    Sign the message using the specified validator.
    signed document:
      {
        message: <message>,
        signature: <signature>
      }
    :param authenticator: A message authenticator.
    :type authenticator: Authenticator
    :param message: A (signed) json encoded AMQP message.
    :rtype message: str
    """
    if not authenticator:
        return message
    try:
        h = sha256()
        h.update(message)
        digest = h.hexdigest()
        signature = authenticator.sign(digest)
        signed = Document(message=message, signature=encode(signature))
        message = signed.dump()
    except Exception, e:
        log.info(utf8(e))
        log.debug(message, exc_info=True)
コード例 #3
0
ファイル: auth.py プロジェクト: stbenjam/gofer
def validate(authenticator, message):
    """
    Validate the document using the specified validator.
    signed document:
      {
        message: <message>,
        signature: <signature>
      }
    :param authenticator: A message authenticator.
    :type authenticator: Authenticator
    :param message: A json encoded AMQP message.
    :rtype message: str
    :return: The authenticated document.
    :rtype: Document
    :raises ValidationFailed: when message is not valid.
    """
    document, original, signature = peal(message)
    try:
        if authenticator:
            h = sha256()
            h.update(original)
            digest = h.hexdigest()
            authenticator.validate(document, digest, decode(signature))
        return document
    except ValidationFailed, de:
        de.document = document
        log.info(utf8(de))
        raise de
コード例 #4
0
ファイル: model.py プロジェクト: stbenjam/gofer
 def domain_id(self):
     """
     Unique domain ID.
     :return: A unique domain ID.
     :rtype: str
     """
     return '::'.join((self.__class__.__name__, utf8(id(self))))
コード例 #5
0
ファイル: reliability.py プロジェクト: stbenjam/gofer
 def _fn(messenger, *args, **kwargs):
     repair = lambda: None
     while not Thread.aborted():
         try:
             repair()
             return fn(messenger, *args, **kwargs)
         except LinkDetached, le:
             if le.condition != NOT_FOUND:
                 log.error(utf8(le))
                 repair = messenger.repair
                 sleep(DELAY)
             else:
                 raise NotFound(*le.args)
         except ConnectionException, pe:
             log.error(utf8(pe))
             repair = messenger.repair
             sleep(DELAY)
コード例 #6
0
 def _fn(messenger, *args, **kwargs):
     repair = lambda: None
     while not Thread.aborted():
         try:
             repair()
             return fn(messenger, *args, **kwargs)
         except ChannelError, le:
             if le.code != 404:
                 log.error(utf8(le))
                 repair = messenger.repair
                 sleep(DELAY)
             else:
                 raise NotFound(*le.args)
         except CONNECTION_EXCEPTIONS, pe:
             log.error(utf8(pe))
             repair = messenger.repair
             sleep(DELAY)
コード例 #7
0
ファイル: reliability.py プロジェクト: darinlively/gofer
 def _fn(messenger, *args, **kwargs):
     repair = lambda: None
     while not Thread.aborted():
         try:
             repair()
             return fn(messenger, *args, **kwargs)
         except LinkDetached, le:
             if le.condition != NOT_FOUND:
                 log.error(utf8(le))
                 repair = messenger.repair
                 sleep(DELAY)
             else:
                 raise NotFound(*le.args)
         except ConnectionException, pe:
             log.error(utf8(pe))
             repair = messenger.repair
             sleep(DELAY)
コード例 #8
0
ファイル: model.py プロジェクト: stbenjam/gofer
 def _fn(*args, **keywords):
     try:
         return fn(*args, **keywords)
     except ModelError:
         raise
     except Exception, e:
         log.exception(utf8(e))
         raise ModelError(*e.args)
コード例 #9
0
ファイル: reliability.py プロジェクト: darinlively/gofer
 def _fn(messenger, *args, **kwargs):
     repair = lambda: None
     while not Thread.aborted():
         try:
             repair()
             return fn(messenger, *args, **kwargs)
         except ChannelError, le:
             if le.code != 404:
                 log.error(utf8(le))
                 repair = messenger.repair
                 sleep(DELAY)
             else:
                 raise NotFound(*le.args)
         except CONNECTION_EXCEPTIONS, pe:
             log.error(utf8(pe))
             repair = messenger.repair
             sleep(DELAY)
コード例 #10
0
ファイル: manager.py プロジェクト: darinlively/gofer
 def __call__(self, *args, **kwargs):
     try:
         result = self.call(*args, **kwargs)
     except Exception, e:
         reply = Document()
         reply.code = 1
         reply.result = utf8(e)
         result = reply
コード例 #11
0
ファイル: manager.py プロジェクト: stbenjam/gofer
 def __call__(self, *args, **kwargs):
     try:
         result = self.call(*args, **kwargs)
     except Exception, e:
         reply = Document()
         reply.code = 1
         reply.result = utf8(e)
         result = reply
コード例 #12
0
ファイル: model.py プロジェクト: stbenjam/gofer
 def __init__(self, name=None, url=None):
     """
     :param name: The queue name.
     :type name: str
     :param url: The (optional) broker URL.
     :type url: str
     """
     BaseQueue.__init__(self, name or utf8(uuid4()))
     self.url = url
コード例 #13
0
 def unloaded(self):
     """
     Plugin unloaded.
     """
     for fn in self.unload:
         try:
             fn()
         except Exception:
             log.exception(utf8(fn))
コード例 #14
0
ファイル: consumer.py プロジェクト: credativ/gofer
 def close(self):
     """
     Close the receiver.
     """
     try:
         channel = self.channel()
         channel.basic_cancel(self.tag)
     except Exception, e:
         log.debug(utf8(e))
コード例 #15
0
ファイル: decorator.py プロジェクト: darinlively/gofer
 def unloaded(self):
     """
     Plugin unloaded.
     """
     for fn in self.unload:
         try:
             fn()
         except Exception:
             log.exception(utf8(fn))
コード例 #16
0
 def setpid(self, pid=os.getpid()):
     """
     Write our procecss id and flush.
     :param pid: The process ID.
     :type pid: int
     """
     self.__fp.seek(0)
     self.__fp.write(utf8(pid))
     self.__fp.flush()
コード例 #17
0
ファイル: lock.py プロジェクト: darinlively/gofer
 def setpid(self, pid=os.getpid()):
     """
     Write our procecss id and flush.
     :param pid: The process ID.
     :type pid: int
     """
     self.__fp.seek(0)
     self.__fp.write(utf8(pid))
     self.__fp.flush()
コード例 #18
0
 def close(self):
     """
     Close the receiver.
     """
     try:
         channel = self.channel()
         channel.basic_cancel(self.tag)
     except Exception, e:
         log.debug(utf8(e))
コード例 #19
0
 def sender(self, address):
     """
     Get a message sender for the specified address.
     :param address: An AMQP address.
     :type address: str
     :return: A sender.
     :rtype: proton.utils.BlockingSender
     """
     name = utf8(uuid4())
     return self._impl.create_sender(address, name=name)
コード例 #20
0
ファイル: connection.py プロジェクト: darinlively/gofer
 def sender(self, address):
     """
     Get a message sender for the specified address.
     :param address: An AMQP address.
     :type address: str
     :return: A sender.
     :rtype: proton.utils.BlockingSender
     """
     name = utf8(uuid4())
     return self._impl.create_sender(address, name=name)
コード例 #21
0
ファイル: connection.py プロジェクト: darinlively/gofer
 def close(self):
     """
     Close the connection.
     """
     connection = self._impl
     self._impl = None
     try:
         connection.close()
         log.info('closed: %s', self.url)
     except Exception, pe:
         log.debug(utf8(pe))
コード例 #22
0
ファイル: connection.py プロジェクト: stbenjam/gofer
 def close(self):
     """
     Close the connection.
     """
     connection = self._impl
     self._impl = None
     try:
         connection.close()
         log.info('closed: %s', self.url)
     except Exception, pe:
         log.exception(utf8(pe))
コード例 #23
0
def validate(document):
    """
    Determine whether the specified document is valid.
    :param document: The document to evaluate.
    :type document: Document
    :raises InvalidDocument: when invalid.
    """
    if document.version != VERSION:
        failed = InvalidVersion(document.dump(), VERSION, document.version)
        log.warn(utf8(failed))
        raise failed
コード例 #24
0
ファイル: model.py プロジェクト: darinlively/gofer
def validate(document):
    """
    Determine whether the specified document is valid.
    :param document: The document to evaluate.
    :type document: Document
    :raises DocumentError: when invalid.
    """
    if document.version != VERSION:
        error = VersionError(document, VERSION, document.version)
        log.warn(utf8(error))
        raise error
コード例 #25
0
ファイル: model.py プロジェクト: stbenjam/gofer
def validate(document):
    """
    Determine whether the specified document is valid.
    :param document: The document to evaluate.
    :type document: Document
    :raises DocumentError: when invalid.
    """
    if document.version != VERSION:
        error = VersionError(document, VERSION, document.version)
        log.warn(utf8(error))
        raise error
コード例 #26
0
 def __init__(self, policy, request):
     """
     :param policy: The policy object.
     :type policy: Policy
     :param request: A request to send.
     :type request: object
     """
     self._sn = utf8(uuid4())
     self._policy = policy
     self._request = request
     self._pending = True
コード例 #27
0
ファイル: policy.py プロジェクト: pombredanne/gofer
 def __init__(self, policy, request):
     """
     :param policy: The policy object.
     :type policy: Policy
     :param request: A request to send.
     :type request: object
     """
     self._sn = utf8(uuid4())
     self._policy = policy
     self._request = request
     self._pending = True
コード例 #28
0
 def _fn(thing, *args, **kwargs):
     repair = lambda: None
     while not Thread.aborted():
         try:
             repair()
             return fn(thing, *args, **kwargs)
         except _NotFound, e:
             raise NotFound(*e.args)
         except LinkError, le:
             log.error(utf8(le))
             repair = thing.repair
             sleep(DELAY)
コード例 #29
0
ファイル: reliability.py プロジェクト: darinlively/gofer
 def _fn(thing, *args, **kwargs):
     repair = lambda: None
     while not Thread.aborted():
         try:
             repair()
             return fn(thing, *args, **kwargs)
         except _NotFound, e:
             raise NotFound(*e.args)
         except LinkError, le:
             log.error(utf8(le))
             repair = thing.repair
             sleep(DELAY)
コード例 #30
0
ファイル: dispatcher.py プロジェクト: pombredanne/gofer
 def __call__(self):
     """
     Invoke the method.
     :return: The invocation result.
     :rtype: Return
     """
     try:
         self.permitted()
         retval = self.method(*self.args, **self.kwargs)
         return Return.succeed(retval)
     except Exception:
         log.exception(utf8(self.method))
         return Return.exception()
コード例 #31
0
 def __call__(self):
     """
     Invoke the method.
     :return: The invocation result.
     :rtype: Return
     """
     try:
         self.permitted()
         retval = self.method(*self.args, **self.kwargs)
         return Return.succeed(retval)
     except Exception:
         log.exception(utf8(self.method))
         return Return.exception()
コード例 #32
0
ファイル: main.py プロジェクト: pombreda/gofer
def setup_logging():
    """
    Set logging levels based on configuration.
    """
    cfg = AgentConfig()
    for name, level in cfg.logging:
        if not level:
            continue
        try:
            logger = logging.getLogger(name)
            level = getattr(logging, level.upper())
            logger.setLevel(level)
        except Exception, e:
            log.error(utf8(e))
コード例 #33
0
ファイル: main.py プロジェクト: stbenjam/gofer
def setup_logging():
    """
    Set logging levels based on configuration.
    """
    cfg = AgentConfig()
    for name, level in cfg.logging:
        if not level:
            continue
        try:
            logger = logging.getLogger(name)
            level = getattr(logging, level.upper())
            logger.setLevel(level)
        except Exception, e:
            log.error(utf8(e))
コード例 #34
0
ファイル: manager.py プロジェクト: darinlively/gofer
 def dispatch(self, call):
     """
     Dispatch the call to the handler.
     :param call: A *call* document.
     :type call: Document
     """
     reply = Document()
     try:
         method = getattr(self.handler, call.name)
         result = method(*call.args, **call.kwargs)
         reply.code = 0
         reply.result = result
     except Exception, e:
         reply.code = 1
         reply.result = utf8(e)
コード例 #35
0
ファイル: dispatcher.py プロジェクト: stbenjam/gofer
 def __call__(self):
     """
     Invoke the method.
     :return: The invocation result.
     :rtype: Return
     """
     try:
         self.permitted()
         fninfo = RMI.fninfo(self.method)
         model = ALL[fninfo.call.model](self.method, *self.args, **self.kwargs)
         retval = model()
         return Return.succeed(retval)
     except Exception:
         log.exception(utf8(self.method))
         return Return.exception()
コード例 #36
0
ファイル: manager.py プロジェクト: stbenjam/gofer
 def dispatch(self, call):
     """
     Dispatch the call to the handler.
     :param call: A *call* document.
     :type call: Document
     """
     reply = Document()
     try:
         method = getattr(self.handler, call.name)
         result = method(*call.args, **call.kwargs)
         reply.code = 0
         reply.result = result
     except Exception, e:
         reply.code = 1
         reply.result = utf8(e)
コード例 #37
0
ファイル: threadpool.py プロジェクト: darinlively/gofer
 def run(self):
     """
     Main run loop; processes input queue.
     """
     while not Thread.aborted():
         call = self.queue.get()
         if call == 1:
             # # busy
             continue
         if not call:
             # termination requested
             return
         try:
             call()
         except Exception:
             log.exception(utf8(call))
コード例 #38
0
ファイル: manager.py プロジェクト: stbenjam/gofer
 def accepted(self, client):
     """
     Process the request on the accepted socket.
     :param client: A client socket.
     :type client: socket.socket
     """
     try:
         client.setsockopt(IPPROTO_TCP, TCP_NODELAY, 1)
         client.setsockopt(SOL_SOCKET, SO_LINGER, struct.pack('ii', 1, 1))
         message = client.recv(4096)
         call = Document()
         call.load(message)
         reply = self.dispatch(call)
         client.send(reply)
     except Exception, e:
         log.error(utf8(e))
コード例 #39
0
ファイル: threadpool.py プロジェクト: stbenjam/gofer
 def run(self):
     """
     Main run loop; processes input queue.
     """
     while not Thread.aborted():
         call = self.queue.get()
         if call == 1:
             # # busy
             continue
         if not call:
             # termination requested
             return
         try:
             call()
         except Exception:
             log.exception(utf8(call))
コード例 #40
0
ファイル: manager.py プロジェクト: darinlively/gofer
 def accepted(self, client):
     """
     Process the request on the accepted socket.
     :param client: A client socket.
     :type client: socket.socket
     """
     try:
         client.setsockopt(IPPROTO_TCP, TCP_NODELAY, 1)
         client.setsockopt(SOL_SOCKET, SO_LINGER, struct.pack('ii', 1, 1))
         message = client.recv(4096)
         call = Document()
         call.load(message)
         reply = self.dispatch(call)
         client.send(reply)
     except Exception, e:
         log.error(utf8(e))
コード例 #41
0
ファイル: reporting.py プロジェクト: darinlively/gofer
def indent(string, indent, *args):
    """
    Indent the specified string and replace arguments.
    :param string: A string.
    :param string: basestring
    :param indent: The number of spaces to indent.
    :type indent: int
    :param args: List of arguments.
    :type args: list
    :return: The indented string.
    :rtype: str
    """
    s = []
    for n in range(0, indent):
        s.append(' ')
    s.append(utf8(string) % args)
    return ''.join(s)
コード例 #42
0
ファイル: connection.py プロジェクト: darinlively/gofer
 def receiver(self, address=None, dynamic=False):
     """
     Get a message receiver for the specified address.
     :param address: An AMQP address.
     :type address: str
     :param dynamic: Indicates link address is dynamically assigned.
     :type dynamic: bool
     :return: A receiver.
     :rtype: proton.utils.BlockingReceiver
     """
     options = None
     name = utf8(uuid4())
     if dynamic:
         # needed by dispatch router
         options = DynamicNodeProperties({'x-opt-qd.address': unicode(address)})
         address = None
     return self._impl.create_receiver(address, name=name, dynamic=dynamic, options=options)
コード例 #43
0
ファイル: builtin.py プロジェクト: pombreda/gofer
def indent(value, indent, *args):
    """
    Generate an indent.
    :param value: The value to indent.
    :type value: object
    :param indent: Number of spaces to indent.
    :type indent: int
    :param args: Replacement arguments.
    :type args: list
    :return: The indented value.
    :rtype: str
    """
    s = []
    for n in range(0, indent):
        s.append(' ')
    s.append(utf8(value) % args)
    return ''.join(s)
コード例 #44
0
ファイル: builtin.py プロジェクト: pombreda/gofer
def indent(value, indent, *args):
    """
    Generate an indent.
    :param value: The value to indent.
    :type value: object
    :param indent: Number of spaces to indent.
    :type indent: int
    :param args: Replacement arguments.
    :type args: list
    :return: The indented value.
    :rtype: str
    """
    s = []
    for n in range(0, indent):
        s.append(' ')
    s.append(utf8(value) % args)
    return ''.join(s)
コード例 #45
0
def indent(string, indent, *args):
    """
    Indent the specified string and replace arguments.
    :param string: A string.
    :param string: basestring
    :param indent: The number of spaces to indent.
    :type indent: int
    :param args: List of arguments.
    :type args: list
    :return: The indented string.
    :rtype: str
    """
    s = []
    for n in range(0, indent):
        s.append(' ')
    s.append(utf8(string) % args)
    return ''.join(s)
コード例 #46
0
ファイル: model.py プロジェクト: pombreda/gofer
 def __call__(self):
     """
     Invoke the method.
     :raise: Error on failure.
     """
     self.open()
     try:
         request = Message(content=self.content,
                           reply_to=self.reply_to,
                           properties=self.properties,
                           correlation_id=utf8(uuid4()),
                           subject=SUBJECT)
         self.sender.send(request)
         reply = self.receiver.fetch()
         self.session.acknowledge()
         self.on_reply(reply)
     finally:
         self.close()
コード例 #47
0
 def __call__(self):
     """
     Invoke the method.
     :raise: Error on failure.
     """
     self.open()
     try:
         reply_to = self.receiver.remote_source.address
         request = Message(body=self.body,
                           reply_to=reply_to,
                           properties=self.properties,
                           correlation_id=utf8(uuid4()),
                           subject=SUBJECT)
         self.send(request)
         reply = self.receiver.receive()
         self.on_reply(reply)
     finally:
         self.close()
コード例 #48
0
ファイル: model.py プロジェクト: pombredanne/gofer
 def __call__(self):
     """
     Invoke the method.
     :raise: Error on failure.
     """
     self.open()
     try:
         reply_to = self.receiver.remote_source.address
         request = Message(
             body=self.body,
             reply_to=reply_to,
             properties=self.properties,
             correlation_id=utf8(uuid4()),
             subject=SUBJECT)
         self.send(request)
         reply = self.receiver.receive()
         self.on_reply(reply)
     finally:
         self.close()
コード例 #49
0
ファイル: dispatcher.py プロジェクト: stbenjam/gofer
 def dispatch(self, document):
     """
     Dispatch the requested RMI.
     :param document: A request document.
     :type document: Document
     :return: The result.
     :rtype: any
     """
     try:
         self.log(document)
         auth = self.auth(document)
         request = Request(document.request)
         log.debug('request: %s', request)
         method = RMI(request, auth, self.catalog)
         log.debug('method: %s', method)
         return method()
     except Exception:
         log.exception(utf8(document))
         return Return.exception()
コード例 #50
0
ファイル: model.py プロジェクト: darinlively/gofer
 def __call__(self):
     """
     Invoke the method.
     :raise: Error on failure.
     """
     self.open()
     try:
         request = Message(
             content=self.content,
             reply_to=self.reply_to,
             properties=self.properties,
             correlation_id=utf8(uuid4()),
             subject=SUBJECT)
         self.sender.send(request)
         reply = self.receiver.fetch()
         self.session.acknowledge()
         self.on_reply(reply)
     finally:
         self.close()
コード例 #51
0
ファイル: model.py プロジェクト: stbenjam/gofer
 def send(self, address, ttl=None, **body):
     """
     Send a message.
     :param address: An AMQP address.
     :type address: str
     :param ttl: Time to Live (seconds)
     :type ttl: float
     :keyword body: document body.
     :return: The message serial number.
     :rtype: str
     :raise: ModelError
     """
     sn = utf8(uuid4())
     routing = (None, address)
     document = Document(sn=sn, version=VERSION, routing=routing)
     document += body
     unsigned = document.dump()
     signed = auth.sign(self.authenticator, unsigned)
     self._impl.send(address, signed, ttl)
     return sn
コード例 #52
0
ファイル: connection.py プロジェクト: stbenjam/gofer
 def open(self):
     """
     Open a connection to the broker.
     """
     if self.is_open():
         # already open
         return
     connector = Connector.find(self.url)
     host = ':'.join((connector.host, utf8(connector.port)))
     virtual_host = connector.virtual_host or VIRTUAL_HOST
     domain = self.ssl_domain(connector)
     userid = connector.userid or USERID
     password = connector.password or PASSWORD
     log.info('open: %s', connector)
     self._impl = RealConnection(host=host,
                                 virtual_host=virtual_host,
                                 ssl=domain,
                                 userid=userid,
                                 password=password,
                                 confirm_publish=True)
     log.info('opened: %s', self.url)