swift 2.23.3__py3-none-any.whl → 2.35.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (206) hide show
  1. swift/__init__.py +29 -50
  2. swift/account/auditor.py +21 -118
  3. swift/account/backend.py +33 -28
  4. swift/account/reaper.py +37 -28
  5. swift/account/replicator.py +22 -0
  6. swift/account/server.py +60 -26
  7. swift/account/utils.py +28 -11
  8. swift-2.23.3.data/scripts/swift-account-audit → swift/cli/account_audit.py +23 -13
  9. swift-2.23.3.data/scripts/swift-config → swift/cli/config.py +2 -2
  10. swift/cli/container_deleter.py +5 -11
  11. swift-2.23.3.data/scripts/swift-dispersion-populate → swift/cli/dispersion_populate.py +8 -7
  12. swift/cli/dispersion_report.py +10 -9
  13. swift-2.23.3.data/scripts/swift-drive-audit → swift/cli/drive_audit.py +63 -21
  14. swift/cli/form_signature.py +3 -7
  15. swift-2.23.3.data/scripts/swift-get-nodes → swift/cli/get_nodes.py +8 -2
  16. swift/cli/info.py +154 -14
  17. swift/cli/manage_shard_ranges.py +705 -37
  18. swift-2.23.3.data/scripts/swift-oldies → swift/cli/oldies.py +25 -14
  19. swift-2.23.3.data/scripts/swift-orphans → swift/cli/orphans.py +7 -3
  20. swift/cli/recon.py +196 -67
  21. swift-2.23.3.data/scripts/swift-recon-cron → swift/cli/recon_cron.py +17 -20
  22. swift-2.23.3.data/scripts/swift-reconciler-enqueue → swift/cli/reconciler_enqueue.py +2 -3
  23. swift/cli/relinker.py +807 -126
  24. swift/cli/reload.py +135 -0
  25. swift/cli/ringbuilder.py +217 -20
  26. swift/cli/ringcomposer.py +0 -1
  27. swift/cli/shard-info.py +4 -3
  28. swift/common/base_storage_server.py +9 -20
  29. swift/common/bufferedhttp.py +48 -74
  30. swift/common/constraints.py +20 -15
  31. swift/common/container_sync_realms.py +9 -11
  32. swift/common/daemon.py +25 -8
  33. swift/common/db.py +195 -128
  34. swift/common/db_auditor.py +168 -0
  35. swift/common/db_replicator.py +95 -55
  36. swift/common/digest.py +141 -0
  37. swift/common/direct_client.py +144 -33
  38. swift/common/error_limiter.py +93 -0
  39. swift/common/exceptions.py +25 -1
  40. swift/common/header_key_dict.py +2 -9
  41. swift/common/http_protocol.py +373 -0
  42. swift/common/internal_client.py +129 -59
  43. swift/common/linkat.py +3 -4
  44. swift/common/manager.py +284 -67
  45. swift/common/memcached.py +390 -145
  46. swift/common/middleware/__init__.py +4 -0
  47. swift/common/middleware/account_quotas.py +211 -46
  48. swift/common/middleware/acl.py +3 -8
  49. swift/common/middleware/backend_ratelimit.py +230 -0
  50. swift/common/middleware/bulk.py +22 -34
  51. swift/common/middleware/catch_errors.py +1 -3
  52. swift/common/middleware/cname_lookup.py +6 -11
  53. swift/common/middleware/container_quotas.py +1 -1
  54. swift/common/middleware/container_sync.py +39 -17
  55. swift/common/middleware/copy.py +12 -0
  56. swift/common/middleware/crossdomain.py +22 -9
  57. swift/common/middleware/crypto/__init__.py +2 -1
  58. swift/common/middleware/crypto/crypto_utils.py +11 -15
  59. swift/common/middleware/crypto/decrypter.py +28 -11
  60. swift/common/middleware/crypto/encrypter.py +12 -17
  61. swift/common/middleware/crypto/keymaster.py +8 -15
  62. swift/common/middleware/crypto/kms_keymaster.py +2 -1
  63. swift/common/middleware/dlo.py +15 -11
  64. swift/common/middleware/domain_remap.py +5 -4
  65. swift/common/middleware/etag_quoter.py +128 -0
  66. swift/common/middleware/formpost.py +73 -70
  67. swift/common/middleware/gatekeeper.py +8 -1
  68. swift/common/middleware/keystoneauth.py +33 -3
  69. swift/common/middleware/list_endpoints.py +4 -4
  70. swift/common/middleware/listing_formats.py +85 -49
  71. swift/common/middleware/memcache.py +4 -95
  72. swift/common/middleware/name_check.py +3 -2
  73. swift/common/middleware/proxy_logging.py +160 -92
  74. swift/common/middleware/ratelimit.py +17 -10
  75. swift/common/middleware/read_only.py +6 -4
  76. swift/common/middleware/recon.py +59 -22
  77. swift/common/middleware/s3api/acl_handlers.py +25 -3
  78. swift/common/middleware/s3api/acl_utils.py +6 -1
  79. swift/common/middleware/s3api/controllers/__init__.py +6 -0
  80. swift/common/middleware/s3api/controllers/acl.py +3 -2
  81. swift/common/middleware/s3api/controllers/bucket.py +242 -137
  82. swift/common/middleware/s3api/controllers/logging.py +2 -2
  83. swift/common/middleware/s3api/controllers/multi_delete.py +43 -20
  84. swift/common/middleware/s3api/controllers/multi_upload.py +219 -133
  85. swift/common/middleware/s3api/controllers/obj.py +112 -8
  86. swift/common/middleware/s3api/controllers/object_lock.py +44 -0
  87. swift/common/middleware/s3api/controllers/s3_acl.py +2 -2
  88. swift/common/middleware/s3api/controllers/tagging.py +57 -0
  89. swift/common/middleware/s3api/controllers/versioning.py +36 -7
  90. swift/common/middleware/s3api/etree.py +22 -9
  91. swift/common/middleware/s3api/exception.py +0 -4
  92. swift/common/middleware/s3api/s3api.py +113 -41
  93. swift/common/middleware/s3api/s3request.py +384 -218
  94. swift/common/middleware/s3api/s3response.py +126 -23
  95. swift/common/middleware/s3api/s3token.py +16 -17
  96. swift/common/middleware/s3api/schema/delete.rng +1 -1
  97. swift/common/middleware/s3api/subresource.py +7 -10
  98. swift/common/middleware/s3api/utils.py +27 -10
  99. swift/common/middleware/slo.py +665 -358
  100. swift/common/middleware/staticweb.py +64 -37
  101. swift/common/middleware/symlink.py +51 -18
  102. swift/common/middleware/tempauth.py +76 -58
  103. swift/common/middleware/tempurl.py +191 -173
  104. swift/common/middleware/versioned_writes/__init__.py +51 -0
  105. swift/common/middleware/{versioned_writes.py → versioned_writes/legacy.py} +27 -26
  106. swift/common/middleware/versioned_writes/object_versioning.py +1482 -0
  107. swift/common/middleware/x_profile/exceptions.py +1 -4
  108. swift/common/middleware/x_profile/html_viewer.py +18 -19
  109. swift/common/middleware/x_profile/profile_model.py +1 -2
  110. swift/common/middleware/xprofile.py +10 -10
  111. swift-2.23.3.data/scripts/swift-container-server → swift/common/recon.py +13 -8
  112. swift/common/registry.py +147 -0
  113. swift/common/request_helpers.py +324 -57
  114. swift/common/ring/builder.py +67 -25
  115. swift/common/ring/composite_builder.py +1 -1
  116. swift/common/ring/ring.py +177 -51
  117. swift/common/ring/utils.py +1 -1
  118. swift/common/splice.py +10 -6
  119. swift/common/statsd_client.py +205 -0
  120. swift/common/storage_policy.py +49 -44
  121. swift/common/swob.py +86 -102
  122. swift/common/{utils.py → utils/__init__.py} +2163 -2772
  123. swift/common/utils/base.py +131 -0
  124. swift/common/utils/config.py +433 -0
  125. swift/common/utils/ipaddrs.py +256 -0
  126. swift/common/utils/libc.py +345 -0
  127. swift/common/utils/logs.py +859 -0
  128. swift/common/utils/timestamp.py +412 -0
  129. swift/common/wsgi.py +553 -535
  130. swift/container/auditor.py +14 -100
  131. swift/container/backend.py +490 -231
  132. swift/container/reconciler.py +126 -37
  133. swift/container/replicator.py +96 -22
  134. swift/container/server.py +358 -165
  135. swift/container/sharder.py +1540 -684
  136. swift/container/sync.py +94 -88
  137. swift/container/updater.py +53 -32
  138. swift/obj/auditor.py +153 -35
  139. swift/obj/diskfile.py +466 -217
  140. swift/obj/expirer.py +406 -124
  141. swift/obj/mem_diskfile.py +7 -4
  142. swift/obj/mem_server.py +1 -0
  143. swift/obj/reconstructor.py +523 -262
  144. swift/obj/replicator.py +249 -188
  145. swift/obj/server.py +207 -122
  146. swift/obj/ssync_receiver.py +145 -85
  147. swift/obj/ssync_sender.py +113 -54
  148. swift/obj/updater.py +652 -139
  149. swift/obj/watchers/__init__.py +0 -0
  150. swift/obj/watchers/dark_data.py +213 -0
  151. swift/proxy/controllers/account.py +11 -11
  152. swift/proxy/controllers/base.py +848 -604
  153. swift/proxy/controllers/container.py +433 -92
  154. swift/proxy/controllers/info.py +3 -2
  155. swift/proxy/controllers/obj.py +1000 -489
  156. swift/proxy/server.py +185 -112
  157. {swift-2.23.3.dist-info → swift-2.35.0.dist-info}/AUTHORS +58 -11
  158. {swift-2.23.3.dist-info → swift-2.35.0.dist-info}/METADATA +51 -56
  159. swift-2.35.0.dist-info/RECORD +201 -0
  160. {swift-2.23.3.dist-info → swift-2.35.0.dist-info}/WHEEL +1 -1
  161. {swift-2.23.3.dist-info → swift-2.35.0.dist-info}/entry_points.txt +43 -0
  162. swift-2.35.0.dist-info/pbr.json +1 -0
  163. swift/locale/de/LC_MESSAGES/swift.po +0 -1216
  164. swift/locale/en_GB/LC_MESSAGES/swift.po +0 -1207
  165. swift/locale/es/LC_MESSAGES/swift.po +0 -1085
  166. swift/locale/fr/LC_MESSAGES/swift.po +0 -909
  167. swift/locale/it/LC_MESSAGES/swift.po +0 -894
  168. swift/locale/ja/LC_MESSAGES/swift.po +0 -965
  169. swift/locale/ko_KR/LC_MESSAGES/swift.po +0 -964
  170. swift/locale/pt_BR/LC_MESSAGES/swift.po +0 -881
  171. swift/locale/ru/LC_MESSAGES/swift.po +0 -891
  172. swift/locale/tr_TR/LC_MESSAGES/swift.po +0 -832
  173. swift/locale/zh_CN/LC_MESSAGES/swift.po +0 -833
  174. swift/locale/zh_TW/LC_MESSAGES/swift.po +0 -838
  175. swift-2.23.3.data/scripts/swift-account-auditor +0 -23
  176. swift-2.23.3.data/scripts/swift-account-info +0 -51
  177. swift-2.23.3.data/scripts/swift-account-reaper +0 -23
  178. swift-2.23.3.data/scripts/swift-account-replicator +0 -34
  179. swift-2.23.3.data/scripts/swift-account-server +0 -23
  180. swift-2.23.3.data/scripts/swift-container-auditor +0 -23
  181. swift-2.23.3.data/scripts/swift-container-info +0 -55
  182. swift-2.23.3.data/scripts/swift-container-reconciler +0 -21
  183. swift-2.23.3.data/scripts/swift-container-replicator +0 -34
  184. swift-2.23.3.data/scripts/swift-container-sharder +0 -37
  185. swift-2.23.3.data/scripts/swift-container-sync +0 -23
  186. swift-2.23.3.data/scripts/swift-container-updater +0 -23
  187. swift-2.23.3.data/scripts/swift-dispersion-report +0 -24
  188. swift-2.23.3.data/scripts/swift-form-signature +0 -20
  189. swift-2.23.3.data/scripts/swift-init +0 -119
  190. swift-2.23.3.data/scripts/swift-object-auditor +0 -29
  191. swift-2.23.3.data/scripts/swift-object-expirer +0 -33
  192. swift-2.23.3.data/scripts/swift-object-info +0 -60
  193. swift-2.23.3.data/scripts/swift-object-reconstructor +0 -33
  194. swift-2.23.3.data/scripts/swift-object-relinker +0 -41
  195. swift-2.23.3.data/scripts/swift-object-replicator +0 -37
  196. swift-2.23.3.data/scripts/swift-object-server +0 -27
  197. swift-2.23.3.data/scripts/swift-object-updater +0 -23
  198. swift-2.23.3.data/scripts/swift-proxy-server +0 -23
  199. swift-2.23.3.data/scripts/swift-recon +0 -24
  200. swift-2.23.3.data/scripts/swift-ring-builder +0 -24
  201. swift-2.23.3.data/scripts/swift-ring-builder-analyzer +0 -22
  202. swift-2.23.3.data/scripts/swift-ring-composer +0 -22
  203. swift-2.23.3.dist-info/RECORD +0 -220
  204. swift-2.23.3.dist-info/pbr.json +0 -1
  205. {swift-2.23.3.dist-info → swift-2.35.0.dist-info}/LICENSE +0 -0
  206. {swift-2.23.3.dist-info → swift-2.35.0.dist-info}/top_level.txt +0 -0
