Beispiel #1
0
 def __init__(self, env, app, account_name, token, container_name,
                 **kwargs):
     WSGIContext.__init__(self, app)
     self.container_name = unquote(container_name)
     self.account_name = unquote(account_name)
     env['HTTP_X_AUTH_TOKEN'] = token
     env['PATH_INFO'] = '/v1/%s/%s' % (account_name, container_name)
Beispiel #2
0
 def __init__(self, env, app, account_name, token, **kwargs):
     WSGIContext.__init__(self, app)
     conf = kwargs.get('conf', {})
     self.logger = kwargs.get('logger', {})
     env['HTTP_X_AUTH_TOKEN'] = token[0]
     env['HTTP_X_AUTH_TOKEN_ALT'] = token[1]
     env['PATH_INFO'] = '/v1/%s' % account_name
Beispiel #3
0
 def __init__(self, env, app, account_name, token, container_name,
              **kwargs):
     WSGIContext.__init__(self, app)
     self.container_name = unquote(container_name)
     self.account_name = unquote(account_name)
     env['HTTP_X_AUTH_TOKEN'] = token
     env['PATH_INFO'] = '/v1/%s/%s' % (account_name, container_name)
Beispiel #4
0
    def __init__(self, rewrite, conf):
        WSGIContext.__init__(self, rewrite.app)
        self.app = rewrite.app
        self.logger = rewrite.logger

        self.account = conf['account'].strip()
        self.thumbhost = conf['thumbhost'].strip()
        self.thumborhost = conf['thumborhost'].strip(
        ) if 'thumborhost' in conf else None
        if 'thumbor_wiki_list' in conf:
            self.thumbor_wiki_list = [
                item.strip() for item in conf['thumbor_wiki_list'].split(',')
            ]
        else:
            self.thumbor_wiki_list = None
        self.user_agent = conf['user_agent'].strip()
        self.bind_port = conf['bind_port'].strip()
        self.shard_container_list = [
            item.strip() for item in conf['shard_container_list'].split(',')
        ]
        # this parameter controls whether URLs sent to the thumbhost are sent
        # as is (eg. upload/proj/lang/) or with the site/lang converted  and
        # only the path sent back (eg en.wikipedia/thumb).
        self.backend_url_format = conf['backend_url_format'].strip(
        )  # asis, sitelang
        self.tld = conf['tld'].strip()
Beispiel #5
0
 def __call__(self, env, start_response):
     ctx = WSGIContext(self.app)
     app_iter = ctx._app_call(env)
     try:
         split_path(env['PATH_INFO'], 4, 4, True)
     except ValueError:
         pass  # not an object request; don't care
     else:
         if env['REQUEST_METHOD'] == 'DELETE' and \
                 ctx._response_status[:3] == '404':
             # Should be a cache hit
             if is_success(
                     get_container_info(env, self.app,
                                        swift_source='S3').get('status')):
                 # Convert to a successful response
                 ctx._response_status = '204 No Content'
                 ctx._response_headers = [
                     (h, '0' if h.lower() == 'content-length' else v)
                     for h, v in ctx._response_headers
                 ]
                 with closing_if_possible(app_iter):
                     for chunk in app_iter:
                         pass  # should be short; just drop it on the floor
                 app_iter = ['']
     start_response(ctx._response_status, ctx._response_headers)
     return app_iter
Beispiel #6
0
 def __init__(self, env, app, account_name, token, container_name, **kwargs):
     self.MAX_BUCKET_LISTING = 1000
     WSGIContext.__init__(self, app)
     self.container_name = unquote(container_name)
     self.account_name = unquote(account_name)
     env["HTTP_X_AUTH_TOKEN"] = token
     env["PATH_INFO"] = "/v1/AUTH_%s/%s" % (account_name, container_name)
     conf = kwargs.get("conf", {})
     self.location = conf.get("location", "US")
 def __init__(self, env, app, account_name, token, container_name,
              **kwargs):
     WSGIContext.__init__(self, app)
     self.container_name = unquote(container_name)
     self.account_name = unquote(account_name)
     env['HTTP_X_AUTH_TOKEN'] = token
     env['PATH_INFO'] = '/v1/%s/%s' % (account_name, container_name)
     conf = kwargs.get('conf', {})
     self.location = conf.get('location', 'US')
Beispiel #8
0
 def __init__(self, staticweb, version, account, container, obj):
     WSGIContext.__init__(self, staticweb.app)
     self.version = version
     self.account = account
     self.container = container
     self.obj = obj
     self.app = staticweb.app
     self.agent = "%(orig)s StaticWeb"
     # Results from the last call to self._get_container_info.
     self._index = self._error = self._listings = self._listings_css = self._dir_type = None
