Exemplo n.º 1
0
def copy_object(api_ver, account, container, object):
    _validate_object(api_ver, account, container, object)

    fresh = bottle.request.get_header('x-fresh-metadata')
    fresh = is_truthy(fresh)

    dst_container, dst_object = get_destination()

    meta = {}
    for key, value in bottle.request.headers.iteritems():
        key = key.lower()
        if key.startswith('x-object-meta-'):
            meta[key] = value

    content_type = bottle.request.get_header('content-type')
    if content_type:
        meta['content-type'] = content_type

    copier = ObjectCopier(
        container, object,
        dst_container, dst_object
    )
    copier.copy(meta=meta, fresh_meta=fresh)

    bottle.response.set_header('x-timestamp', 0)
    bottle.response.status = 201
Exemplo n.º 2
0
def get_content_type(path):
    detect_content_type = bottle.request.get_header('x-detect-content-type')
    if is_truthy(detect_content_type):
        guessed_type, _ = mimetypes.guess_type(path)
        return guessed_type or 'application/octet-stream'

    content_type = bottle.request.get_header('content-type', None)
    if content_type is None:
        raise bottle.HTTPError(400, 'No content type')
    return content_type
Exemplo n.º 3
0
def preprocess_settings():
    for key in KEYS_INT:
        if key in _SETTINGS:
            _SETTINGS[key] = int(_SETTINGS[key])

    for key in KEYS_BOOL:
        if key in _SETTINGS:
            _SETTINGS[key] = is_truthy(_SETTINGS[key])

    for key in KEYS_COMMA_SEPARATED:
        if key in _SETTINGS:
            _SETTINGS[key] = [part.strip() for part in _SETTINGS[key].split(",")]
Exemplo n.º 4
0
    def __call__(self, env, start_response):
        ip_address = env.get('REMOTE_ADDR')
        msg = [
            '[', ip_address, '] ', env['SERVER_PROTOCOL'], ' ',
            env['REQUEST_METHOD'], ' ', env['PATH_INFO'], '\n'
        ]
        for key, value in env.iteritems():
            if key.startswith('HTTP_'):
                msg.append(key[5:] + ': ' + value + '\n')
        msg.append('\n')

        if is_truthy(self.conf.get('log_response_status')):

            def start_wrapper(status, headers):
                msg.append(status)
                return start_response(status, headers)
        else:
            start_wrapper = start_response

        resp = self.app(env, start_wrapper)
        logger.info(''.join(str(piece) for piece in msg))
        return resp
Exemplo n.º 5
0
    def __call__(self, env, start_response):
        ip_address = env.get('REMOTE_ADDR')
        msg = [
            '[', ip_address, '] ',
            env['SERVER_PROTOCOL'], ' ', env['REQUEST_METHOD'],
            ' ', env['PATH_INFO'], '\n'
        ]
        for key, value in env.iteritems():
            if key.startswith('HTTP_'):
                msg.append(key[5:] + ': ' + value + '\n')
        msg.append('\n')

        if is_truthy(self.conf.get('log_response_status')):
            def start_wrapper(status, headers):
                msg.append(status)
                return start_response(status, headers)
        else:
            start_wrapper = start_response

        resp = self.app(env, start_wrapper)
        logger.info(''.join(str(piece) for piece in msg))
        return resp
Exemplo n.º 6
0
def copy_object(api_ver, account, container, object):
    _validate_object(api_ver, account, container, object)

    fresh = bottle.request.get_header('x-fresh-metadata')
    fresh = is_truthy(fresh)

    dst_container, dst_object = get_destination()

    meta = {}
    for key, value in bottle.request.headers.iteritems():
        key = key.lower()
        if key.startswith('x-object-meta-'):
            meta[key] = value

    content_type = bottle.request.get_header('content-type')
    if content_type:
        meta['content-type'] = content_type

    copier = ObjectCopier(container, object, dst_container, dst_object)
    copier.copy(meta=meta, fresh_meta=fresh)

    bottle.response.set_header('x-timestamp', 0)
    bottle.response.status = 201
Exemplo n.º 7
0
def requires_priv(priv_name):
    settings = get_settings()
    disable = settings.get('this.disable_access_restrictions')
    disable = is_truthy(disable)
    if disable:
        return no_restrictions

    if priv_name not in PRIVS_BY_NAME:
        raise Exception('Wrong access!')

    priv = PRIVS_BY_NAME[priv_name]

    @decorator
    def wrapper(func, *args, **kwargs):
        user = bottle.request.environ.get('sxswift.user')
        if not user:
            raise bottle.HTTPError(401)

        access = user.get('access', NO_PRIVS)
        if not access.extends(priv):
            raise bottle.HTTPError(403)
        return func(*args, **kwargs)
    return wrapper
Exemplo n.º 8
0
def requires_priv(priv_name):
    settings = get_settings()
    disable = settings.get('this.disable_access_restrictions')
    disable = is_truthy(disable)
    if disable:
        return no_restrictions

    if priv_name not in PRIVS_BY_NAME:
        raise Exception('Wrong access!')

    priv = PRIVS_BY_NAME[priv_name]

    @decorator
    def wrapper(func, *args, **kwargs):
        user = bottle.request.environ.get('sxswift.user')
        if not user:
            raise bottle.HTTPError(401)

        access = user.get('access', NO_PRIVS)
        if not access.extends(priv):
            raise bottle.HTTPError(403)
        return func(*args, **kwargs)

    return wrapper