@@ -13,16 +13,13 @@
13
13
  # See the License for the specific language governing permissions and
14
14
  # limitations under the License.
15
15
 
16
- from swift import gettext_ as _
17
-
18
-
19
16
  class ProfileException(Exception):
20
17
 
21
18
  def __init__(self, msg):
22
19
  self.msg = msg
23
20
 
24
21
  def __str__(self):
25
- return _('Profiling Error: %s') % self.msg
22
+ return 'Profiling Error: %s' % self.msg
26
23
 
27
24
 
28
25
  class NotFoundException(ProfileException):
@@ -13,14 +13,13 @@
13
13
  # See the License for the specific language governing permissions and
14
14
  # limitations under the License.
15
15
 
16
- import cgi
16
+ import html
17
17
  import os
18
18
  import random
19
19
  import re
20
20
  import string
21
21
  import tempfile
22
22
 
23
- from swift import gettext_ as _
24
23
  from swift.common.middleware.x_profile.exceptions import PLOTLIBNotInstalled
25
24
  from swift.common.middleware.x_profile.exceptions import ODFLIBNotInstalled
26
25
  from swift.common.middleware.x_profile.exceptions import NotFoundException
@@ -246,7 +245,7 @@ class HTMLViewer(object):
246
245
  if multiple:
247
246
  return value
248
247
  if isinstance(value, list):
249
- return eval(value[0]) if isinstance(default, int) else value[0]
248
+ return int(value[0]) if isinstance(default, int) else value[0]
250
249
  else:
251
250
  return value
252
251
 
@@ -307,7 +306,7 @@ class HTMLViewer(object):
307
306
  nfl_filter, download_format)
308
307
  headers.append(('Access-Control-Allow-Origin', '*'))
309
308
  else:
310
- raise MethodNotAllowed(_('method %s is not allowed.') % method)
309
+ raise MethodNotAllowed('method %s is not allowed.' % method)
311
310
  return content, headers
312
311
 
313
312
  def index_page(self, log_files=None, sort='time', limit=-1,
@@ -318,12 +317,12 @@ class HTMLViewer(object):
318
317
  try:
319
318
  stats = Stats2(*log_files)
320
319
  except (IOError, ValueError):
321
- raise DataLoadFailure(_('Can not load profile data from %s.')
320
+ raise DataLoadFailure('Can not load profile data from %s.'
322
321
  % log_files)
323
322
  if not fulldirs:
324
323
  stats.strip_dirs()
325
324
  stats.sort_stats(sort)
326
- nfl_filter_esc = nfl_filter.replace('(', '\(').replace(')', '\)')
325
+ nfl_filter_esc = nfl_filter.replace(r'(', r'\(').replace(r')', r'\)')
327
326
  amount = [nfl_filter_esc, limit] if nfl_filter_esc else [limit]
328
327
  profile_html = self.generate_stats_html(stats, self.app_path,
329
328
  profile_id, *amount)
@@ -369,9 +368,9 @@ class HTMLViewer(object):
369
368
  def download(self, log_files, sort='time', limit=-1, nfl_filter='',
370
369
  output_format='default'):
371
370
  if len(log_files) == 0:
372
- raise NotFoundException(_('no log file found'))
371
+ raise NotFoundException('no log file found')
373
372
  try:
374
- nfl_esc = nfl_filter.replace('(', '\(').replace(')', '\)')
373
+ nfl_esc = nfl_filter.replace(r'(', r'\(').replace(r')', r'\)')
375
374
  # remove the slash that is intentionally added in the URL
376
375
  # to avoid failure of filtering stats data.
377
376
  if nfl_esc.startswith('/'):
@@ -392,14 +391,14 @@ class HTMLViewer(object):
392
391
  except ODFLIBNotInstalled:
393
392
  raise
394
393
  except Exception as ex:
395
- raise ProfileException(_('Data download error: %s') % ex)
394
+ raise ProfileException('Data download error: %s' % ex)
396
395
 
397
396
  def plot(self, log_files, sort='time', limit=10, nfl_filter='',
398
397
  metric_selected='cc', plot_type='bar'):
399
398
  if not PLOTLIB_INSTALLED:
400
- raise PLOTLIBNotInstalled(_('python-matplotlib not installed.'))
399
+ raise PLOTLIBNotInstalled('python-matplotlib not installed.')
401
400
  if len(log_files) == 0:
402
- raise NotFoundException(_('no log file found'))
401
+ raise NotFoundException('no log file found')
403
402
  try:
404
403
  stats = Stats2(*log_files)
405
404
  stats.sort_stats(sort)
@@ -433,7 +432,7 @@ class HTMLViewer(object):
433
432
  data = profile_img.read()
434
433
  return data, [('content-type', 'image/jpg')]
435
434
  except Exception as ex:
436
- raise ProfileException(_('plotting results failed due to %s') % ex)
435
+ raise ProfileException('plotting results failed due to %s' % ex)
437
436
 
438
437
  def format_source_code(self, nfl):
439
438
  nfls = re.split('[:()]', nfl)
@@ -444,7 +443,7 @@ class HTMLViewer(object):
444
443
  lineno = 0
445
444
  # for security reason, this need to be fixed.
446
445
  if not file_path.endswith('.py'):
447
- return _('The file type are forbidden to access!')
446
+ return 'The file type are forbidden to access!'
448
447
  try:
449
448
  data = []
450
449
  i = 0
@@ -454,18 +453,18 @@ class HTMLViewer(object):
454
453
  fmt = '<span id="L%d" rel="#L%d">%' + max_width\
455
454
  + 'd|<code>%s</code></span>'
456
455
  for line in lines:
457
- l = cgi.escape(line, quote=None)
456
+ el = html.escape(line)
458
457
  i = i + 1
459
458
  if i == lineno:
460
459
  fmt2 = '<span id="L%d" style="background-color: \
461
460
  rgb(127,255,127)">%' + max_width +\
462
461
  'd|<code>%s</code></span>'
463
- data.append(fmt2 % (i, i, l))
462
+ data.append(fmt2 % (i, i, el))
464
463
  else:
465
- data.append(fmt % (i, i, i, l))
464
+ data.append(fmt % (i, i, i, el))
466
465
  data = ''.join(data)
467
466
  except Exception:
468
- return _('Can not access the file %s.') % file_path
467
+ return 'Can not access the file %s.' % file_path
469
468
  return '<pre>%s</pre>' % data
470
469
 
471
470
  def generate_stats_html(self, stats, app_path, profile_id, *selection):
@@ -518,7 +517,7 @@ class HTMLViewer(object):
518
517
  html.append('<td>-</td>')
519
518
  else:
520
519
  html.append('<td>%f</td>' % (float(ct) / cc))
521
- nfls = cgi.escape(stats.func_std_string(func))
520
+ nfls = html.escape(stats.func_std_string(func))
522
521
  if nfls.split(':')[0] not in ['', 'profile'] and\
523
522
  os.path.isfile(nfls.split(':')[0]):
524
523
  html.append('<td><a href="%s/%s%s?format=python#L%d">\
@@ -532,5 +531,5 @@ class HTMLViewer(object):
532
531
  --></a></td></tr>' % (app_path,
533
532
  profile_id, nfls))
534
533
  except Exception as ex:
535
- html.append("Exception:" % str(ex))
534
+ html.append("Exception:" + str(ex))
536
535
  return ''.join(html)
@@ -20,7 +20,6 @@ import pstats
20
20
  import tempfile
21
21
  import time
22
22
 
23
- from swift import gettext_ as _
24
23
  from swift.common.middleware.x_profile.exceptions import ODFLIBNotInstalled
25
24
 
26
25
 
@@ -125,7 +124,7 @@ class Stats2(pstats.Stats):
125
124
 
126
125
  def to_ods(self, *selection):
127
126
  if not ODFLIB_INSTALLED:
128
- raise ODFLIBNotInstalled(_('odfpy not installed.'))
127
+ raise ODFLIBNotInstalled('odfpy not installed.')
129
128
  if self.fcn_list:
130
129
  stat_list = self.fcn_list[:]
131
130
  order_text = " Ordered by: " + self.sort_type + '\n'
@@ -16,6 +16,11 @@
16
16
  """
17
17
  Profiling middleware for Swift Servers.
18
18
 
19
+ .. note::
20
+ This middleware is intended for development and testing environments only,
21
+ not production. No authentication is expected or required for the web UI,
22
+ and profiling may incur noticeable performance penalties.
23
+
19
24
  The current implementation is based on eventlet aware profiler.(For the
20
25
  future, more profilers could be added in to collect more data for analysis.)
21
26
  Profiling all incoming requests and accumulating cpu timing statistics
@@ -80,10 +85,8 @@ import time
80
85
 
81
86
  from eventlet import greenthread, GreenPool, patcher
82
87
  import eventlet.green.profile as eprofile
83
- import six
84
- from six.moves import urllib
88
+ import urllib
85
89
 
86
- from swift import gettext_ as _
87
90
  from swift.common.utils import get_logger, config_true_value
88
91
  from swift.common.swob import Request
89
92
  from swift.common.middleware.x_profile.exceptions import MethodNotAllowed
@@ -93,7 +96,7 @@ from swift.common.middleware.x_profile.html_viewer import HTMLViewer
93
96
  from swift.common.middleware.x_profile.profile_model import ProfileLog
94
97
 
95
98
 
96
- DEFAULT_PROFILE_PREFIX = '/tmp/log/swift/profile/default.profile'
99
+ DEFAULT_PROFILE_PREFIX = '/tmp/log/swift/profile/default.profile' # nosec B108
97
100
 
98
101
  # unwind the iterator; it may call start_response, do lots of work, etc
99
102
  PROFILE_EXEC_EAGER = """
@@ -108,10 +111,7 @@ PROFILE_EXEC_LAZY = """
108
111
  app_iter_ = self.app(environ, start_response)
109
112
  """
110
113
 
111
- if six.PY3:
112
- thread = patcher.original('_thread') # non-monkeypatched module needed
113
- else:
114
- thread = patcher.original('thread') # non-monkeypatched module needed
114
+ thread = patcher.original('_thread') # non-monkeypatched module needed
115
115
 
116
116
 
117
117
  # This monkey patch code fix the problem of eventlet profile tool
@@ -213,7 +213,7 @@ class ProfileMiddleware(object):
213
213
  query_dict,
214
214
  self.renew_profile)
215
215
  start_response('200 OK', headers)
216
- if isinstance(content, six.text_type):
216
+ if isinstance(content, str):
217
217
  content = content.encode('utf-8')
218
218
  return [content]
219
219
  except MethodNotAllowed as mx:
@@ -227,7 +227,7 @@ class ProfileMiddleware(object):
227
227
  return '%s' % pf
228
228
  except Exception as ex:
229
229
  start_response('500 Internal Server Error', [])
230
- return _('Error on render profiling results: %s') % ex
230
+ return 'Error on render profiling results: %s' % ex
231
231
  else:
232
232
  _locals = locals()
233
233
  code = self.unwind and PROFILE_EXEC_EAGER or\
@@ -1,5 +1,4 @@
1
- #!python
2
- # Copyright (c) 2010-2012 OpenStack Foundation
1
+ # Copyright (c) 2010-2021 OpenStack Foundation
3
2
  #
4
3
  # Licensed under the Apache License, Version 2.0 (the "License");
5
4
  # you may not use this file except in compliance with the License.
@@ -14,10 +13,16 @@
14
13
  # See the License for the specific language governing permissions and
15
14
  # limitations under the License.
16
15
 
17
- import sys
18
- from swift.common.utils import parse_options
19
- from swift.common.wsgi import run_wsgi
16
+ RECON_RELINKER_FILE = 'relinker.recon'
17
+ RECON_OBJECT_FILE = 'object.recon'
18
+ RECON_CONTAINER_FILE = 'container.recon'
19
+ RECON_ACCOUNT_FILE = 'account.recon'
20
+ RECON_DRIVE_FILE = 'drive.recon'
21
+ DEFAULT_RECON_CACHE_PATH = '/var/cache/swift'
20
22
 
