예제 #1
0
파일: launch.py 프로젝트: Mrkebubun/sputnik
(options, args) = parser.parse_args()

if options.filename:
    # noinspection PyUnresolvedReferences
    config.reconfigure(options.filename)

from twisted.internet.defer import inlineCallbacks, returnValue
from autobahn.wamp import types
from sputnik.webserver.router.twisted.wamp import RouterSession, Router
from autobahn.wamp.exception import ApplicationError
from sputnik.exception import *

from sputnik import observatory
from sputnik import plugin

debug, log, warn, error, critical = observatory.get_loggers("router")

class SputnikRouter(Router):
    @inlineCallbacks
    def authorize(self, session, uri, action):
        results = []
        for plugin in self.factory.authz_plugins:
            result = yield plugin.authorize(self, session, uri, action)
            if result == None:
                continue
            results.append(result)

        # Require no False and at least one True.
        returnValue(all(results) and results)

    def validate(self, type, uri, args, kwargs):
예제 #2
0
#
# Copyright 2014 Mimetic Markets, Inc.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#

from sputnik import observatory

debug, log, warn, error, critical = observatory.get_loggers("authn_wampcra")

from sputnik.webserver.plugin import AuthenticationPlugin
from twisted.internet.defer import inlineCallbacks, returnValue
from twisted.internet import threads
from autobahn import util
from autobahn.wamp import types, auth

import hashlib
import json

class WAMPCRALogin(AuthenticationPlugin):
    def __init__(self):
        AuthenticationPlugin.__init__(self)

    @inlineCallbacks
    def onHello(self, router_session, realm, details):
        for authmethod in details.authmethods:
            if authmethod == u"wampcra":
                debug("Attemping wampcra login for %s..." % details.authid)
                # Create and store a one time challenge.
예제 #3
0
파일: alerts.py 프로젝트: Mrkebubun/sputnik
#
# Copyright 2014 Mimetic Markets, Inc.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#

from sputnik import config
from sputnik import observatory

debug, log, warn, error, critical = observatory.get_loggers("alerts_proxy")

from sputnik.webserver.plugin import BackendPlugin
from sputnik.alerts import AlertsProxy as ap

class AlertsProxy(BackendPlugin):
    def __init__(self):
        BackendPlugin.__init__(self)
        self.proxy = ap(config.get("alerts", "export"))


예제 #4
0
#
# Copyright 2014 Mimetic Markets, Inc.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#

from sputnik import config
from sputnik import observatory

debug, log, warn, error, critical = observatory.get_loggers("accountant_proxy")

from sputnik.webserver.plugin import BackendPlugin
from sputnik.accountant import accountant


class AccountantProxy(BackendPlugin):
    def __init__(self):
        BackendPlugin.__init__(self)
        self.proxy = accountant.AccountantProxy(
            "dealer", config.get("accountant", "webserver_export"),
            config.getint("accountant", "webserver_export_base_port"))
예제 #5
0
#
# Copyright 2014 Mimetic Markets, Inc.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#

from sputnik import config
from sputnik import observatory
from sputnik import util

debug, log, warn, error, critical = observatory.get_loggers("rpc_market")

from sputnik.plugin import PluginException
from sputnik.webserver.plugin import ServicePlugin, schema, error_handler
from sputnik.exception import WebserverException
from datetime import datetime

from twisted.internet.defer import inlineCallbacks, returnValue, succeed
from autobahn import wamp


class MarketService(ServicePlugin):
    def __init__(self):
        ServicePlugin.__init__(self)
        self.markets = {}
        self.books = {}
        self.trade_history = {}
        self.ohlcv_history = {}
        self.safe_prices = {}
예제 #6
0
파일: plugin.py 프로젝트: treverson/sputnik
#
# Copyright 2014 Mimetic Markets, Inc.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
from sputnik.plugin import Plugin
from autobahn.twisted.wamp import ApplicationSession
from twisted.internet.defer import inlineCallbacks, returnValue, maybeDeferred
from sputnik import observatory, rpc_schema

debug, log, warn, error, critical = observatory.get_loggers("plugin")

from autobahn import wamp
from autobahn.wamp.types import RegisterOptions

from jsonschema import ValidationError
from sputnik.exception import *

def error_handler(func):
    @inlineCallbacks
    def wrapped_f(*args, **kwargs):
        try:
            result = yield maybeDeferred(func, *args, **kwargs)
            returnValue({'success': True, 'result': result})
        except SputnikException as e:
            error("SputnikException received: %s" % str(e.args))
            returnValue({'success': False, 'error': e.args})
        except Exception as e:
            error("UNHANDLED EXCEPTION: %s" % str(e.args))