Beispiel #9
0
 def __init__(self, env, app, account_name, token, container_name,
              **kwargs):
     self.MAX_BUCKET_LISTING = 1000
     WSGIContext.__init__(self, app)
     self.container_name = unquote(container_name)
     self.account_name = unquote(account_name)
     env['HTTP_X_AUTH_TOKEN'] = token
     env['PATH_INFO'] = '/v1/AUTH_%s/%s' % (account_name, container_name)
     conf = kwargs.get('conf', {})
     self.location = conf.get('location', 'US')
Beispiel #10
0
 def __init__(self, staticweb, version, account, container, obj):
     WSGIContext.__init__(self, staticweb.app)
     self.version = version
     self.account = account
     self.container = container
     self.obj = obj
     self.app = staticweb.app
     self.agent = '%(orig)s StaticWeb'
     # Results from the last call to self._get_container_info.
     self._index = self._error = self._listings = self._listings_css = \
         self._dir_type = None
Beispiel #11
0
 def __init__(self, env, app, account_name, token, container_name,
              object_name, **kwargs):
     WSGIContext.__init__(self, app)
     self.account_name = unquote(account_name)
     self.container_name = unquote(container_name)
     conf = kwargs.get('conf', {})
     self.logger = kwargs.get('logger', {})
     env['HTTP_X_AUTH_TOKEN'] = token[0]
     env['HTTP_X_AUTH_TOKEN_ALT'] = token[1]
     env['PATH_INFO'] = '/v1/%s/%s/%s' % (account_name, container_name,
                                          object_name)
     self.logger.debug("ObjectController env: %s" % env)
Beispiel #12
0
    def __init__(self, rewrite, conf):
        WSGIContext.__init__(self, rewrite.app)
        self.app = rewrite.app
        self.logger = rewrite.logger

        self.account = conf['account'].strip()
        self.thumborhost = conf['thumborhost'].strip()
        self.user_agent = conf['user_agent'].strip()
        self.bind_port = conf['bind_port'].strip()
        self.shard_container_list = [
            item.strip() for item in conf['shard_container_list'].split(',')
        ]
Beispiel #13
0
 def __init__(self, staticweb, version, account, container, obj):
     WSGIContext.__init__(self, staticweb.app)
     self.version = version
     self.account = account
     self.container = container
     self.obj = obj
     self.app = staticweb.app
     self.cache_timeout = staticweb.cache_timeout
     self.logger = staticweb.logger
     self.access_logger = staticweb.access_logger
     self.log_headers = staticweb.log_headers
     self.agent = '%(orig)s StaticWeb'
     # Results from the last call to self._get_container_info.
     self._index = self._error = self._listings = self._listings_css = None
Beispiel #14
0
 def __init__(self, staticweb, version, account, container, obj):
     WSGIContext.__init__(self, staticweb.app)
     self.version = version
     self.account = account
     self.container = container
     self.obj = obj
     self.app = staticweb.app
     self.cache_timeout = staticweb.cache_timeout
     self.logger = staticweb.logger
     self.access_logger = staticweb.access_logger
     self.log_headers = staticweb.log_headers
     self.agent = '%(orig)s StaticWeb'
     # Results from the last call to self._get_container_info.
     self._index = self._error = self._listings = self._listings_css = None
Beispiel #15
0
    def __init__(self, rewrite, conf):
        WSGIContext.__init__(self, rewrite.app)
        self.app = rewrite.app
        self.logger = rewrite.logger

        self.account = conf['account'].strip()
        self.thumbhost = conf['thumbhost'].strip()
        self.thumborhost = conf['thumborhost'].strip() if 'thumborhost' in conf else None
        self.thumbor_wiki_list = [item.strip() for item in conf['thumbor_wiki_list'].split(',')] if 'thumbor_wiki_list' in conf else None
        self.user_agent = conf['user_agent'].strip()
        self.bind_port = conf['bind_port'].strip()
        self.shard_container_list = [item.strip() for item in conf['shard_container_list'].split(',')]
        # this parameter controls whether URLs sent to the thumbhost are sent as is (eg. upload/proj/lang/) or with the site/lang
        # converted  and only the path sent back (eg en.wikipedia/thumb).
        self.backend_url_format = conf['backend_url_format'].strip()  # asis, sitelang
Beispiel #16
0
 def __init__(self, swascii, version, account, container, obj, conf):
     WSGIContext.__init__(self, swascii.app)
     self.app = swascii.app
     self.version = version
     self.account = account
     self.container = container
     self.obj = obj
     self.greyscale = [" ",
                       " ",
                       ".,-",
                       "_ivc=!/|\~=",
                       "gjez2](YL)t[+T7Vf",
                       "mdK4~GbNDXY5P*Q",
                       "W8KMA",
                       "#%$"
                       ]
     self.zonebounds = [36, 72, 108, 144, 180, 216, 252]
Beispiel #17
0
    def __init__(self, rewrite, conf):
        WSGIContext.__init__(self, rewrite.app)
        self.app = rewrite.app
        self.logger = rewrite.logger

        self.account = conf['account'].strip()
        self.thumborhost = conf['thumborhost'].strip()
        self.inactivedc_thumborhost = conf['inactivedc_thumborhost'].strip()
        self.user_agent = conf['user_agent'].strip()
        self.bind_port = conf['bind_port'].strip()
        self.shard_container_list = [
            item.strip() for item in conf['shard_container_list'].split(',')
        ]
        self.thumbnail_update_expiry_headers = \
            conf['thumbnail_update_expiry_headers'].strip().lower() == 'true'
        self.thumbnail_expiry = conf['thumbnail_expiry'].strip()
        self.thumbnail_user = conf['thumbnail_user'].strip()
        self.thumbnail_key = conf['thumbnail_key'].strip()
Beispiel #18
0
    def __init__(self, rewrite, conf):
        def striplist(l):
            return([x.strip() for x in l])

        WSGIContext.__init__(self, rewrite.app)
        self.app = rewrite.app
        self.logger = rewrite.logger

        self.account = conf['account'].strip()
        self.thumbhost = conf['thumbhost'].strip()
        self.user_agent = conf['user_agent'].strip()
        self.bind_port = conf['bind_port'].strip()
        self.shard_containers = conf['shard_containers'].strip() #all, some, none
        if (self.shard_containers == 'some'):
            # if we're supposed to shard some containers, get a cleaned list of the containers to shard
            self.shard_container_list = striplist(conf['shard_container_list'].split(','))
        # this parameter controls whether URLs sent to the thumbhost are sent as is (eg. upload/proj/lang/) or with the site/lang
        # converted  and only the path sent back (eg en.wikipedia/thumb).
        self.backend_url_format = conf['backend_url_format'].strip() #'asis', 'sitelang'
Beispiel #19
0
    def __init__(self, rewrite, conf):
        def striplist(l):
            return([x.strip() for x in l])

        WSGIContext.__init__(self, rewrite.app)
        self.app = rewrite.app
        self.logger = rewrite.logger

        self.account = conf['account'].strip()
        self.thumbhost = conf['thumbhost'].strip()
        self.user_agent = conf['user_agent'].strip()
        self.bind_port = conf['bind_port'].strip()
        self.shard_containers = conf['shard_containers'].strip() #all, some, none
        if (self.shard_containers == 'some'):
            # if we're supposed to shard some containers, get a cleaned list of the containers to shard
            self.shard_container_list = striplist(conf['shard_container_list'].split(','))
        # this parameter controls whether URLs sent to the thumbhost are sent as is (eg. upload/proj/lang/) or with the site/lang
        # converted  and only the path sent back (eg en.wikipedia/thumb).
        self.backend_url_format = conf['backend_url_format'].strip() #'asis', 'sitelang'
 def __init__(self, wsgi_app, logger):
     WSGIContext.__init__(self, wsgi_app)
     self.logger = logger