21
- if __name__ == '__main__':
22
- conf_file, options = parse_options()
23
- sys.exit(run_wsgi(conf_file, 'container-server', **options))
23
+
24
+ def server_type_to_recon_file(server_type):
25
+ if not isinstance(server_type, str) or \
26
+ server_type.lower() not in ('account', 'container', 'object'):
27
+ raise ValueError('Invalid server_type')
28
+ return "%s.recon" % server_type.lower()
@@ -0,0 +1,147 @@
1
+ # Copyright (c) 2022 NVIDIA
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12
+ # implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ # Used by get_swift_info and register_swift_info to store information about
17
+ # the swift cluster.
18
+ from copy import deepcopy
19
+
20
+ _swift_info = {}
21
+ _swift_admin_info = {}
22
+
23
+
24
+ def get_swift_info(admin=False, disallowed_sections=None):
25
+ """
26
+ Returns information about the swift cluster that has been previously
27
+ registered with the register_swift_info call.
28
+
29
+ :param admin: boolean value, if True will additionally return an 'admin'
30
+ section with information previously registered as admin
31
+ info.
32
+ :param disallowed_sections: list of section names to be withheld from the
33
+ information returned.
34
+ :returns: dictionary of information about the swift cluster.
35
+ """
36
+ disallowed_sections = disallowed_sections or []
37
+ info = deepcopy(_swift_info)
38
+ for section in disallowed_sections:
39
+ key_to_pop = None
40
+ sub_section_dict = info
41
+ for sub_section in section.split('.'):
42
+ if key_to_pop:
43
+ sub_section_dict = sub_section_dict.get(key_to_pop, {})
44
+ if not isinstance(sub_section_dict, dict):
45
+ sub_section_dict = {}
46
+ break
47
+ key_to_pop = sub_section
48
+ sub_section_dict.pop(key_to_pop, None)
49
+
50
+ if admin:
51
+ info['admin'] = dict(_swift_admin_info)
52
+ info['admin']['disallowed_sections'] = list(disallowed_sections)
53
+ return info
54
+
55
+
56
+ def register_swift_info(name='swift', admin=False, **kwargs):
57
+ """
58
+ Registers information about the swift cluster to be retrieved with calls
59
+ to get_swift_info.
60
+
61
+ NOTE: Do not use "." in the param: name or any keys in kwargs. "." is used
62
+ in the disallowed_sections to remove unwanted keys from /info.
63
+
64
+ :param name: string, the section name to place the information under.
65
+ :param admin: boolean, if True, information will be registered to an
66
+ admin section which can optionally be withheld when
67
+ requesting the information.
68
+ :param kwargs: key value arguments representing the information to be
69
+ added.
70
+ :raises ValueError: if name or any of the keys in kwargs has "." in it
71
+ """
72
+ if name == 'admin' or name == 'disallowed_sections':
73
+ raise ValueError('\'{0}\' is reserved name.'.format(name))
74
+
75
+ if admin:
76
+ dict_to_use = _swift_admin_info
77
+ else:
78
+ dict_to_use = _swift_info
79
+ if name not in dict_to_use:
80
+ if "." in name:
81
+ raise ValueError('Cannot use "." in a swift_info key: %s' % name)
82
+ dict_to_use[name] = {}
83
+ for key, val in kwargs.items():
84
+ if "." in key:
85
+ raise ValueError('Cannot use "." in a swift_info key: %s' % key)
86
+ dict_to_use[name][key] = val
87
+
88
+
89
+ _sensitive_headers = set()
90
+ _sensitive_params = set()
91
+
92
+
93
+ def get_sensitive_headers():
94
+ """
95
+ Returns the set of registered sensitive headers.
96
+
97
+ Used by :mod:`swift.common.middleware.proxy_logging` to perform redactions
98
+ prior to logging.
99
+ """
100
+ return frozenset(_sensitive_headers)
101
+
102
+
103
+ def register_sensitive_header(header):
104
+ """
105
+ Register a header as being "sensitive".
106
+
107
+ Sensitive headers are automatically redacted when logging. See the
108
+ ``reveal_sensitive_prefix`` option in the proxy-server sample config
109
+ for more information.
110
+
111
+ :param header: The (case-insensitive) header name which, if present, may
112
+ contain sensitive information. Examples include ``X-Auth-Token`` and
113
+ (if s3api is enabled) ``Authorization``. Limited to ASCII characters.
114
+ """
115
+ if not isinstance(header, str):
116
+ raise TypeError
117
+ header.encode('ascii')
118
+ _sensitive_headers.add(header.lower())
119
+
120
+
121
+ def get_sensitive_params():
122
+ """
123
+ Returns the set of registered sensitive query parameters.
124
+
125
+ Used by :mod:`swift.common.middleware.proxy_logging` to perform redactions
126
+ prior to logging.
127
+ """
128
+ return frozenset(_sensitive_params)
129
+
130
+
131
+ def register_sensitive_param(query_param):
132
+ """
133
+ Register a query parameter as being "sensitive".
134
+
135
+ Sensitive query parameters are automatically redacted when logging. See
136
+ the ``reveal_sensitive_prefix`` option in the proxy-server sample config
137
+ for more information.
138
+
139
+ :param query_param: The (case-sensitive) query parameter name which, if
140
+ present, may contain sensitive information. Examples include
141
+ ``temp_url_signature`` and (if s3api is enabled) ``X-Amz-Signature``.
142
+ Limited to ASCII characters.
143
+ """
144
+ if not isinstance(query_param, str):
145
+ raise TypeError
146
+ query_param.encode('ascii')
147
+ _sensitive_params.add(query_param)