예제 #7
0
#
# Copyright 2014 Mimetic Markets, Inc.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#

from sputnik import config
from sputnik import observatory

debug, log, warn, error, critical = observatory.get_loggers("cashier_proxy")

from sputnik.webserver.plugin import BackendPlugin
from sputnik.zmq_util import dealer_proxy_async

class CashierProxy(BackendPlugin):
    def __init__(self):
        BackendPlugin.__init__(self)
        self.proxy = dealer_proxy_async(
                config.get("cashier", "webserver_export"))

예제 #8
0
파일: totp.py 프로젝트: Mrkebubun/sputnik
#
# Copyright 2014 Mimetic Markets, Inc.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#

from sputnik import observatory

debug, log, warn, error, critical = observatory.get_loggers("auth_totp")

from sputnik.webserver.plugin import AuthenticationPlugin
from twisted.internet.defer import inlineCallbacks, returnValue
from autobahn import util
from autobahn.wamp import types, auth

class TOTPVerification(AuthenticationPlugin):
    def __init__(self):
        AuthenticationPlugin.__init__(self)

    def init(self):
        self.administrator = self.require("sputnik.webserver.plugins.backend.administrator.AdministratorProxy")

    @inlineCallbacks
    def onHello(self, router_session, realm, details):
        for authmethod in details.authmethods:
            # only run TOTP for wampcra
            if authmethod == u"wampcra":
                log("Checking for TOTP for username %s..." % details.authid)
                # We can accept unicode usernames, but convert them before
예제 #9
0
파일: mem.py 프로젝트: ysobolev/sputnik
#
# Copyright 2014 Mimetic Markets, Inc.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#

from sputnik import observatory

debug, log, warn, error, critical = observatory.get_loggers("db_mem")

from sputnik.webserver.plugin import DatabasePlugin
from autobahn.wamp import types


class InMemoryDatabase(DatabasePlugin):
    def __init__(self):
        DatabasePlugin.__init__(self)
        self.users = {}

    def add_user(self, username, line):
        debug("Adding user %s..." % username)
        if username in self.users:
            warn("User %s already exists." % username)
        self.users[username] = line

    def remove_user(self, username):
        debug("Removing user %s..." % username)
        if username in self.users:
            del self.users[username]
예제 #10
0
파일: user.py 프로젝트: Mrkebubun/sputnik
#
# Copyright 2014 Mimetic Markets, Inc.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#

from sputnik import config
from sputnik import observatory
from sputnik import util

debug, log, warn, error, critical = observatory.get_loggers("feeds_user")

from sputnik.plugin import PluginException
from sputnik.webserver.plugin import ServicePlugin
from datetime import datetime
from sputnik import util

from twisted.internet.defer import inlineCallbacks, returnValue, gatherResults
from autobahn import wamp

class UserAnnouncer(ServicePlugin):
    def on_fill(self, username, fill):
        username = util.encode_username(username)
        self.publish(u"feeds.user.fills.%s" % username, fill)

    def on_transaction(self, username, transaction):
        username = util.encode_username(username)
        self.publish(u"feeds.user.transactions.%s" % username, transaction)
예제 #11
0
파일: engine.py 프로젝트: Mrkebubun/sputnik
#
# Copyright 2014 Mimetic Markets, Inc.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#

from sputnik import config
from sputnik import observatory

debug, log, warn, error, critical = observatory.get_loggers("engine")

from sputnik.webserver.plugin import ReceiverPlugin
from sputnik.zmq_util import export, pull_share_async

class EngineReceiver(ReceiverPlugin):
    def __init__(self):
        ReceiverPlugin.__init__(self)

    @export
    def book(self, ticker, book):
        log("Got 'book' for %s / %s" % (ticker, book))
        self.emit("book", ticker, book)

    @export
    def safe_prices(self, ticker, price):
        log("Got safe price for %s: %s" % (ticker, price))
        self.emit("safe_prices", ticker, price)

    def init(self):
예제 #12
0
#
# Copyright 2014 Mimetic Markets, Inc.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#

from sputnik import config
from sputnik import observatory

debug, log, warn, error, critical = observatory.get_loggers("db_postgres")

from sputnik.webserver.plugin import DatabasePlugin
from autobahn.wamp import types
from twisted.internet.defer import inlineCallbacks, returnValue
from twisted.enterprise import adbapi
from sputnik import util
import markdown
import datetime
import collections
from psycopg2 import OperationalError
from twisted.internet.defer import inlineCallbacks, returnValue
from sputnik.exception import *


class MyConnectionPool():
    def __init__(self, *args, **kwargs):
        self.args = args
        self.kwargs = kwargs
        self.pool = adbapi.ConnectionPool(*args, **kwargs)
예제 #13
0
파일: mem.py 프로젝트: Mrkebubun/sputnik
#
# Copyright 2014 Mimetic Markets, Inc.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#

from sputnik import observatory

debug, log, warn, error, critical = observatory.get_loggers("db_mem")

from sputnik.webserver.plugin import DatabasePlugin
from autobahn.wamp import types

class InMemoryDatabase(DatabasePlugin):
    def __init__(self):
        DatabasePlugin.__init__(self)
        self.users = {}

    def add_user(self, username, line):
        debug("Adding user %s..." % username)
        if username in self.users:
            warn("User %s already exists." % username)
        self.users[username] = line

    def remove_user(self, username):
        debug("Removing user %s..." % username)
        if username in self.users:
            del self.users[username]
        else:
예제 #14
0
#
# Copyright 2014 Mimetic Markets, Inc.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#

from sputnik import config
from sputnik import observatory

debug, log, warn, error, critical = observatory.get_loggers("private")

from sputnik.plugin import PluginException
from sputnik.webserver.plugin import ServicePlugin, schema, authenticated, error_handler
from sputnik.exception import WebserverException

from twisted.internet.defer import inlineCallbacks, returnValue, succeed
from autobahn import wamp
from autobahn.wamp.types import RegisterOptions


class PrivateService(ServicePlugin):
    def __init__(self):
        ServicePlugin.__init__(self)

    @wamp.register(u"rpc.private.foobar")
    @error_handler
    @authenticated
    @schema("public/private.json#foobar")
    def foobar(self, x, username=None):
예제 #15
0
#
# Copyright 2014 Mimetic Markets, Inc.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#

from sputnik import config
from sputnik import observatory
from sputnik import util

debug, log, warn, error, critical = observatory.get_loggers("feeds_user")

from sputnik.plugin import PluginException
from sputnik.webserver.plugin import ServicePlugin
from datetime import datetime
from sputnik import util

from twisted.internet.defer import inlineCallbacks, returnValue, gatherResults
from autobahn import wamp


class UserAnnouncer(ServicePlugin):
    def on_fill(self, username, fill):
        username = util.encode_username(username)
        self.publish(u"feeds.user.fills.%s" % username, fill)

    def on_transaction(self, username, transaction):
        username = util.encode_username(username)
        self.publish(u"feeds.user.transactions.%s" % username, transaction)
예제 #16
0
#
# Copyright 2014 Mimetic Markets, Inc.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#

from sputnik import config
from sputnik import observatory

debug, log, warn, error, critical = observatory.get_loggers("private")

from sputnik.plugin import PluginException
from sputnik.webserver.plugin import ServicePlugin, schema, authenticated, error_handler
from sputnik.exception import WebserverException

from twisted.internet.defer import inlineCallbacks, returnValue, succeed
from autobahn import wamp
from autobahn.wamp.types import RegisterOptions


class PrivateService(ServicePlugin):
    def __init__(self):
        ServicePlugin.__init__(self)

    @wamp.register(u"rpc.private.foobar")
    @error_handler
    @authenticated
    @schema("public/private.json#foobar")
    def foobar(self, x, username=None):
예제 #17
0
#
# Copyright 2014 Mimetic Markets, Inc.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#

from sputnik import config
from sputnik import observatory

debug, log, warn, error, critical = observatory.get_loggers("rpc_registrar")

from sputnik.plugin import PluginException
from sputnik.webserver.plugin import ServicePlugin, schema, error_handler
from sputnik.exception import WebserverException

from twisted.internet.defer import inlineCallbacks, returnValue
from autobahn import wamp

class RegistrarService(ServicePlugin):
    def __init__(self):
        ServicePlugin.__init__(self)

    def init(self):
        self.administrator = self.require("sputnik.webserver.plugins.backend.administrator.AdministratorProxy")
    
    @wamp.register(u"rpc.registrar.make_account")
    @error_handler
    @schema("public/registrar.json#make_account", drop_args=[])
    def make_account(self, username, password, email, nickname, locale=None):
