Example #1
0
    def __init__(self, env, project):
        self.env = env
        self.proxy_app = Proxy('http://localhost:%s/' % env.c.port)

        # import here to avoid circular dependencies.
        from synthesepy import web
        self.web_app = web.get_application(project=project)

        self.static_apps = []
        for base, path in env.c.static_paths:
            self.static_apps.append((base, static.Cling(path)))
Example #2
0
    def __call__(self, environ, start_response):
        path_info = environ.get('PATH_INFO', '')
        basename, response = path_info.rsplit('.', 1)

        if response in self.responses:
            dataset = open_url(urljoin(self.url, basename))
            app = SimpleHandler(dataset)
        else:
            app = Proxy(urljoin(self.url, path_info))

        return app(environ, start_response)
Example #3
0
def main():
    options, args = parser.parse_args()
    if not args or len(args) > 1:
        parser.error('You must give one PROXY_URL')
    proxy_url = args[0]
    app = JumbleMiddleware(
        LinkRewriterMiddleware(Proxy(proxy_url), proxy_url))
    if getattr(options, 'debug', False):
        app = EvalException(app)
    app = validator(app)
    from paste.httpserver import serve
    serve(app, host=options.host, port=int(options.port))
Example #4
0
    def _wsgi_get(self, path_info, **kwargs):
        if path_info.startswith('/'):
            if 'app' in kwargs:
                app = kwargs.pop('app')
            elif self.app is not no_default:
                app = self.app
            else:
                raise ValueError('There is no app available')
        else:
            if Proxy is not no_default:
                app = Proxy(path_info)
                path_info = '/'
            else:
                raise ImportError('Paste is not installed')

        if 'environ' in kwargs:
            environ = kwargs.pop('environ').copy()
        else:
            environ = {}
        if path_info:
            kwargs['PATH_INFO'] = path_info
        environ.update(kwargs)

        # unsuported (came from Deliverance)
        for key in [
                'HTTP_ACCEPT_ENCODING', 'HTTP_IF_MATCH',
                'HTTP_IF_UNMODIFIED_SINCE', 'HTTP_RANGE', 'HTTP_IF_RANGE'
        ]:
            if key in environ:
                del environ[key]

        req = Request(environ)
        resp = req.get_response(app)
        status = resp.status.split()
        ctype = resp.content_type.split(';')[0]
        if status[0] not in '45' and ctype == 'text/html':
            body = resp.body
        else:
            body = []
        result = self.__class__(
            body,
            parent=self._parent,
            app=self.app,  # always return self.app
            response=resp)
        return result
Example #5
0
    def __call__(self, environ, start_response):
        req = Request(environ)
        if '.' in req.path_info:
            basename, response = req.path_info.rsplit('.', 1)
        else:
            basename, response = req.path_info, None

        # cache a local copy
        if response in self.responses:
            url = urljoin(self.url, basename)
            dataset = open_url(url)
            cachepath = os.path.join(self.cachedir, basename.replace('/', '_'))

            # here we an use mstat to check the mtime of the file, and 
            # do a HEAD on the dataset to compare with Last-Modified header
            r = requests.head(url + '.dods')
            if 'last-modified' in r.headers:
                last_modified = time.mktime(parsedate(r.headers['last-modified']))
                mtime = time.mktime(time.localtime( os.stat(cachepath)[ST_MTIME] ))
                if last_modified > mtime:
                    os.unlink(cachepath)

            # replace data with a caching version
            for var in walk(dataset, BaseType):
                var.data = CachingArrayProxy(
                        cachepath, self.tilesize, self.maxsize,
                        var.type, var.id,
                        var.data.url, var.data.shape, var.data._slice)
            #for var in walk(dataset, SequenceType):
            #    var.data = CachingSequenceProxy(
            #            cachepath,
            #            var.id,
            #            var.data.url, var.data.slice, var.data._slice, var.data.children)

            app = SimpleHandler(dataset)
        # pass this upstream
        else:
            app = Proxy(self.url)

        return app(environ, start_response)
Example #6
0
#!/usr/bin/env python3

import sys
import requests
from paste.proxy import Proxy
from werkzeug.contrib.fixers import ProxyFix
import flask

upstream = Proxy('http://127.0.0.1:51358')

app = flask.Flask(__name__)
app.wsgi_app = ProxyFix(app.wsgi_app)

config = app.config
config.from_pyfile('config/basename.py')
config.from_pyfile('config/secret.py')
config.from_pyfile('config/oauth.py')


def authenticate():
    access_token = flask.session.get('access_token')
    if not access_token:
        print('auth fail - no access token', file=sys.stderr)
        return False

    profile_url = config['LIQUID_URL'] + '/accounts/profile'
    profile_resp = requests.get(profile_url, headers={
        'Authorization': 'Bearer {}'.format(flask.session['access_token']),
    })

    if profile_resp.status_code != 200: