Esempio n. 1
0
    def request(self, request):
        #
        # First time here
        if not request.cache.x_runtime:
            loop = get_event_loop()
            request.cache.x_count = 0
            request.cache.x_runtime = loop.time()
            request.response['X-Request-ID'] = generate_secret(32, xchars)
        else:
            request.cache.x_count += 1
            return

        app = request.app

        # listen for all events on applications model
        channels = app.channels
        channels.register(
            app.config['CHANNEL_DATAMODEL'], 'applications.*', reload_app(app)
        )

        # Get the root application
        root = get_application(app, id=app.config['MASTER_APPLICATION_ID'])
        # The root domain is not specified - cannot use multiapp
        if not root.domain:
            return

        host = request.get_host().split(':', 1)[0]
        multi = root.domain.split('.')
        bits = host.split('.')

        try:
            if len(bits) == 3 and bits[-2:] == multi[-2:]:
                name = bits[0]
                if name == 'api':
                    return
                app_domain = get_application(app, name=name)
            else:
                app_domain = get_application(app, domain=host)
        except Http404:
            return

        return app_domain.request(request, self.api_url(request, multi))
Esempio n. 2
0
    def request(self, request):
        #
        # First time here
        if not request.cache.x_runtime:
            loop = get_event_loop()
            request.cache.x_count = 0
            request.cache.x_runtime = loop.time()
            request.response['X-Request-ID'] = generate_secret(32, xchars)
        else:
            request.cache.x_count += 1
            return

        app = request.app

        # listen for all events on applications model
        channels = app.channels
        channels.register(app.config['CHANNEL_DATAMODEL'], 'applications.*',
                          reload_app(app))

        # Get the root application
        root = get_application(app, id=app.config['MASTER_APPLICATION_ID'])
        # The root domain is not specified - cannot use multiapp
        if not root.domain:
            return

        host = request.get_host().split(':', 1)[0]
        multi = root.domain.split('.')
        bits = host.split('.')

        try:
            if len(bits) == 3 and bits[-2:] == multi[-2:]:
                name = bits[0]
                if name == 'api':
                    return
                app_domain = get_application(app, name=name)
            else:
                app_domain = get_application(app, domain=host)
        except Http404:
            return

        return app_domain.request(request, self.api_url(request, multi))
Esempio n. 3
0
 def run(self, options, **params):
     key = generate_secret(options.length, hexadecimal=options.hex)
     self.write('Secret key:')
     self.write(key)
     self.write('-----------------------------------------------------')
     return key
Esempio n. 4
0
 def run(self, options, **params):
     return generate_secret(options.length, hexadecimal=options.hex)
Esempio n. 5
0
 def run(self, options, **params):
     key = generate_secret(options.length, hexadecimal=options.hex)
     self.write('Secret key:')
     self.write(key)
     self.write('-----------------------------------------------------')
     return key
Esempio n. 6
0
 def regenerate_token(self, request, instance, session=None):
     app_domain = self.instance(instance).obj
     with self.session(request, session=session) as session:
         app_domain.secret = generate_secret(64)
         session.add(app_domain)
     return app_domain.secret
Esempio n. 7
0
 def create_instance(self):
     model = self.db_model()
     token = generate_secret(64)
     return model(id=create_uuid(), secret=token)
Esempio n. 8
0
 def regenerate_token(self, request, instance, session=None):
     app_domain = self.instance(instance).obj
     with self.session(request, session=session) as session:
         app_domain.secret = generate_secret(64)
         session.add(app_domain)
     return app_domain.secret
Esempio n. 9
0
 def create_instance(self):
     model = self.db_model()
     token = generate_secret(64)
     return model(id=create_uuid(), secret=token)