日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

openstack swift middleware开发

發布時間:2024/9/16 编程问答 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 openstack swift middleware开发 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

首先MiddleWare核心代碼,這段代碼卸載swift的源代碼目錄下,~/swift/swift/common/middleware下新建deletionpreventing.py:

import os from swift.common.swob import Request, Responseclass DeletionPreventingMiddleware(object):def __init__(self, app,conf):self.app = appprint "vincent middleware"print appdef __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 confdef 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請求失敗,說明中間件起作用了

總結

以上是生活随笔為你收集整理的openstack swift middleware开发的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。