首先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 (#)
> GET /auth/v1. HTTP/1.1
> User-Agent: curl/7.35.
> Host: 127.0.0.1:
> 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 (#)
> GET /v1/AUTH_test/ HTTP/1.1
> User-Agent: curl/7.35.
> Host: 127.0.0.1:
> 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 (#)
> PUT /v1/AUTH_test/ab3 HTTP/1.1
> User-Agent: curl/7.35.
> Host: 127.0.0.1:
> 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 OK
< Content-Length:
< X-Account-Object-Count:
< X-Account-Storage-Policy-Policy--Bytes-Used:
< X-Account-Storage-Policy-Policy--Container-Count:
< X-Timestamp: 1444721178.82674
< X-Account-Storage-Policy-Policy--Object-Count:
< X-Account-Bytes-Used:
< X-Account-Container-Count:
< Content-Type: text/plain; charset=utf-
< Accept-Ranges: bytes
< X-Trans-Id: tx6c0f7ff0121740a190b6f-005630e646
< Date: Wed, Oct :: GMT
<
ab
ab2
ab3
hello
hello1
* Connection # 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 (#)
> DELETE /v1/AUTH_test/ab3 HTTP/1.1
> User-Agent: curl/7.35.
> Host: 127.0.0.1:
> 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请求失败,说明中间件起作用了

openstack swift middleware开发的更多相关文章

  1. OpenStack Swift client开发

    如果你搭建好了Swift环境 ,你应该可以通过Swift 命令 来尝试去测试上传下载等功能,这是因为在安装Swift的时候,通常会安装一个python-swiftclient客户端,这个一个pytho ...

  2. 理解 OpenStack Swift (1):OpenStack + 三节点Swift 集群+ HAProxy + UCARP 安装和配置

    本系列文章着重学习和研究OpenStack Swift,包括环境搭建.原理.架构.监控和性能等. (1)OpenStack + 三节点Swift 集群+ HAProxy + UCARP 安装和配置 ( ...

  3. [转载] 对象存储(2):OpenStack Swift——概念、架构与规模部署

    原文: http://www.testlab.com.cn/Index/article/id/1085.html#rd?sukey=fc78a68049a14bb228cb2742bdec2b9498 ...

  4. Openstack Swift中间件编写

    关于openstack swift的资料可以看这里,这里还有这里. 准备环境 从零开始接触的同学可以先从swift的all in one部署开始学习,在本机搭建好swift环境就可以进行简单的测试了. ...

  5. 理解 OpenStack Swift (3):监控和一些影响性能的因素 [Monitoring and Performance]

    本系列文章着重学习和研究OpenStack Swift,包括环境搭建.原理.架构.监控和性能等. (1)OpenStack + 三节点Swift 集群+ HAProxy + UCARP 安装和配置 ( ...

  6. 理解 OpenStack Swift (2):架构、原理及功能 [Architecture, Implementation and Features]

    本系列文章着重学习和研究OpenStack Swift,包括环境搭建.原理.架构.监控和性能等. (1)OpenStack + 三节点Swift 集群+ HAProxy + UCARP 安装和配置 ( ...

  7. OpenStack Swift集群与Keystone的整合使用说明

    之前已经介绍了OpenStack Swift集群和Keystone的安装部署,最后来讲一讲Swift集群与Keystone的整合使用吧. 1. 简介 本文档描述了Keystone与Swift集群的整合 ...

  8. OpenStack Swift集群部署流程与简单使用

    之前介绍了<OpenStack Swift All In One安装部署流程与简单使用>,那么接下来就说一说Swift集群部署吧. 1. 简介 本文档详细描述了使用两台PC部署一个小型Sw ...

  9. Openstack Swift 原理、架构与 API 介绍

    OpenStack Swift 开源项目提供了弹性可伸缩.高可用的分布式对象存储服务,适合存储大规模非结构化数据.本文将深入介绍 Swift 的基本设计原理.对称式的系统架构和 RESTful API ...

随机推荐

  1. 洛谷 P2788 数学1(math1)- 加减算式

    题目背景 蒟蒻HansBug在数学考场上,挠了无数次的头,可脑子里还是一片空白. 题目描述 好不容易啊,HansBug终于熬到了做到数学最后一题的时刻了,眼前是一堆杂乱的加减算式.显然成功就在眼前了. ...

  2. 版本号对比方案及参考代码(Objective-C,Java,JavaScript)

    常用版本号 如 2.0.1 与 2.0.2 相比  2.0.2是比2.0.1要新的 那么该如何对这个版本号进行对比 这里有一个比较简单的实现方案 2.0.1 这种格式可以拆分为多个部分 如这里的2是大 ...

  3. es 集群部署

    下载 [root@localhost ~]# wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.5.1 ...

  4. nvm、npm、nodejs的关系(转载)

    nvm.npm.nodejs的关系 为什么要了解nvm.npm.nodejs的关系: reactNative的项目构建都是有这几个工具进行构建管理. 掌握他们的关系,就能了解reactNative项目 ...

  5. caffe layer注册机制

    Caffe内部维护一个注册表用于查找特定Layer对应的工厂函数(Layer Factory的设计用到了设计模式里的工厂模式).Layer_factory的主要作用是负责Layer的注册,已经注册完事 ...

  6. 在Foxmail邮件客户端登录263企业邮箱

    一.问题描述 首次用Foxmail登录263企业,输入账号和密码,创建 二.问题分析 客户端配置地址: 协议类型 服务器地址 默认端 加密端(SSL) POP pop.263.net 110 1995 ...

  7. kvm安装图终端界面及形界面安装系统

    1.图形界面安装: qemu-img create -f qcow2 /kvm/os/vm-01.qcow2 16G mkdir -p /kvm/iso cd /kvm/iso 上传事先下载好的镜像文 ...

  8. Go:sync.Once 实现单例模式

    代码: package main import ( "fmt" "sync" ) type Singleton struct{} var singleton * ...

  9. svn搭建脚本

    1.yum install subversion 2.输入rpm -ql subversion查看安装位置 我们知道svn在bin目录下生成了几个二进制文件. 输入 svn --help可以查看svn ...

  10. nginx如何防止高负载造成服务器崩溃

    nginx-http-sysguard模块 一.作用 防止因nginx并发访问量过高或者遭受攻击造成服务器宕机,可根据负载设置界面跳转.   二.安装配置 1.下载模块软件包 wget https:/ ...