Beispiel #21
0
    def __call__(self, env, start_response):
        # a lot of this is cribbed from listing_formats / swob.Request
        if env['REQUEST_METHOD'] != 'GET':
            # Nothing to translate
            return self.app(env, start_response)

        try:
            v, a, c = split_path(env.get('SCRIPT_NAME', '') +
                                 env['PATH_INFO'], 3, 3)
            if not valid_api_version(v):
                raise ValueError
        except ValueError:
            # not a container request; pass through
            return self.app(env, start_response)

        ctx = WSGIContext(self.app)
        resp_iter = ctx._app_call(env)

        content_type = content_length = cl_index = None
        for index, (header, value) in enumerate(ctx._response_headers):
            header = header.lower()
            if header == 'content-type':
                content_type = value.split(';', 1)[0].strip()
                if content_length:
                    break
            elif header == 'content-length':
                cl_index = index
                try:
                    content_length = int(value)
                except ValueError:
                    pass  # ignore -- we'll bail later
                if content_type:
                    break

        if content_type != 'application/json' or content_length is None or \
                content_length > MAX_CONTAINER_LISTING_CONTENT_LENGTH:
            start_response(ctx._response_status, ctx._response_headers,
                           ctx._response_exc_info)
            return resp_iter

        # We've done our sanity checks, slurp the response into memory
        with closing_if_possible(resp_iter):
            body = b''.join(resp_iter)

        try:
            listing = json.loads(body)
            for item in listing:
                if 'subdir' in item:
                    continue
                value, params = parse_header(item['hash'])
                if 's3_etag' in params:
                    item['s3_etag'] = '"%s"' % params.pop('s3_etag')
                    item['hash'] = value + ''.join(
                        '; %s=%s' % kv for kv in params.items())
        except (TypeError, KeyError, ValueError):
            # If anything goes wrong above, drop back to original response
            start_response(ctx._response_status, ctx._response_headers,
                           ctx._response_exc_info)
            return [body]

        body = json.dumps(listing).encode('ascii')
        ctx._response_headers[cl_index] = (
            ctx._response_headers[cl_index][0],
            str(len(body)),
        )
        start_response(ctx._response_status, ctx._response_headers,
                       ctx._response_exc_info)
        return [body]
 def __init__(self, env, app, account_name, token, **kwargs):
     WSGIContext.__init__(self, app)
     env['HTTP_X_AUTH_TOKEN'] = token
     env['PATH_INFO'] = '/v1/%s' % account_name
Beispiel #23
0
 def __init__(self, slowdown, data_to_read, sleep_time, req):
     WSGIContext.__init__(self, slowdown.app)
     self.data_to_read = data_to_read
     self.sleep_time = sleep_time
     self.req = req
Beispiel #24
0
    def __call__(self, env, start_response):
        # a lot of this is cribbed from listing_formats / swob.Request
        if env['REQUEST_METHOD'] != 'GET':
            # Nothing to translate
            return self.app(env, start_response)

        try:
            v, a, c = split_path(
                env.get('SCRIPT_NAME', '') + env['PATH_INFO'], 3, 3)
            if not valid_api_version(v):
                raise ValueError
        except ValueError:
            # not a container request; pass through
            return self.app(env, start_response)

        ctx = WSGIContext(self.app)
        resp_iter = ctx._app_call(env)

        content_type = content_length = cl_index = None
        for index, (header, value) in enumerate(ctx._response_headers):
            header = header.lower()
            if header == 'content-type':
                content_type = value.split(';', 1)[0].strip()
                if content_length:
                    break
            elif header == 'content-length':
                cl_index = index
                try:
                    content_length = int(value)
                except ValueError:
                    pass  # ignore -- we'll bail later
                if content_type:
                    break

        if content_type != 'application/json' or content_length is None or \
                content_length > MAX_CONTAINER_LISTING_CONTENT_LENGTH:
            start_response(ctx._response_status, ctx._response_headers,
                           ctx._response_exc_info)
            return resp_iter

        # We've done our sanity checks, slurp the response into memory
        with closing_if_possible(resp_iter):
            body = b''.join(resp_iter)

        try:
            listing = json.loads(body)
            for item in listing:
                if 'subdir' in item:
                    continue
                value, params = parse_header(item['hash'])
                if 's3_etag' in params:
                    item['s3_etag'] = '"%s"' % params.pop('s3_etag')
                    item['hash'] = value + ''.join('; %s=%s' % kv
                                                   for kv in params.items())
        except (TypeError, KeyError, ValueError):
            # If anything goes wrong above, drop back to original response
            start_response(ctx._response_status, ctx._response_headers,
                           ctx._response_exc_info)
            return [body]

        body = json.dumps(listing)
        ctx._response_headers[cl_index] = (
            ctx._response_headers[cl_index][0],
            str(len(body)),
        )
        start_response(ctx._response_status, ctx._response_headers,
                       ctx._response_exc_info)
        return [body]
Beispiel #25
0
 def __init__(self, slo, slo_etag):
     WSGIContext.__init__(self, slo.app)
     self.slo_etag = '"' + slo_etag.hexdigest() + '"'
 def __init__(self, wsgi_app, logger):
     WSGIContext.__init__(self, wsgi_app)
     self.logger = logger
Beispiel #27
0
 def __init__(self, env, app, account_name, token, **kwargs):
     WSGIContext.__init__(self, app)
     env['HTTP_X_AUTH_TOKEN'] = token
     env['PATH_INFO'] = '/v1/%s' % account_name