Exemplo n.º 1
0
class PricingServer(PricingBase, Server):

    def server_init(self):
        self.log = LogSinkClient(self.service_dir_client)
        self.userstore_client = UserStoreClient(self.service_dir_client)

    def price_request(self, requested_fib):
        return int(floor(logarithm(requested_fib,10))) + 1

    def pay_for_user_request(self, requested_fib, username):
        request_cost = self.price_request(requested_fib)
        credit = self.userstore_client.get_credit(username)
        if credit < request_cost:
            self.log.info(
                'User "%s" denied fib(%s), credit: %s' % (
                username,
                requested_fib,
                credit))
            return [
                False,
                "Error: fib(%s) costs %s, user %s has insufficient credit(%s)" % (
                requested_fib, request_cost, username, credit)]
        new_credit = self.userstore_client.increment_credit(
            username, -1 * request_cost)
        self.log.info("%s used %s credit, balance: %s" % (
            username, request_cost, new_credit))
        return [True, new_credit]
Exemplo n.º 2
0
class PricingServer(PricingBase, Server):
    def server_init(self):
        self.log = LogSinkClient(self.service_dir_client)
        self.userstore_client = UserStoreClient(self.service_dir_client)

    def price_request(self, requested_fib):
        return int(floor(logarithm(requested_fib, 10))) + 1

    def pay_for_user_request(self, requested_fib, username):
        request_cost = self.price_request(requested_fib)
        credit = self.userstore_client.get_credit(username)
        if credit < request_cost:
            self.log.info('User "%s" denied fib(%s), credit: %s' %
                          (username, requested_fib, credit))
            return [
                False,
                "Error: fib(%s) costs %s, user %s has insufficient credit(%s)"
                % (requested_fib, request_cost, username, credit)
            ]
        new_credit = self.userstore_client.increment_credit(
            username, -1 * request_cost)
        self.log.info("%s used %s credit, balance: %s" %
                      (username, request_cost, new_credit))
        return [True, new_credit]
Exemplo n.º 3
0
 def server_init(self):
     self.log = LogSinkClient(self.service_dir_client)
     self.userstore_client = UserStoreClient(self.service_dir_client)
Exemplo n.º 4
0
 def server_init(self):
     self.log = LogSinkClient(self.service_dir_client)
     self.userstore_client = UserStoreClient(self.service_dir_client)
Exemplo n.º 5
0
 def server_init(self):
     self.log = LogSinkClient(self.service_dir_client)
     self.userstore_client = UserStoreClient(self.service_dir_client)
     self.controller_client = GenericClient(self.service_dir_client, name="controller")
     self.basic_auth = HTTPBasic(self.wsgi_app_post_auth, self.userstore_client) 
Exemplo n.º 6
0
from wsgi_intercept import requests_intercept, add_wsgi_intercept
from wsgi_proxy import WSGIProxyApplication
from fibpro.userstore import UserStoreServer, UserStoreClient

from fibpro.reqtool.record import RecordingProxy


def intercept(host, port, app):
    add_wsgi_intercept(host, port, lambda: app)


requests_intercept.install()
proxy = RecordingProxy(UserStoreServer(register=False).app())
#proxy = RecordingProxy(WSGIProxyApplication())
intercept('127.0.0.1', 9003, proxy)
UserStoreClient().get_user("username")
print proxy.session[0][0].__dict__
print proxy.session[0][1].__dict__