예제 #18
0
파일: basic.py 프로젝트: Mrkebubun/sputnik
#
# Copyright 2014 Mimetic Markets, Inc.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#

from sputnik import observatory

debug, log, warn, error, critical = observatory.get_loggers("permissions")

from sputnik.webserver.plugin import AuthorizationPlugin
from autobahn.wamp import types
from autobahn.wamp.interfaces import IRouter

class BasicPermissions(AuthorizationPlugin):
    def __init__(self):
        AuthorizationPlugin.__init__(self)

    def authorize(self, router, session, uri, action):
        log("Authorizing %s(%s) to %s %s" % \
                (session._authid, session._authrole, \
                 IRouter.ACTION_TO_STRING[action], uri))
        
        return True

예제 #19
0
파일: ip.py 프로젝트: ysobolev/sputnik
#
# Copyright 2014 Mimetic Markets, Inc.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#

from sputnik import observatory

debug, log, warn, error, critical = observatory.get_loggers("authn_ip")

from sputnik.webserver.plugin import AuthenticationPlugin
from twisted.internet.defer import inlineCallbacks, returnValue
from twisted.internet import threads
from autobahn import util
from autobahn.wamp import types, auth

import hashlib
import json


class IPFilter(AuthenticationPlugin):
    def __init__(self):
        AuthenticationPlugin.__init__(self)

    def onHello(self, router_session, realm, details):
        ip = router_session._transport.peer
        headers = router_session._transport.http_headers
        if "x-forwarded-for" in headers:
            ip += " (but really: %s)" % str(headers["x-forwarded-for"])
예제 #20
0
#
# Copyright 2014 Mimetic Markets, Inc.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#

from sputnik import observatory

debug, log, warn, error, critical = observatory.get_loggers("authn_anonymous")

from sputnik.webserver.plugin import AuthenticationPlugin
from autobahn.wamp import types

class AnonymousLogin(AuthenticationPlugin):
    def __init__(self):
        AuthenticationPlugin.__init__(self)

    def onHello(self, router_session, realm, details):
        for authmethod in details.authmethods:
            if authmethod == u"anonymous":
                log("Successful anonymous login (ID: %s)." % \
                        details.pending_session)
                return types.Accept(authid=u"anonymous",
                                    authrole=u"anonymous",
                                    authmethod=u"anonymous",
                                    authprovider=u"anonymous")

예제 #21
0
#
# Copyright 2014 Mimetic Markets, Inc.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#

from sputnik import config
from sputnik import observatory

debug, log, warn, error, critical = observatory.get_loggers("alerts_proxy")

from sputnik.webserver.plugin import BackendPlugin
from sputnik.alerts import AlertsProxy as ap


class AlertsProxy(BackendPlugin):
    def __init__(self):
        BackendPlugin.__init__(self)
        self.proxy = ap(config.get("alerts", "export"))
예제 #22
0
#
# Copyright 2014 Mimetic Markets, Inc.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#

from sputnik import config
from sputnik import observatory

debug, log, warn, error, critical = observatory.get_loggers("cashier_proxy")

from sputnik.webserver.plugin import BackendPlugin
from sputnik.rpc.zmq_util import dealer_proxy_async


class CashierProxy(BackendPlugin):
    def __init__(self):
        BackendPlugin.__init__(self)
        self.proxy = dealer_proxy_async(
            config.get("cashier", "webserver_export"))
예제 #23
0
파일: plugin.py 프로젝트: ysobolev/sputnik
#
# Copyright 2014 Mimetic Markets, Inc.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
from sputnik.plugin import Plugin
from autobahn.twisted.wamp import ApplicationSession
from twisted.internet.defer import inlineCallbacks, returnValue, maybeDeferred
from sputnik import observatory
from sputnik.rpc import rpc_schema

debug, log, warn, error, critical = observatory.get_loggers("plugin")

from autobahn import wamp
from autobahn.wamp.types import RegisterOptions

from jsonschema import ValidationError
from sputnik.exception import *

def error_handler(func):
    @inlineCallbacks
    def wrapped_f(*args, **kwargs):
        try:
            result = yield maybeDeferred(func, *args, **kwargs)
            returnValue({'success': True, 'result': result})
        except SputnikException as e:
            error("SputnikException received: %s" % str(e.args))
            returnValue({'success': False, 'error': e.args})
        except Exception as e:
예제 #24
0
파일: market.py 프로젝트: treverson/sputnik
#
# Copyright 2014 Mimetic Markets, Inc.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#

from sputnik import config
from sputnik import observatory
from sputnik import util

debug, log, warn, error, critical = observatory.get_loggers("rpc_market")

from sputnik.plugin import PluginException
from sputnik.webserver.plugin import ServicePlugin, schema, error_handler
from sputnik.exception import WebserverException
from datetime import datetime

from twisted.internet.defer import inlineCallbacks, returnValue, succeed
from autobahn import wamp


class MarketService(ServicePlugin):
    def __init__(self):
        ServicePlugin.__init__(self)
        self.markets = {}
        self.books = {}
        self.trade_history = {}
        self.ohlcv_history = {}
        self.safe_prices = {}
예제 #25
0
#
# Copyright 2014 Mimetic Markets, Inc.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#

from sputnik import config
from sputnik import observatory

debug, log, warn, error, critical = observatory.get_loggers("db_postgres")

from sputnik.webserver.plugin import DatabasePlugin
from autobahn.wamp import types
from twisted.internet.defer import inlineCallbacks, returnValue
from twisted.enterprise import adbapi
from sputnik.util import conversions as util
import markdown
import datetime
import collections
from psycopg2 import OperationalError
from twisted.internet.defer import inlineCallbacks, returnValue
from sputnik.exception import *

class MyConnectionPool():
    def __init__(self, *args, **kwargs):
        self.args = args
        self.kwargs = kwargs
        self.pool = adbapi.ConnectionPool(*args, **kwargs)
예제 #26
0
#
# Copyright 2014 Mimetic Markets, Inc.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#

from sputnik import observatory

debug, log, warn, error, critical = observatory.get_loggers("permissions")

from sputnik.webserver.plugin import AuthorizationPlugin
from autobahn.wamp import types
from sputnik.webserver.router.wamp.interfaces import IRouter
import re
from sputnik import util


