def start_service(addr, encoder, authenticator=None): """ Start a service with options """ s = Responder(addr, encoder=encoder, authenticator=authenticator, timeouts=(3000, 3000)) s.register('none', lambda: None) s.register('divide', lambda x, y: x / y) s.register('upper', lambda dct: {k: v.upper() for k, v in dct.items()}) s.start()
def run(self): self.sock_addr = 'ipc:///tmp/service.sock' self.tcp_addr = 'tcp://127.0.0.1:9443' s = Responder(self.tcp_addr, timeouts=(None, None)) s.register('echo', echo) s.register('node_cfg', get_node_cfg) s.register('offline', offline) s.register('wedged', wedged) s.start()
def main(): global CONF time.sleep(random.random()) logging.basicConfig(level=logging.DEBUG) conf_filepath = sys.argv[1] CONF = config.load(conf_filepath) service = Responder( 'ipc:///tmp/auth-example-service.sock', authenticator=Authenticator( CONF.authenticator['secret'], hashlib.sha256 ) ) service.register('generate_uuid', generate_uuid) service.start()
# A simple service for testing purposes from nanoservice import Responder def ping(): return 'pong' def add(x, y): return x + y addr = 'ipc:///tmp/math-test-service.sock' s = Responder(addr) s.register('ping', ping) s.register('add', add) print('Starting serice on address {}'.format(addr)) s.start()
# A simple service for testing purposes from nanoservice import Responder def ping(): return "pong" def add(x, y): return x + y addr = "ipc:///tmp/math-test-service.sock" s = Responder(addr) s.register("ping", ping) s.register("add", add) print("Starting serice on address {}".format(addr)) s.start()
def start_service(self, addr, authenticator=None): s = Responder(addr, authenticator=authenticator, timeouts=(3000, 3000)) s.register('divide', lambda x, y: x / y) s.start()