今天重新搭建swift服务器,git下代码后一时好奇,进入kilo/stable branch后,与四个月前下载的swift/kilo版本做了个比较。使用diff命令完成。发现代码还是略有区别。

  1. diff -r -u -N --new-file swift/swift/common/bufferedhttp.py swift-kilo/swift/common/bufferedhttp.py
  2. --- swift/swift/common/bufferedhttp.py 2015-09-18 15:30:03.730723515 +0800
  3. +++ swift-kilo/swift/common/bufferedhttp.py 2015-09-18 16:43:36.283386102 +0800
  4. @@ -27,19 +27,14 @@
  5. """
  6. from swift import gettext_ as _
  7. -from swift.common import constraints
  8. from urllib import quote
  9. import logging
  10. import time
  11. import socket
  12. -import eventlet
  13. from eventlet.green.httplib import CONTINUE, HTTPConnection, HTTPMessage, \
  14. HTTPResponse, HTTPSConnection, _UNKNOWN
  15. -httplib = eventlet.import_patched('httplib')
  16. -httplib._MAXHEADERS = constraints.MAX_HEADER_COUNT
  17. -
  18. class BufferedHTTPResponse(HTTPResponse):
  19. """HTTPResponse class that buffers reading of headers"""
  20. diff -r -u -N --new-file swift/swift/common/constraints.py swift-kilo/swift/common/constraints.py
  21. --- swift/swift/common/constraints.py 2015-09-18 15:30:03.730723515 +0800
  22. +++ swift-kilo/swift/common/constraints.py 2015-09-18 16:43:36.259385971 +0800
  23. @@ -36,7 +36,6 @@
  24. MAX_ACCOUNT_NAME_LENGTH = 256
  25. MAX_CONTAINER_NAME_LENGTH = 256
  26. VALID_API_VERSIONS = ["v1", "v1.0"]
  27. -EXTRA_HEADER_COUNT = 0
  28. # If adding an entry to DEFAULT_CONSTRAINTS, note that
  29. # these constraints are automatically published by the
  30. @@ -55,7 +54,6 @@
  31. 'max_account_name_length': MAX_ACCOUNT_NAME_LENGTH,
  32. 'max_container_name_length': MAX_CONTAINER_NAME_LENGTH,
  33. 'valid_api_versions': VALID_API_VERSIONS,
  34. - 'extra_header_count': EXTRA_HEADER_COUNT,
  35. }
  36. SWIFT_CONSTRAINTS_LOADED = False
  37. @@ -107,13 +105,6 @@
  38. 'xml': 'application/xml'}
  39. -# By default the maximum number of allowed headers depends on the number of max
  40. -# allowed metadata settings plus a default value of 32 for regular http
  41. -# headers. If for some reason this is not enough (custom middleware for
  42. -# example) it can be increased with the extra_header_count constraint.
  43. -MAX_HEADER_COUNT = MAX_META_COUNT + 32 + max(EXTRA_HEADER_COUNT, 0)
  44. -
  45. -
  46. def check_metadata(req, target_type):
  47. """
  48. Check metadata sent in the request headers. This should only check
  49. diff -r -u -N --new-file swift/swift/common/middleware/tempurl.py swift-kilo/swift/common/middleware/tempurl.py
  50. --- swift/swift/common/middleware/tempurl.py 2015-09-18 15:30:03.738723545 +0800
  51. +++ swift-kilo/swift/common/middleware/tempurl.py 2015-09-18 16:43:36.243385885 +0800
  52. @@ -122,13 +122,11 @@
  53. from urlparse import parse_qs
  54. from swift.proxy.controllers.base import get_account_info, get_container_info
  55. -from swift.common.swob import HeaderKeyDict, HTTPUnauthorized, HTTPBadRequest
  56. +from swift.common.swob import HeaderKeyDict, HTTPUnauthorized
  57. from swift.common.utils import split_path, get_valid_utf8_str, \
  58. register_swift_info, get_hmac, streq_const_time, quote
  59. -DISALLOWED_INCOMING_HEADERS = 'x-object-manifest'
  60. -
  61. #: Default headers to remove from incoming requests. Simply a whitespace
  62. #: delimited list of header names and names can optionally end with '*' to
  63. #: indicate a prefix match. DEFAULT_INCOMING_ALLOW_HEADERS is a list of
  64. @@ -152,10 +150,6 @@
  65. DEFAULT_OUTGOING_ALLOW_HEADERS = 'x-object-meta-public-*'
  66. -CONTAINER_SCOPE = 'container'
  67. -ACCOUNT_SCOPE = 'account'
  68. -
  69. -
  70. def get_tempurl_keys_from_metadata(meta):
  71. """
  72. Extracts the tempurl keys from metadata.
  73. @@ -176,38 +170,6 @@
  74. quote(filename, safe=' /'), quote(filename))
  75. -def authorize_same_account(account_to_match):
  76. -
  77. - def auth_callback_same_account(req):
  78. - try:
  79. - _ver, acc, _rest = req.split_path(2, 3, True)
  80. - except ValueError:
  81. - return HTTPUnauthorized(request=req)
  82. -
  83. - if acc == account_to_match:
  84. - return None
  85. - else:
  86. - return HTTPUnauthorized(request=req)
  87. -
  88. - return auth_callback_same_account
  89. -
  90. -
  91. -def authorize_same_container(account_to_match, container_to_match):
  92. -
  93. - def auth_callback_same_container(req):
  94. - try:
  95. - _ver, acc, con, _rest = req.split_path(3, 4, True)
  96. - except ValueError:
  97. - return HTTPUnauthorized(request=req)
  98. -
  99. - if acc == account_to_match and con == container_to_match:
  100. - return None
  101. - else:
  102. - return HTTPUnauthorized(request=req)
  103. -
  104. - return auth_callback_same_container
  105. -
  106. -
  107. class TempURL(object):
  108. """
  109. WSGI Middleware to grant temporary URLs specific access to Swift
  110. @@ -268,10 +230,6 @@
  111. #: The methods allowed with Temp URLs.
  112. self.methods = methods
  113. - self.disallowed_headers = set(
  114. - 'HTTP_' + h.upper().replace('-', '_')
  115. - for h in DISALLOWED_INCOMING_HEADERS.split())
  116. -
  117. headers = DEFAULT_INCOMING_REMOVE_HEADERS
  118. if 'incoming_remove_headers' in conf:
  119. headers = conf['incoming_remove_headers']
  120. @@ -340,10 +298,10 @@
  121. return self.app(env, start_response)
  122. if not temp_url_sig or not temp_url_expires:
  123. return self._invalid(env, start_response)
  124. - account, container = self._get_account_and_container(env)
  125. + account = self._get_account(env)
  126. if not account:
  127. return self._invalid(env, start_response)
  128. - keys = self._get_keys(env)
  129. + keys = self._get_keys(env, account)
  130. if not keys:
  131. return self._invalid(env, start_response)
  132. if env['REQUEST_METHOD'] == 'HEAD':
  133. @@ -358,32 +316,15 @@
  134. else:
  135. hmac_vals = self._get_hmacs(env, temp_url_expires, keys)
  136. - is_valid_hmac = False
  137. - hmac_scope = None
  138. - for hmac, scope in hmac_vals:
  139. - # While it's true that we short-circuit, this doesn't affect the
  140. - # timing-attack resistance since the only way this will
  141. - # short-circuit is when a valid signature is passed in.
  142. - if streq_const_time(temp_url_sig, hmac):
  143. - is_valid_hmac = True
  144. - hmac_scope = scope
  145. - break
  146. + # While it's true that any() will short-circuit, this doesn't affect
  147. + # the timing-attack resistance since the only way this will
  148. + # short-circuit is when a valid signature is passed in.
  149. + is_valid_hmac = any(streq_const_time(temp_url_sig, hmac)
  150. + for hmac in hmac_vals)
  151. if not is_valid_hmac:
  152. return self._invalid(env, start_response)
  153. - # disallowed headers prevent accidently allowing upload of a pointer
  154. - # to data that the PUT tempurl would not otherwise allow access for.
  155. - # It should be safe to provide a GET tempurl for data that an
  156. - # untrusted client just uploaded with a PUT tempurl.
  157. - resp = self._clean_disallowed_headers(env, start_response)
  158. - if resp:
  159. - return resp
  160. self._clean_incoming_headers(env)
  161. -
  162. - if hmac_scope == ACCOUNT_SCOPE:
  163. - env['swift.authorize'] = authorize_same_account(account)
  164. - else:
  165. - env['swift.authorize'] = authorize_same_container(account,
  166. - container)
  167. + env['swift.authorize'] = lambda req: None
  168. env['swift.authorize_override'] = True
  169. env['REMOTE_USER'] = '.wsgi.tempurl'
  170. qs = {'temp_url_sig': temp_url_sig,
  171. @@ -424,23 +365,22 @@
  172. return self.app(env, _start_response)
  173. - def _get_account_and_container(self, env):
  174. + def _get_account(self, env):
  175. """
  176. - Returns just the account and container for the request, if it's an
  177. - object request and one of the configured methods; otherwise, None is
  178. + Returns just the account for the request, if it's an object
  179. + request and one of the configured methods; otherwise, None is
  180. returned.
  181. :param env: The WSGI environment for the request.
  182. - :returns: (Account str, container str) or (None, None).
  183. + :returns: Account str or None.
  184. """
  185. if env['REQUEST_METHOD'] in self.methods:
  186. try:
  187. ver, acc, cont, obj = split_path(env['PATH_INFO'], 4, 4, True)
  188. except ValueError:
  189. - return (None, None)
  190. + return None
  191. if ver == 'v1' and obj.strip('/'):
  192. - return (acc, cont)
  193. - return (None, None)
  194. + return acc
  195. def _get_temp_url_info(self, env):
  196. """
  197. @@ -470,23 +410,18 @@
  198. inline = True
  199. return temp_url_sig, temp_url_expires, filename, inline
  200. - def _get_keys(self, env):
  201. + def _get_keys(self, env, account):
  202. """
  203. Returns the X-[Account|Container]-Meta-Temp-URL-Key[-2] header values
  204. - for the account or container, or an empty list if none are set. Each
  205. - value comes as a 2-tuple (key, scope), where scope is either
  206. - CONTAINER_SCOPE or ACCOUNT_SCOPE.
  207. + for the account or container, or an empty list if none are set.
  208. Returns 0-4 elements depending on how many keys are set in the
  209. account's or container's metadata.
  210. :param env: The WSGI environment for the request.
  211. - :returns: [
  212. - (X-Account-Meta-Temp-URL-Key str value, ACCOUNT_SCOPE) if set,
  213. - (X-Account-Meta-Temp-URL-Key-2 str value, ACCOUNT_SCOPE if set,
  214. - (X-Container-Meta-Temp-URL-Key str value, CONTAINER_SCOPE) if set,
  215. - (X-Container-Meta-Temp-URL-Key-2 str value, CONTAINER_SCOPE if set,
  216. - ]
  217. + :param account: Account str.
  218. + :returns: [X-Account-Meta-Temp-URL-Key str value if set,
  219. + X-Account-Meta-Temp-URL-Key-2 str value if set]
  220. """
  221. account_info = get_account_info(env, self.app, swift_source='TU')
  222. account_keys = get_tempurl_keys_from_metadata(account_info['meta'])
  223. @@ -495,28 +430,25 @@
  224. container_keys = get_tempurl_keys_from_metadata(
  225. container_info.get('meta', []))
  226. - return ([(ak, ACCOUNT_SCOPE) for ak in account_keys] +
  227. - [(ck, CONTAINER_SCOPE) for ck in container_keys])
  228. + return account_keys + container_keys
  229. - def _get_hmacs(self, env, expires, scoped_keys, request_method=None):
  230. + def _get_hmacs(self, env, expires, keys, request_method=None):
  231. """
  232. :param env: The WSGI environment for the request.
  233. :param expires: Unix timestamp as an int for when the URL
  234. expires.
  235. - :param scoped_keys: (key, scope) tuples like _get_keys() returns
  236. + :param keys: Key strings, from the X-Account-Meta-Temp-URL-Key[-2] of
  237. + the account.
  238. :param request_method: Optional override of the request in
  239. the WSGI env. For example, if a HEAD
  240. does not match, you may wish to
  241. override with GET to still allow the
  242. HEAD.
  243. -
  244. - :returns: a list of (hmac, scope) 2-tuples
  245. """
  246. if not request_method:
  247. request_method = env['REQUEST_METHOD']
  248. - return [
  249. - (get_hmac(request_method, env['PATH_INFO'], expires, key), scope)
  250. - for (key, scope) in scoped_keys]
  251. + return [get_hmac(
  252. + request_method, env['PATH_INFO'], expires, key) for key in keys]
  253. def _invalid(self, env, start_response):
  254. """
  255. @@ -533,22 +465,6 @@
  256. body = '401 Unauthorized: Temp URL invalid\n'
  257. return HTTPUnauthorized(body=body)(env, start_response)
  258. - def _clean_disallowed_headers(self, env, start_response):
  259. - """
  260. - Validate the absense of disallowed headers for "unsafe" operations.
  261. -
  262. - :returns: None for safe operations or swob.HTTPBadResponse if the
  263. - request includes disallowed headers.
  264. - """
  265. - if env['REQUEST_METHOD'] in ('GET', 'HEAD', 'OPTIONS'):
  266. - return
  267. - for h in env:
  268. - if h in self.disallowed_headers:
  269. - return HTTPBadRequest(
  270. - body='The header %r is not allowed in this tempurl' %
  271. - h[len('HTTP_'):].title().replace('_', '-'))(
  272. - env, start_response)
  273. -
  274. def _clean_incoming_headers(self, env):
  275. """
  276. Removes any headers from the WSGI environment as per the
  277. diff -r -u -N --new-file swift/swift/proxy/server.py swift-kilo/swift/proxy/server.py
  278. --- swift/swift/proxy/server.py 2015-09-18 15:30:03.754723606 +0800
  279. +++ swift-kilo/swift/proxy/server.py 2015-09-18 16:43:36.111385171 +0800
  280. @@ -378,7 +378,6 @@
  281. allowed_methods = getattr(controller, 'allowed_methods', set())
  282. return HTTPMethodNotAllowed(
  283. request=req, headers={'Allow': ', '.join(allowed_methods)})
  284. - old_authorize = None
  285. if 'swift.authorize' in req.environ:
  286. # We call authorize before the handler, always. If authorized,
  287. # we remove the swift.authorize hook so isn't ever called
  288. @@ -389,7 +388,7 @@
  289. if not resp and not req.headers.get('X-Copy-From-Account') \
  290. and not req.headers.get('Destination-Account'):
  291. # No resp means authorized, no delayed recheck required.
  292. - old_authorize = req.environ['swift.authorize']
  293. + del req.environ['swift.authorize']
  294. else:
  295. # Response indicates denial, but we might delay the denial
  296. # and recheck later. If not delayed, return the error now.
  297. @@ -399,13 +398,7 @@
  298. # gets mutated during handling. This way logging can display the
  299. # method the client actually sent.
  300. req.environ['swift.orig_req_method'] = req.method
  301. - try:
  302. - if old_authorize:
  303. - req.environ.pop('swift.authorize', None)
  304. - return handler(req)
  305. - finally:
  306. - if old_authorize:
  307. - req.environ['swift.authorize'] = old_authorize
  308. + return handler(req)
  309. except HTTPException as error_response:
  310. return error_response
  311. except (Exception, Timeout):

其中,swift目录为最新版本的swift kilo/stable中源码;swift-kilo目录为四个月前下载的源码。

从上面的比较中,可以看出两个时段的代码略有区别,差异在百来行左右,主要集中于tempurl中间件代码中。这部分,与我动手修改的部分关系不大。唯一稍稍有关的代码更新,可能就是proxy server中代码更新。但仔细研究后发现,就是对旧的认证入口函数做了一个保存,在返回产生异常时,利用旧认证函数对env中认证函数进行赋值。相当于对代码逻辑的小小完善,对整体大流程不会有影响。

我想,我可以放心在最新kilo分支代码上进行修改,并利用它搭建系统,进行压力测试。

swift kilo版代码更新的更多相关文章

  1. Unity手游之路<十三>手游代码更新策略探讨

    http://blog.csdn.net/janeky/article/details/25923151 这几个月公司项目非常忙,加上家里事情也多,所以blog更新一直搁置了.最近在项目开发上线过程中 ...

  2. openstack【Kilo】汇总:包括20英文文档、各个组件新增功能及Kilo版部署

    OpenStack Kilo版本发布 20英文文档OpenStack Kilo版本文档汇总:各个操作系统安装部署.配置文档.用户指南等文档 Kilo版部署 openstack[Kilo]入门 [准备篇 ...

  3. Unity手游之路手游代码更新策略探讨

    版权声明: https://blog.csdn.net/janeky/article/details/25923151 这几个月公司项目非常忙.加上家里事情也多,所以blog更新一直搁置了. 近期在项 ...

  4. OpenStack Kilo版加CEPH部署手册

    OpenStack Kilo版加CEPH部署手册 作者: yz联系方式: QQ: 949587200日期: 2015-7-13版本: Kilo 转载地址: http://mp.weixin.qq.co ...

  5. Win10桌面预览版14316更新内容大全

    下载更新: 安装之后右下角: Win10桌面预览版14316更新内容:       Windows上运行乌班图Bash:通过设置开启开发者模式,更新和安全>面向开发人员.然后搜索"Wi ...

  6. 理解JavaScript设计模式与开发应用中发布-订阅模式的最终版代码

    最近拜读了曾探所著的<JavaScript设计模式与开发应用>一书,在读到发布-订阅模式一章时,作者不仅给出了基本模式的通用版本的发布-订阅模式的代码,最后还做出了扩展,给该模式增加了离线 ...

  7. WebGIS中以version方式实现代码更新后前端自动读取更新代码的方法

    文章版权由作者李晓晖和博客园共有,若转载请于明显处标明出处:http://www.cnblogs.com/naaoveGIS/ 1. 前言 GIS代码进行更新后,由于用户前端已有缓存,导致更新的功能不 ...

  8. 【剑指offer】Java版代码(完整版)

    原文地址:https://blog.csdn.net/baiye_xing/article/details/78428561 一.引言 <剑指offer>可谓是程序猿面试的神书了,在面试中 ...

  9. git如何merge github forked repository里的代码更新?(转)

    参考内容:git如何merge github forked repository里的代码更新? [refer to ]http://www.haojii.com/2011/08/how-to-git- ...

随机推荐

  1. 【js】callback时代的变更

    最近团队开始越来越多的使用es7标准的async/await,从最开始的promise到后面的generator,再到现在async,对于异步,每个时期都有着其特有的解决方案,今天笔者就以自己的接触为 ...

  2. 推荐一波 瀑布流的RecylceView

    推荐博客:http://www.bubuko.com/infodetail-999014.html

  3. [ZJOI2006]GameZ游戏排名系统

    Description GameZ为他们最新推出的游戏开通了一个网站.世界各地的玩家都可以将自己的游戏得分上传到网站上.这样就可以看到自己在世界上的排名.得分越高,排名就越靠前.当两个玩家的名次相同时 ...

  4. ACM_同余+暴力找规律

    小光的忧伤 Time Limit: 2000/1000ms (Java/Others) Problem Description: 锴神:我尊重作者原意,你们出什么我就加什么.于是小光打了道水题(也就是 ...

  5. C#将类对象转换为字典

    主要是实现将类里面 的属性和对应的值转换为字典的键和值. public class RDfsedfw { /// <summary> /// 将匿名类转换为字典 /// </summ ...

  6. 国际化------international

    1.配置web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi=& ...

  7. C++(extern关键字的理解和作用深入)

    extern关键字的理解和作用深入 extern是一个关键字,它告诉编译器存在着一个变量或者一个函数,如果在当前编译语句的前面中没有找到相应的变量或者函数, 也会在当前文件的后面或者其它文件中定义 引 ...

  8. Farseer.net轻量级开源框架 入门篇:使用前说明

    导航 目   录:Farseer.net轻量级开源框架 目录 上一篇:Farseer.net轻量级开源框架 入门篇: 框架性能测试 下一篇:Farseer.net轻量级开源框架 入门篇: 增.删.改. ...

  9. windows2008 rs+sql 2008 下配置站点权限

    几点注意 Windows 2008 iis7.5  1 建立应用程序池 2 文件目录的权限加上 IIS AppPool\应用程序池名称 (找不到直接录入) 3 文件目录要给 IUser权限,不然出错. ...

  10. java内存组成

     java内存组成介绍:堆(Heap)和非堆(Non-heap)内存 按照官方的说法:“Java 虚拟机具有一个堆,堆是运行时数据区域,所有类实例和数组的内存均从此处分配.堆是在 Java 虚拟机启动 ...