class DefaultPermissions(AuthorizationPlugin):
    def __init__(self):
        AuthorizationPlugin.__init__(self)

    def authorize(self, router, session, uri, action):
        debug("Checking permissions for %s(%s) to %s %s" % \
              (session._authid, session._authrole, \
               IRouter.ACTION_TO_STRING[action], uri))

        # allow trusted roles to do everything
        if session._authrole == u"trusted":
            log("Authorizing %s(%s) to %s %s" % \
예제 #27
0
파일: launch.py 프로젝트: ysobolev/sputnik
(options, args) = parser.parse_args()

if options.filename:
    # noinspection PyUnresolvedReferences
    config.reconfigure(options.filename)

from twisted.internet.defer import inlineCallbacks, returnValue
from autobahn.wamp import types
from sputnik.webserver.router.twisted.wamp import RouterSession, Router
from autobahn.wamp.exception import ApplicationError
from sputnik.exception import *

from sputnik import observatory
from sputnik import plugin

debug, log, warn, error, critical = observatory.get_loggers("router")


class SputnikRouter(Router):
    @inlineCallbacks
    def authorize(self, session, uri, action):
        results = []
        for plugin in self.factory.authz_plugins:
            result = yield plugin.authorize(self, session, uri, action)
            if result == None:
                continue
            results.append(result)

        # Require no False and at least one True.
        returnValue(all(results) and results)
예제 #28
0
#
# Copyright 2014 Mimetic Markets, Inc.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#

from sputnik import config
from sputnik import observatory

debug, log, warn, error, critical = observatory.get_loggers("rpc_token")

from sputnik.plugin import PluginException
from sputnik.webserver.plugin import ServicePlugin, authenticated, schema, error_handler
from sputnik.exception import WebserverException

from twisted.internet.defer import inlineCallbacks, returnValue, succeed
from autobahn import wamp
from autobahn.wamp.types import RegisterOptions
from datetime import datetime, timedelta
from sputnik.util import conversions as util


class TokenService(ServicePlugin):
    def __init__(self):
        ServicePlugin.__init__(self)

    def init(self):
        self.administrator = self.require(
            "sputnik.webserver.plugins.backend.administrator.AdministratorProxy"
예제 #29
0
#
# Copyright 2014 Mimetic Markets, Inc.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#

__author__ = 'sameer'

from sputnik import config
from sputnik import observatory

debug, log, warn, error, critical = observatory.get_loggers("administrator")

from sputnik.webserver.plugin import ReceiverPlugin
from sputnik.zmq_util import export, router_share_async

class AdministratorReceiver(ReceiverPlugin):
    def __init__(self):
        ReceiverPlugin.__init__(self)

    @export
    def reload_contract(self, ticker):
        self.market.load_contract(ticker)

    def init(self):
        self.market = self.require("sputnik.webserver.plugins.rpc.market.MarketService")
        self.share = router_share_async(self,
                config.get("webserver", "administrator_export"))
예제 #30
0
파일: cookie.py 프로젝트: Mrkebubun/sputnik
#
# Copyright 2014 Mimetic Markets, Inc.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#

from sputnik import observatory

debug, log, warn, error, critical = observatory.get_loggers("authn_cookie")

from sputnik.webserver.plugin import AuthenticationPlugin
from autobahn import util
from autobahn.wamp import types
from twisted.internet.defer import inlineCallbacks, returnValue
import json
import hashlib

class CookieLogin(AuthenticationPlugin):
    def __init__(self):
        AuthenticationPlugin.__init__(self)
        self.cookies = {}

    def new_cookie(self, username):
        self.cookies[username] = util.newid()
        return self.cookies[username]

    def set_cookie(self, username, cookie):
        self.cookies[username] = cookie
예제 #31
0
파일: token.py 프로젝트: ysobolev/sputnik
#
# Copyright 2014 Mimetic Markets, Inc.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#

from sputnik import config
from sputnik import observatory

debug, log, warn, error, critical = observatory.get_loggers("rpc_token")

from sputnik.plugin import PluginException
from sputnik.webserver.plugin import ServicePlugin, authenticated, schema, error_handler
from sputnik.exception import WebserverException

from twisted.internet.defer import inlineCallbacks, returnValue, succeed
from autobahn import wamp
from autobahn.wamp.types import RegisterOptions
from datetime import datetime, timedelta
from sputnik.util import conversions as util

class TokenService(ServicePlugin):
    def __init__(self):
        ServicePlugin.__init__(self)

    def init(self):
        self.administrator = self.require("sputnik.webserver.plugins.backend.administrator.AdministratorProxy")
        self.cookie_jar = self.require("sputnik.webserver.plugins.authn.cookie.CookieLogin")
    
예제 #32
0
#
# Copyright 2014 Mimetic Markets, Inc.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#

from sputnik import config
from sputnik import observatory

debug, log, warn, error, critical = observatory.get_loggers("accountant")

from sputnik.webserver.plugin import ReceiverPlugin
from sputnik.zmq_util import export, pull_share_async

class AccountantReceiver(ReceiverPlugin):
    def __init__(self):
        ReceiverPlugin.__init__(self)

    @export
    def fill(self, username, fill):
        log("Got 'fill' for %s / %s" % (username, fill))
        self.emit("fill", username, fill)

    @export
    def transaction(self, username, transaction):
        log("Got transaction for %s: %s" % (username, transaction))
        self.emit("transaction", username, transaction)

    @export
예제 #33
0
파일: engine.py 프로젝트: ysobolev/sputnik
#
# Copyright 2014 Mimetic Markets, Inc.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#

from sputnik import config
from sputnik import observatory

debug, log, warn, error, critical = observatory.get_loggers("engine")

from sputnik.webserver.plugin import ReceiverPlugin
from sputnik.rpc.zmq_util import export, pull_share_async


class EngineReceiver(ReceiverPlugin):
    def __init__(self):
        ReceiverPlugin.__init__(self)

    @export
    def book(self, ticker, book):
        log("Got 'book' for %s / %s" % (ticker, book))
        self.emit("book", ticker, book)

    @export
    def safe_prices(self, ticker, price):
        log("Got safe price for %s: %s" % (ticker, price))
        self.emit("safe_prices", ticker, price)
예제 #34
0
#
# Copyright 2014 Mimetic Markets, Inc.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#

from sputnik import config
from sputnik import observatory

debug, log, warn, error, critical = observatory.get_loggers("rpc_registrar")

from sputnik.plugin import PluginException
from sputnik.webserver.plugin import ServicePlugin, schema, error_handler
from sputnik.exception import WebserverException

from twisted.internet.defer import inlineCallbacks, returnValue
from autobahn import wamp


class RegistrarService(ServicePlugin):
    def __init__(self):
        ServicePlugin.__init__(self)

    def init(self):
        self.administrator = self.require(
            "sputnik.webserver.plugins.backend.administrator.AdministratorProxy"
        )

    @wamp.register(u"rpc.registrar.make_account")