文档章节

openstack swift middleware开发

Vincent-Duan
 Vincent-Duan
发布于 2016/10/12 23:46
字数 683
阅读 127
收藏 0

「深度学习福利」大神带你进阶工程师,立即查看>>>

首先MiddleWare核心代码,这段代码卸载swift的源代码目录下,~/swift/swift/common/middleware下新建deletionpreventing.py:

import os
from swift.common.swob import Request, Response

class DeletionPreventingMiddleware(object):
    def __init__(self, app,conf):
        self.app = app
        print "vincent middleware"
        print app
    def __call__(self, env, start_response):
        print "it in deletionprevention middleware"
        if env['REQUEST_METHOD'] != 'DELETE':
            print "not put method"
            return self.app(env, start_response)
        return Response( status=403, body="Delete prohibited", content_type="text/plain")(env, start_response)
def filter_factory(global_conf, **local_conf):
    conf = global_conf.copy()
    conf.update(local_conf)
    print conf
    def deletionpreventing_filter(app):
        print "deletion"
        return DeletionPreventingMiddleware(app, conf)
    return deletionpreventing_filter

在/etc/swift/proxy-server.conf中添加中间件

[pipeline:main]
pipeline = catch_errors healthcheck cache ratelimit tempauth deletionpreventing proxy-logging proxy-server
[filter:deletionpreventing]
use = egg:swift#deletionpreventing
myconf=value1

其中deletionpriventing就是我们自己定义的中间件

然后在~/swift/swift.egg-info目录下的entry_point.txt中添加中间件:

deletionpreventing = swift.common.middleware.deletionpreventing:filter_factory

在~/swift/setup.cfg中添加中间件(这一步可以不做)

deletionpreventing = swift.common.middleware.deletionpreventing:filter_factory

测试运行:

swift@vincent-virtual-machine ~/swift $ curl -v -H "X-Storage-User:test:tester" -H "X-Storage-Pass:testing" http://127.0.0.1:8080/auth/v1.0
* Hostname was NOT found in DNS cache
*   Trying 127.0.0.1...
* Connected to 127.0.0.1 (127.0.0.1) port 8080 (#0)
> GET /auth/v1.0 HTTP/1.1
> User-Agent: curl/7.35.0
> Host: 127.0.0.1:8080
> Accept: */*
> X-Storage-User:test:tester
> X-Storage-Pass:testing
> 
< HTTP/1.1 200 OK
< X-Storage-Url: http://127.0.0.1:8080/v1/AUTH_test
< X-Auth-Token: AUTH_tkf36387dd367b474383cfac60979bed45
< Content-Type: text/html; charset=UTF-8
< X-Storage-Token: AUTH_tkf36387dd367b474383cfac60979bed45
< X-Trans-Id: tx0b4c7f7dee284e0d9dd5b-005630e592
< Content-Length: 0
< Date: Wed, 28 Oct 2015 15:11:14 GMT
< 
* Connection #0 to host 127.0.0.1 left intact
swift@vincent-virtual-machine ~/swift $

查看列表:

swift@vincent-virtual-machine ~/swift $ curl -v  -H "X-Auth-Token: AUTH_tkf36387dd367b474383cfac60979bed45" http://127.0.0.1:8080/v1/AUTH_test/
* Hostname was NOT found in DNS cache
*   Trying 127.0.0.1...
* Connected to 127.0.0.1 (127.0.0.1) port 8080 (#0)
> GET /v1/AUTH_test/ HTTP/1.1
> User-Agent: curl/7.35.0
> Host: 127.0.0.1:8080
> Accept: */*
> X-Auth-Token: AUTH_tkf36387dd367b474383cfac60979bed45
> 
< HTTP/1.1 200 OK
< Content-Length: 20
< X-Account-Object-Count: 2
< X-Account-Storage-Policy-Policy-0-Bytes-Used: 12
< X-Account-Storage-Policy-Policy-0-Container-Count: 4
< X-Timestamp: 1444721178.82674
< X-Account-Storage-Policy-Policy-0-Object-Count: 2
< X-Account-Bytes-Used: 12
< X-Account-Container-Count: 4
< Content-Type: text/plain; charset=utf-8
< Accept-Ranges: bytes
< X-Trans-Id: tx1533138aaa0c4c6b99dfc-005630e60f
< Date: Wed, 28 Oct 2015 15:13:19 GMT
< 
ab
ab2
hello
hello1
* Connection #0 to host 127.0.0.1 left intact
swift@vincent-virtual-machine ~/swift $

测试PUT请求:

swift@vincent-virtual-machine ~/swift $ curl -X PUT -v  -H "X-Auth-Token: AUTH_tkf36387dd367b474383cfac60979bed45" http://127.0.0.1:8080/v1/AUTH_test/ab3
* Hostname was NOT found in DNS cache
*   Trying 127.0.0.1...
* Connected to 127.0.0.1 (127.0.0.1) port 8080 (#0)
> PUT /v1/AUTH_test/ab3 HTTP/1.1
> User-Agent: curl/7.35.0
> Host: 127.0.0.1:8080
> Accept: */*
> X-Auth-Token: AUTH_tkf36387dd367b474383cfac60979bed45
> 
< HTTP/1.1 201 Created
< Content-Length: 0
< Content-Type: text/html; charset=UTF-8
< X-Trans-Id: tx6010eaabf2e64f4fa69dd-005630e642
< Date: Wed, 28 Oct 2015 15:14:10 GMT
< 
* Connection #0 to host 127.0.0.1 left intact
swift@vincent-virtual-machine ~/swift $ curl -v  -H "X-Auth-Token: AUTH_tkf36387dd367b474383cfac60979bed45" http://127.0.0.1:8080/v1/AUTH_test/
* Hostname was NOT found in DNS cache
*   Trying 127.0.0.1...
* Connected to 127.0.0.1 (127.0.0.1) port 8080 (#0)
> GET /v1/AUTH_test/ HTTP/1.1
> User-Agent: curl/7.35.0
> Host: 127.0.0.1:8080
> Accept: */*
> X-Auth-Token: AUTH_tkf36387dd367b474383cfac60979bed45
> 
< HTTP/1.1 200 OK
< Content-Length: 24
< X-Account-Object-Count: 2
< X-Account-Storage-Policy-Policy-0-Bytes-Used: 12
< X-Account-Storage-Policy-Policy-0-Container-Count: 5
< X-Timestamp: 1444721178.82674
< X-Account-Storage-Policy-Policy-0-Object-Count: 2
< X-Account-Bytes-Used: 12
< X-Account-Container-Count: 5
< Content-Type: text/plain; charset=utf-8
< Accept-Ranges: bytes
< X-Trans-Id: tx6c0f7ff0121740a190b6f-005630e646
< Date: Wed, 28 Oct 2015 15:14:14 GMT
< 
ab
ab2
ab3
hello
hello1
* Connection #0 to host 127.0.0.1 left intact

PUT成功;

测试DELETE请求:

swift@vincent-virtual-machine ~/swift $ curl -X DELETE -v  -H "X-Auth-Token: AUTH_tkf36387dd367b474383cfac60979bed45" http://127.0.0.1:8080/v1/AUTH_test/ab3
* Hostname was NOT found in DNS cache
*   Trying 127.0.0.1...
* Connected to 127.0.0.1 (127.0.0.1) port 8080 (#0)
> DELETE /v1/AUTH_test/ab3 HTTP/1.1
> User-Agent: curl/7.35.0
> Host: 127.0.0.1:8080
> Accept: */*
> X-Auth-Token: AUTH_tkf36387dd367b474383cfac60979bed45
> 
< HTTP/1.1 403 Forbidden
< Content-Length: 17
< Content-Type: text/plain
< X-Trans-Id: tx5426c7feb84c41f29b837-005630e66f
< Date: Wed, 28 Oct 2015 15:14:55 GMT
< 
* Connection #0 to host 127.0.0.1 left intact
Delete prohibitedswift@vincent-virtual-machine ~/swift $

DELETE请求失败,说明中间件起作用了

Vincent-Duan

Vincent-Duan

粉丝 41
博文 966
码字总数 550870
作品 0
海淀
私信 提问
加载中
请先登录后再评论。
Swift百万线程攻破单例(Singleton)模式

一、不安全的单例实现 在上一篇文章我们给出了单例的设计模式,直接给出了线程安全的实现方法。单例的实现有多种方法,如下面: class SwiftSingleton { } 这段代码的实现,在shared中进行条...

一叶博客
2014/06/20
3.5K
16
beego API开发以及自动化文档

beego API开发以及自动化文档 beego1.3版本已经在上个星期发布了,但是还是有很多人不了解如何来进行开发,也是在一步一步的测试中开发,期间QQ群里面很多人都问我如何开发,我的业余时间实在...

astaxie
2014/06/25
2.7W
22
Web开发组件管理器--Bower

Bower 是一个针对Web开发的包管理器。该工具主要用来帮助用户轻松安装CSS、JavaScript、图像等相关包,并管理这些包之间的依赖。 功能有些类似于Component。不同之处是,Component是围绕Git...

匿名
2013/02/01
1.2W
2
跨平台手机应用开发--Gideros

Gideros 可以让你轻松快速创建 iOS 和 Android 应用,提供用户友好的集成开发环境,内建模拟器对应用进行不同屏幕大小、分辨率下的测试,最大的优点是可即时修改代码即时进行测试,无需编译安...

匿名
2013/02/19
2.8K
1
Android3D应用与游戏开发框架--JQGL

JQGL 是一款针对Android设备上3D应用、游戏的开发框架。 核心功能是OpenGL-ES的使用框架,相对于大部分开发者而已,OpenGL是陌生的,没有专门研究无法进行相关的开发。 本框架针对于Android...

Jping
2013/02/21
1.6K
0

没有更多内容

加载失败,请刷新页面

加载更多

Subversion存储库中“分支”,“标记”和“主干”的含义是什么?

问题: I've seen these words a lot around Subversion (and I guess general repository) discussions. 我已经在Subversion(我猜通用存储库)讨论中看到了很多这样的话。 I have been us......

富含淀粉
56分钟前
5
0
《Java8实战》笔记(03):Lambda表达式

本文源码 Lambda 管中窥豹 可以把Lambda表达式理解为简洁地表示可传递的匿名函数的一种方式:它没有名称,但它有参数列表、函数主体、返回类型,可能还有一个可以抛出的异常列表。 Lambda表达...

巨輪
58分钟前
7
0
从其他文件夹导入文件 - Importing files from different folder

问题: I have the following folder structure. 我有以下文件夹结构。 application/app/folder/file.py and I want to import some functions from file.py in another Python file which r......

javail
今天
22
0
大数据研发学习之路--Hadoop集群搭建

阅读编译文档 准备一个hadoop源码包,我选择的hadoop版本是:hadoop-2.7.7-src.tar.gz,在hadoop-2.7.7的源码 包的根目录下有一个文档叫做BUILDING.txt,这其中说明了编译hadoop所需要的一些...

DSJ-shitou
今天
8
0
OSChina 周五乱弹 —— 特么是别的公司派来的特洛伊木马吧?

Osc乱弹歌单(2020)请戳(这里) 【今日歌曲】 小小编辑推荐:《我会守在这里》- 毛不易 《我会守在这里》- 毛不易 手机党少年们想听歌,请使劲儿戳(这里) @FalconChen :股市连跪了五天,...

小小编辑
今天
77
2

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部