文档章节

openstack swift middleware开发

Vincent-Duan
 Vincent-Duan
发布于 2016/10/12 23:46
字数 683
阅读 13
收藏 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

粉丝 9
博文 304
码字总数 100203
作品 0
海淀
私信 提问
OpenStack Identity(Keystone)身份服务-体系结构与中间件

OpenStack Identity(Keystone)服务为运行OpenStack Compute上的OpenStack云提供了认证和管理用户、帐号和角色信息服务,并为OpenStack Object Storage提供授权服务。 Keystone体系结构 Ke...

三毛々
2012/10/18
0
0
(zhuan) Revisiting OpenStack Architecture: Esse...

While it is still seven weeks until OpenStack "Essex" (2012.1) officially is released, release candidates are just around the corner. With this in mind, I thought it would be a ......

威廉亨利
2012/03/13
0
0
浅谈OpenStack平台的安全问题及措施

OpenStack的优势与劣势 Openstack具有三大特点:免费开源、强大的兼客性以及开放性。 Openstack 本身是一个开源、免费的软件,同商业软件相比它给了客户足够的自由度,可以在任何场合使用,O...

凌洛
05/12
0
0
openstack学习之路-level1-1

Openstack各组件介绍 Dashboard 项目名horizon 提供openstack的交互界面,可以在交互界面中管理openstack,比如启动一个实例,配置IP地址,配置用户认证等 Compute 项目名nova 负责openstack...

gyj0825
06/26
0
0
云计算相关资料/博客/网上收集的关于OpenStack的一些资源

OpenStack Nova code:https://bugs.launchpad.net/nova OpenStack Blog:http://planet.openstack.org/ OpenStack 官方文档:http://docs.openstack.org/cactus/openstack-compute/admin/co......

DongZhang
2012/02/02
0
0

没有更多内容

加载失败,请刷新页面

加载更多

Ubuntu常用操作

查看端口号 netstat -anp |grep 端口号 查看已使用端口情况 netstat -nultp(此处不用加端口号) netstat -anp |grep 82查看82端口的使用情况 查找被占用的端口: netstat -tln netstat -tl...

hc321
昨天
0
0
网站cdn的静态资源突然访问变的缓慢,问题排查流程

1.首先我查看了一下是否自己的网络问题,通过对比其他资源的访问速度和下载速度,确认不是 2.通过ping 和 tracert 判断cdn域名能否正常访问,(最后回想感觉这一步可以省略,因为每次最终能访...

小海bug
昨天
0
0
Mybatis 学习笔记四 MyBatis-Plus插件

Mybatis 学习笔记四 MyBatis-Plus插件 maven依赖 <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus</artifactId> <ve......

晨猫
昨天
2
0
小白带你认识netty(二)之netty服务端启动(下)

承接上一篇小白带你认识netty(二)之netty服务端启动(上),还剩下两步骤:3、注册Selector:将Channel注册到Selector上 和 4、端口的绑定:服务端端口的监听。 3、注册Selector:将Chann...

天空小小
昨天
0
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部