root / pithos / backends / modular.py @ 33b4e4a6
History | View | Annotate | Download (44.8 kB)
1 |
# Copyright 2011-2012 GRNET S.A. All rights reserved.
|
---|---|
2 |
#
|
3 |
# Redistribution and use in source and binary forms, with or
|
4 |
# without modification, are permitted provided that the following
|
5 |
# conditions are met:
|
6 |
#
|
7 |
# 1. Redistributions of source code must retain the above
|
8 |
# copyright notice, this list of conditions and the following
|
9 |
# disclaimer.
|
10 |
#
|
11 |
# 2. Redistributions in binary form must reproduce the above
|
12 |
# copyright notice, this list of conditions and the following
|
13 |
# disclaimer in the documentation and/or other materials
|
14 |
# provided with the distribution.
|
15 |
#
|
16 |
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
|
17 |
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
18 |
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
19 |
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
|
20 |
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
21 |
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
22 |
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
23 |
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
24 |
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
25 |
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
26 |
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
27 |
# POSSIBILITY OF SUCH DAMAGE.
|
28 |
#
|
29 |
# The views and conclusions contained in the software and
|
30 |
# documentation are those of the authors and should not be
|
31 |
# interpreted as representing official policies, either expressed
|
32 |
# or implied, of GRNET S.A.
|
33 |
|
34 |
import sys |
35 |
import os |
36 |
import time |
37 |
import uuid as uuidlib |
38 |
import logging |
39 |
import binascii |
40 |
|
41 |
from base import DEFAULT_QUOTA, DEFAULT_VERSIONING, NotAllowedError, QuotaError, BaseBackend |
42 |
|
43 |
from pithos.lib.hashmap import HashMap |
44 |
|
45 |
# Default modules and settings.
|
46 |
DEFAULT_DB_MODULE = 'pithos.backends.lib.sqlalchemy'
|
47 |
DEFAULT_DB_CONNECTION = 'sqlite:///backend.db'
|
48 |
DEFAULT_BLOCK_MODULE = 'pithos.backends.lib.hashfiler'
|
49 |
DEFAULT_BLOCK_PATH = 'data/'
|
50 |
#DEFAULT_QUEUE_MODULE = 'pithos.backends.lib.rabbitmq'
|
51 |
#DEFAULT_QUEUE_CONNECTION = 'rabbitmq://guest:guest@localhost:5672/pithos'
|
52 |
|
53 |
QUEUE_MESSAGE_KEY = '#'
|
54 |
QUEUE_CLIENT_ID = 2 # Pithos. |
55 |
|
56 |
( CLUSTER_NORMAL, CLUSTER_HISTORY, CLUSTER_DELETED ) = range(3) |
57 |
|
58 |
inf = float('inf') |
59 |
|
60 |
ULTIMATE_ANSWER = 42
|
61 |
|
62 |
|
63 |
logger = logging.getLogger(__name__) |
64 |
|
65 |
|
66 |
def backend_method(func=None, autocommit=1): |
67 |
if func is None: |
68 |
def fn(func): |
69 |
return backend_method(func, autocommit)
|
70 |
return fn
|
71 |
|
72 |
if not autocommit: |
73 |
return func
|
74 |
def fn(self, *args, **kw): |
75 |
self.wrapper.execute()
|
76 |
try:
|
77 |
ret = func(self, *args, **kw)
|
78 |
self.wrapper.commit()
|
79 |
return ret
|
80 |
except:
|
81 |
self.wrapper.rollback()
|
82 |
raise
|
83 |
return fn
|
84 |
|
85 |
|
86 |
class ModularBackend(BaseBackend): |
87 |
"""A modular backend.
|
88 |
|
89 |
Uses modules for SQL functions and storage.
|
90 |
"""
|
91 |
|
92 |
def __init__(self, db_module=None, db_connection=None, |
93 |
block_module=None, block_path=None, |
94 |
queue_module=None, queue_connection=None): |
95 |
db_module = db_module or DEFAULT_DB_MODULE
|
96 |
db_connection = db_connection or DEFAULT_DB_CONNECTION
|
97 |
block_module = block_module or DEFAULT_BLOCK_MODULE
|
98 |
block_path = block_path or DEFAULT_BLOCK_PATH
|
99 |
#queue_module = queue_module or DEFAULT_QUEUE_MODULE
|
100 |
#queue_connection = queue_connection or DEFAULT_QUEUE_CONNECTION
|
101 |
|
102 |
self.hash_algorithm = 'sha256' |
103 |
self.block_size = 4 * 1024 * 1024 # 4MB |
104 |
|
105 |
self.default_policy = {'quota': DEFAULT_QUOTA, 'versioning': DEFAULT_VERSIONING} |
106 |
|
107 |
def load_module(m): |
108 |
__import__(m)
|
109 |
return sys.modules[m]
|
110 |
|
111 |
self.db_module = load_module(db_module)
|
112 |
self.wrapper = self.db_module.DBWrapper(db_connection) |
113 |
params = {'wrapper': self.wrapper} |
114 |
self.permissions = self.db_module.Permissions(**params) |
115 |
for x in ['READ', 'WRITE']: |
116 |
setattr(self, x, getattr(self.db_module, x)) |
117 |
self.node = self.db_module.Node(**params) |
118 |
for x in ['ROOTNODE', 'SERIAL', 'HASH', 'SIZE', 'TYPE', 'MTIME', 'MUSER', 'UUID', 'CHECKSUM', 'CLUSTER', 'MATCH_PREFIX', 'MATCH_EXACT']: |
119 |
setattr(self, x, getattr(self.db_module, x)) |
120 |
|
121 |
self.block_module = load_module(block_module)
|
122 |
params = {'path': block_path,
|
123 |
'block_size': self.block_size, |
124 |
'hash_algorithm': self.hash_algorithm} |
125 |
self.store = self.block_module.Store(**params) |
126 |
|
127 |
if queue_module and queue_connection: |
128 |
self.queue_module = load_module(queue_module)
|
129 |
params = {'exchange': queue_connection,
|
130 |
'message_key': QUEUE_MESSAGE_KEY,
|
131 |
'client_id': QUEUE_CLIENT_ID}
|
132 |
self.queue = self.queue_module.Queue(**params) |
133 |
else:
|
134 |
class NoQueue: |
135 |
def send(self, *args): |
136 |
pass
|
137 |
|
138 |
def close(self): |
139 |
pass
|
140 |
|
141 |
self.queue = NoQueue()
|
142 |
|
143 |
def close(self): |
144 |
self.wrapper.close()
|
145 |
self.queue.close()
|
146 |
|
147 |
@backend_method
|
148 |
def list_accounts(self, user, marker=None, limit=10000): |
149 |
"""Return a list of accounts the user can access."""
|
150 |
|
151 |
logger.debug("list_accounts: %s %s %s", user, marker, limit)
|
152 |
allowed = self._allowed_accounts(user)
|
153 |
start, limit = self._list_limits(allowed, marker, limit)
|
154 |
return allowed[start:start + limit]
|
155 |
|
156 |
@backend_method
|
157 |
def get_account_meta(self, user, account, domain, until=None): |
158 |
"""Return a dictionary with the account metadata for the domain."""
|
159 |
|
160 |
logger.debug("get_account_meta: %s %s %s", account, domain, until)
|
161 |
path, node = self._lookup_account(account, user == account)
|
162 |
if user != account:
|
163 |
if until or node is None or account not in self._allowed_accounts(user): |
164 |
raise NotAllowedError
|
165 |
try:
|
166 |
props = self._get_properties(node, until)
|
167 |
mtime = props[self.MTIME]
|
168 |
except NameError: |
169 |
props = None
|
170 |
mtime = until |
171 |
count, bytes, tstamp = self._get_statistics(node, until) |
172 |
tstamp = max(tstamp, mtime)
|
173 |
if until is None: |
174 |
modified = tstamp |
175 |
else:
|
176 |
modified = self._get_statistics(node)[2] # Overall last modification. |
177 |
modified = max(modified, mtime)
|
178 |
|
179 |
if user != account:
|
180 |
meta = {'name': account}
|
181 |
else:
|
182 |
meta = {} |
183 |
if props is not None: |
184 |
meta.update(dict(self.node.attribute_get(props[self.SERIAL], domain))) |
185 |
if until is not None: |
186 |
meta.update({'until_timestamp': tstamp})
|
187 |
meta.update({'name': account, 'count': count, 'bytes': bytes}) |
188 |
meta.update({'modified': modified})
|
189 |
return meta
|
190 |
|
191 |
@backend_method
|
192 |
def update_account_meta(self, user, account, domain, meta, replace=False): |
193 |
"""Update the metadata associated with the account for the domain."""
|
194 |
|
195 |
logger.debug("update_account_meta: %s %s %s %s", account, domain, meta, replace)
|
196 |
if user != account:
|
197 |
raise NotAllowedError
|
198 |
path, node = self._lookup_account(account, True) |
199 |
self._put_metadata(user, node, domain, meta, replace)
|
200 |
|
201 |
@backend_method
|
202 |
def get_account_groups(self, user, account): |
203 |
"""Return a dictionary with the user groups defined for this account."""
|
204 |
|
205 |
logger.debug("get_account_groups: %s", account)
|
206 |
if user != account:
|
207 |
if account not in self._allowed_accounts(user): |
208 |
raise NotAllowedError
|
209 |
return {}
|
210 |
self._lookup_account(account, True) |
211 |
return self.permissions.group_dict(account) |
212 |
|
213 |
@backend_method
|
214 |
def update_account_groups(self, user, account, groups, replace=False): |
215 |
"""Update the groups associated with the account."""
|
216 |
|
217 |
logger.debug("update_account_groups: %s %s %s", account, groups, replace)
|
218 |
if user != account:
|
219 |
raise NotAllowedError
|
220 |
self._lookup_account(account, True) |
221 |
self._check_groups(groups)
|
222 |
if replace:
|
223 |
self.permissions.group_destroy(account)
|
224 |
for k, v in groups.iteritems(): |
225 |
if not replace: # If not already deleted. |
226 |
self.permissions.group_delete(account, k)
|
227 |
if v:
|
228 |
self.permissions.group_addmany(account, k, v)
|
229 |
|
230 |
@backend_method
|
231 |
def get_account_policy(self, user, account): |
232 |
"""Return a dictionary with the account policy."""
|
233 |
|
234 |
logger.debug("get_account_policy: %s", account)
|
235 |
if user != account:
|
236 |
if account not in self._allowed_accounts(user): |
237 |
raise NotAllowedError
|
238 |
return {}
|
239 |
path, node = self._lookup_account(account, True) |
240 |
return self._get_policy(node) |
241 |
|
242 |
@backend_method
|
243 |
def update_account_policy(self, user, account, policy, replace=False): |
244 |
"""Update the policy associated with the account."""
|
245 |
|
246 |
logger.debug("update_account_policy: %s %s %s", account, policy, replace)
|
247 |
if user != account:
|
248 |
raise NotAllowedError
|
249 |
path, node = self._lookup_account(account, True) |
250 |
self._check_policy(policy)
|
251 |
self._put_policy(node, policy, replace)
|
252 |
|
253 |
@backend_method
|
254 |
def put_account(self, user, account, policy={}): |
255 |
"""Create a new account with the given name."""
|
256 |
|
257 |
logger.debug("put_account: %s %s", account, policy)
|
258 |
if user != account:
|
259 |
raise NotAllowedError
|
260 |
node = self.node.node_lookup(account)
|
261 |
if node is not None: |
262 |
raise NameError('Account already exists') |
263 |
if policy:
|
264 |
self._check_policy(policy)
|
265 |
node = self._put_path(user, self.ROOTNODE, account) |
266 |
self._put_policy(node, policy, True) |
267 |
|
268 |
@backend_method
|
269 |
def delete_account(self, user, account): |
270 |
"""Delete the account with the given name."""
|
271 |
|
272 |
logger.debug("delete_account: %s", account)
|
273 |
if user != account:
|
274 |
raise NotAllowedError
|
275 |
node = self.node.node_lookup(account)
|
276 |
if node is None: |
277 |
return
|
278 |
if not self.node.node_remove(node): |
279 |
raise IndexError('Account is not empty') |
280 |
self.permissions.group_destroy(account)
|
281 |
|
282 |
@backend_method
|
283 |
def list_containers(self, user, account, marker=None, limit=10000, shared=False, until=None): |
284 |
"""Return a list of containers existing under an account."""
|
285 |
|
286 |
logger.debug("list_containers: %s %s %s %s %s", account, marker, limit, shared, until)
|
287 |
if user != account:
|
288 |
if until or account not in self._allowed_accounts(user): |
289 |
raise NotAllowedError
|
290 |
allowed = self._allowed_containers(user, account)
|
291 |
start, limit = self._list_limits(allowed, marker, limit)
|
292 |
return allowed[start:start + limit]
|
293 |
if shared:
|
294 |
allowed = [x.split('/', 2)[1] for x in self.permissions.access_list_shared(account)] |
295 |
allowed = list(set(allowed)) |
296 |
start, limit = self._list_limits(allowed, marker, limit)
|
297 |
return allowed[start:start + limit]
|
298 |
node = self.node.node_lookup(account)
|
299 |
return [x[0] for x in self._list_objects(node, account, '', '/', marker, limit, False, None, [], until)] |
300 |
|
301 |
@backend_method
|
302 |
def get_container_meta(self, user, account, container, domain, until=None): |
303 |
"""Return a dictionary with the container metadata for the domain."""
|
304 |
|
305 |
logger.debug("get_container_meta: %s %s %s %s", account, container, domain, until)
|
306 |
if user != account:
|
307 |
if until or container not in self._allowed_containers(user, account): |
308 |
raise NotAllowedError
|
309 |
path, node = self._lookup_container(account, container)
|
310 |
props = self._get_properties(node, until)
|
311 |
mtime = props[self.MTIME]
|
312 |
count, bytes, tstamp = self._get_statistics(node, until) |
313 |
tstamp = max(tstamp, mtime)
|
314 |
if until is None: |
315 |
modified = tstamp |
316 |
else:
|
317 |
modified = self._get_statistics(node)[2] # Overall last modification. |
318 |
modified = max(modified, mtime)
|
319 |
|
320 |
if user != account:
|
321 |
meta = {'name': container}
|
322 |
else:
|
323 |
meta = dict(self.node.attribute_get(props[self.SERIAL], domain)) |
324 |
if until is not None: |
325 |
meta.update({'until_timestamp': tstamp})
|
326 |
meta.update({'name': container, 'count': count, 'bytes': bytes}) |
327 |
meta.update({'modified': modified})
|
328 |
return meta
|
329 |
|
330 |
@backend_method
|
331 |
def update_container_meta(self, user, account, container, domain, meta, replace=False): |
332 |
"""Update the metadata associated with the container for the domain."""
|
333 |
|
334 |
logger.debug("update_container_meta: %s %s %s %s %s", account, container, domain, meta, replace)
|
335 |
if user != account:
|
336 |
raise NotAllowedError
|
337 |
path, node = self._lookup_container(account, container)
|
338 |
self._put_metadata(user, node, domain, meta, replace)
|
339 |
|
340 |
@backend_method
|
341 |
def get_container_policy(self, user, account, container): |
342 |
"""Return a dictionary with the container policy."""
|
343 |
|
344 |
logger.debug("get_container_policy: %s %s", account, container)
|
345 |
if user != account:
|
346 |
if container not in self._allowed_containers(user, account): |
347 |
raise NotAllowedError
|
348 |
return {}
|
349 |
path, node = self._lookup_container(account, container)
|
350 |
return self._get_policy(node) |
351 |
|
352 |
@backend_method
|
353 |
def update_container_policy(self, user, account, container, policy, replace=False): |
354 |
"""Update the policy associated with the container."""
|
355 |
|
356 |
logger.debug("update_container_policy: %s %s %s %s", account, container, policy, replace)
|
357 |
if user != account:
|
358 |
raise NotAllowedError
|
359 |
path, node = self._lookup_container(account, container)
|
360 |
self._check_policy(policy)
|
361 |
self._put_policy(node, policy, replace)
|
362 |
|
363 |
@backend_method
|
364 |
def put_container(self, user, account, container, policy={}): |
365 |
"""Create a new container with the given name."""
|
366 |
|
367 |
logger.debug("put_container: %s %s %s", account, container, policy)
|
368 |
if user != account:
|
369 |
raise NotAllowedError
|
370 |
try:
|
371 |
path, node = self._lookup_container(account, container)
|
372 |
except NameError: |
373 |
pass
|
374 |
else:
|
375 |
raise NameError('Container already exists') |
376 |
if policy:
|
377 |
self._check_policy(policy)
|
378 |
path = '/'.join((account, container))
|
379 |
node = self._put_path(user, self._lookup_account(account, True)[1], path) |
380 |
self._put_policy(node, policy, True) |
381 |
|
382 |
@backend_method
|
383 |
def delete_container(self, user, account, container, until=None): |
384 |
"""Delete/purge the container with the given name."""
|
385 |
|
386 |
logger.debug("delete_container: %s %s %s", account, container, until)
|
387 |
if user != account:
|
388 |
raise NotAllowedError
|
389 |
path, node = self._lookup_container(account, container)
|
390 |
|
391 |
if until is not None: |
392 |
hashes, size = self.node.node_purge_children(node, until, CLUSTER_HISTORY)
|
393 |
for h in hashes: |
394 |
self.store.map_delete(h)
|
395 |
self.node.node_purge_children(node, until, CLUSTER_DELETED)
|
396 |
self._report_size_change(user, account, -size, {'action': 'container purge'}) |
397 |
return
|
398 |
|
399 |
if self._get_statistics(node)[0] > 0: |
400 |
raise IndexError('Container is not empty') |
401 |
hashes, size = self.node.node_purge_children(node, inf, CLUSTER_HISTORY)
|
402 |
for h in hashes: |
403 |
self.store.map_delete(h)
|
404 |
self.node.node_purge_children(node, inf, CLUSTER_DELETED)
|
405 |
self.node.node_remove(node)
|
406 |
self._report_size_change(user, account, -size, {'action': 'container delete'}) |
407 |
|
408 |
@backend_method
|
409 |
def list_objects(self, user, account, container, prefix='', delimiter=None, marker=None, limit=10000, virtual=True, domain=None, keys=[], shared=False, until=None, size_range=None): |
410 |
"""Return a list of objects existing under a container."""
|
411 |
|
412 |
logger.debug("list_objects: %s %s %s %s %s %s %s %s %s %s %s", account, container, prefix, delimiter, marker, limit, virtual, domain, keys, shared, until)
|
413 |
allowed = [] |
414 |
if user != account:
|
415 |
if until:
|
416 |
raise NotAllowedError
|
417 |
allowed = self.permissions.access_list_paths(user, '/'.join((account, container))) |
418 |
if not allowed: |
419 |
raise NotAllowedError
|
420 |
else:
|
421 |
if shared:
|
422 |
allowed = self.permissions.access_list_shared('/'.join((account, container))) |
423 |
if not allowed: |
424 |
return []
|
425 |
path, node = self._lookup_container(account, container)
|
426 |
allowed = self._get_formatted_paths(allowed)
|
427 |
return self._list_objects(node, path, prefix, delimiter, marker, limit, virtual, domain, keys, until, size_range, allowed) |
428 |
|
429 |
@backend_method
|
430 |
def list_object_meta(self, user, account, container, domain, until=None): |
431 |
"""Return a list with all the container's object meta keys for the domain."""
|
432 |
|
433 |
logger.debug("list_object_meta: %s %s %s %s", account, container, domain, until)
|
434 |
allowed = [] |
435 |
if user != account:
|
436 |
if until:
|
437 |
raise NotAllowedError
|
438 |
allowed = self.permissions.access_list_paths(user, '/'.join((account, container))) |
439 |
if not allowed: |
440 |
raise NotAllowedError
|
441 |
path, node = self._lookup_container(account, container)
|
442 |
before = until if until is not None else inf |
443 |
allowed = self._get_formatted_paths(allowed)
|
444 |
return self.node.latest_attribute_keys(node, domain, before, CLUSTER_DELETED, allowed) |
445 |
|
446 |
@backend_method
|
447 |
def get_object_meta(self, user, account, container, name, domain, version=None): |
448 |
"""Return a dictionary with the object metadata for the domain."""
|
449 |
|
450 |
logger.debug("get_object_meta: %s %s %s %s %s", account, container, name, domain, version)
|
451 |
self._can_read(user, account, container, name)
|
452 |
path, node = self._lookup_object(account, container, name)
|
453 |
props = self._get_version(node, version)
|
454 |
if version is None: |
455 |
modified = props[self.MTIME]
|
456 |
else:
|
457 |
try:
|
458 |
modified = self._get_version(node)[self.MTIME] # Overall last modification. |
459 |
except NameError: # Object may be deleted. |
460 |
del_props = self.node.version_lookup(node, inf, CLUSTER_DELETED)
|
461 |
if del_props is None: |
462 |
raise NameError('Object does not exist') |
463 |
modified = del_props[self.MTIME]
|
464 |
|
465 |
meta = dict(self.node.attribute_get(props[self.SERIAL], domain)) |
466 |
meta.update({'name': name,
|
467 |
'bytes': props[self.SIZE], |
468 |
'type': props[self.TYPE], |
469 |
'hash':props[self.HASH], |
470 |
'version': props[self.SERIAL], |
471 |
'version_timestamp': props[self.MTIME], |
472 |
'modified': modified,
|
473 |
'modified_by': props[self.MUSER], |
474 |
'uuid': props[self.UUID], |
475 |
'checksum': props[self.CHECKSUM]}) |
476 |
return meta
|
477 |
|
478 |
@backend_method
|
479 |
def update_object_meta(self, user, account, container, name, domain, meta, replace=False): |
480 |
"""Update the metadata associated with the object for the domain and return the new version."""
|
481 |
|
482 |
logger.debug("update_object_meta: %s %s %s %s %s %s", account, container, name, domain, meta, replace)
|
483 |
self._can_write(user, account, container, name)
|
484 |
path, node = self._lookup_object(account, container, name)
|
485 |
src_version_id, dest_version_id = self._put_metadata(user, node, domain, meta, replace)
|
486 |
self._apply_versioning(account, container, src_version_id)
|
487 |
return dest_version_id
|
488 |
|
489 |
@backend_method
|
490 |
def get_object_permissions(self, user, account, container, name): |
491 |
"""Return the action allowed on the object, the path
|
492 |
from which the object gets its permissions from,
|
493 |
along with a dictionary containing the permissions."""
|
494 |
|
495 |
logger.debug("get_object_permissions: %s %s %s", account, container, name)
|
496 |
allowed = 'write'
|
497 |
permissions_path = self._get_permissions_path(account, container, name)
|
498 |
if user != account:
|
499 |
if self.permissions.access_check(permissions_path, self.WRITE, user): |
500 |
allowed = 'write'
|
501 |
elif self.permissions.access_check(permissions_path, self.READ, user): |
502 |
allowed = 'read'
|
503 |
else:
|
504 |
raise NotAllowedError
|
505 |
self._lookup_object(account, container, name)
|
506 |
return (allowed, permissions_path, self.permissions.access_get(permissions_path)) |
507 |
|
508 |
@backend_method
|
509 |
def update_object_permissions(self, user, account, container, name, permissions): |
510 |
"""Update the permissions associated with the object."""
|
511 |
|
512 |
logger.debug("update_object_permissions: %s %s %s %s", account, container, name, permissions)
|
513 |
if user != account:
|
514 |
raise NotAllowedError
|
515 |
path = self._lookup_object(account, container, name)[0] |
516 |
self._check_permissions(path, permissions)
|
517 |
self.permissions.access_set(path, permissions)
|
518 |
|
519 |
@backend_method
|
520 |
def get_object_public(self, user, account, container, name): |
521 |
"""Return the public id of the object if applicable."""
|
522 |
|
523 |
logger.debug("get_object_public: %s %s %s", account, container, name)
|
524 |
self._can_read(user, account, container, name)
|
525 |
path = self._lookup_object(account, container, name)[0] |
526 |
p = self.permissions.public_get(path)
|
527 |
if p is not None: |
528 |
p += ULTIMATE_ANSWER |
529 |
return p
|
530 |
|
531 |
@backend_method
|
532 |
def update_object_public(self, user, account, container, name, public): |
533 |
"""Update the public status of the object."""
|
534 |
|
535 |
logger.debug("update_object_public: %s %s %s %s", account, container, name, public)
|
536 |
self._can_write(user, account, container, name)
|
537 |
path = self._lookup_object(account, container, name)[0] |
538 |
if not public: |
539 |
self.permissions.public_unset(path)
|
540 |
else:
|
541 |
self.permissions.public_set(path)
|
542 |
|
543 |
@backend_method
|
544 |
def get_object_hashmap(self, user, account, container, name, version=None): |
545 |
"""Return the object's size and a list with partial hashes."""
|
546 |
|
547 |
logger.debug("get_object_hashmap: %s %s %s %s", account, container, name, version)
|
548 |
self._can_read(user, account, container, name)
|
549 |
path, node = self._lookup_object(account, container, name)
|
550 |
props = self._get_version(node, version)
|
551 |
hashmap = self.store.map_get(binascii.unhexlify(props[self.HASH])) |
552 |
return props[self.SIZE], [binascii.hexlify(x) for x in hashmap] |
553 |
|
554 |
def _update_object_hash(self, user, account, container, name, size, type, hash, checksum, permissions, src_node=None, is_copy=False): |
555 |
if permissions is not None and user != account: |
556 |
raise NotAllowedError
|
557 |
self._can_write(user, account, container, name)
|
558 |
if permissions is not None: |
559 |
path = '/'.join((account, container, name))
|
560 |
self._check_permissions(path, permissions)
|
561 |
|
562 |
account_path, account_node = self._lookup_account(account, True) |
563 |
container_path, container_node = self._lookup_container(account, container)
|
564 |
path, node = self._put_object_node(container_path, container_node, name)
|
565 |
pre_version_id, dest_version_id = self._put_version_duplicate(user, node, src_node=src_node, size=size, type=type, hash=hash, checksum=checksum, is_copy=is_copy) |
566 |
|
567 |
# Check quota.
|
568 |
del_size = self._apply_versioning(account, container, pre_version_id)
|
569 |
size_delta = size - del_size |
570 |
if size_delta > 0: |
571 |
account_quota = long(self._get_policy(account_node)['quota']) |
572 |
container_quota = long(self._get_policy(container_node)['quota']) |
573 |
if (account_quota > 0 and self._get_statistics(account_node)[1] + size_delta > account_quota) or \ |
574 |
(container_quota > 0 and self._get_statistics(container_node)[1] + size_delta > container_quota): |
575 |
# This must be executed in a transaction, so the version is never created if it fails.
|
576 |
raise QuotaError
|
577 |
self._report_size_change(user, account, size_delta, {'action': 'object update'}) |
578 |
|
579 |
if permissions is not None: |
580 |
self.permissions.access_set(path, permissions)
|
581 |
return pre_version_id, dest_version_id
|
582 |
|
583 |
@backend_method
|
584 |
def update_object_hashmap(self, user, account, container, name, size, type, hashmap, checksum, domain, meta={}, replace_meta=False, permissions=None): |
585 |
"""Create/update an object with the specified size and partial hashes."""
|
586 |
|
587 |
logger.debug("update_object_hashmap: %s %s %s %s %s %s %s", account, container, name, size, type, hashmap, checksum) |
588 |
if size == 0: # No such thing as an empty hashmap. |
589 |
hashmap = [self.put_block('')] |
590 |
map = HashMap(self.block_size, self.hash_algorithm) |
591 |
map.extend([binascii.unhexlify(x) for x in hashmap]) |
592 |
missing = self.store.block_search(map) |
593 |
if missing:
|
594 |
ie = IndexError()
|
595 |
ie.data = [binascii.hexlify(x) for x in missing] |
596 |
raise ie
|
597 |
|
598 |
hash = map.hash()
|
599 |
pre_version_id, dest_version_id = self._update_object_hash(user, account, container, name, size, type, binascii.hexlify(hash), checksum, permissions) |
600 |
self._put_metadata_duplicate(pre_version_id, dest_version_id, domain, meta, replace_meta)
|
601 |
self.store.map_put(hash, map) |
602 |
return dest_version_id
|
603 |
|
604 |
@backend_method
|
605 |
def update_object_checksum(self, user, account, container, name, version, checksum): |
606 |
"""Update an object's checksum."""
|
607 |
|
608 |
logger.debug("update_object_checksum: %s %s %s %s %s", account, container, name, version, checksum)
|
609 |
# Update objects with greater version and same hashmap and size (fix metadata updates).
|
610 |
self._can_write(user, account, container, name)
|
611 |
path, node = self._lookup_object(account, container, name)
|
612 |
props = self._get_version(node, version)
|
613 |
versions = self.node.node_get_versions(node)
|
614 |
for x in versions: |
615 |
if x[self.SERIAL] >= int(version) and x[self.HASH] == props[self.HASH] and x[self.SIZE] == props[self.SIZE]: |
616 |
self.node.version_put_property(x[self.SERIAL], 'checksum', checksum) |
617 |
|
618 |
def _copy_object(self, user, src_account, src_container, src_name, dest_account, dest_container, dest_name, type, dest_domain=None, dest_meta={}, replace_meta=False, permissions=None, src_version=None, is_move=False): |
619 |
self._can_read(user, src_account, src_container, src_name)
|
620 |
path, node = self._lookup_object(src_account, src_container, src_name)
|
621 |
# TODO: Will do another fetch of the properties in duplicate version...
|
622 |
props = self._get_version(node, src_version) # Check to see if source exists. |
623 |
src_version_id = props[self.SERIAL]
|
624 |
hash = props[self.HASH]
|
625 |
size = props[self.SIZE]
|
626 |
|
627 |
is_copy = not is_move and (src_account, src_container, src_name) != (dest_account, dest_container, dest_name) # New uuid. |
628 |
pre_version_id, dest_version_id = self._update_object_hash(user, dest_account, dest_container, dest_name, size, type, hash, checksum=None, permissions, src_node=node, is_copy=is_copy) |
629 |
self._put_metadata_duplicate(src_version_id, dest_version_id, dest_domain, dest_meta, replace_meta)
|
630 |
return dest_version_id
|
631 |
|
632 |
@backend_method
|
633 |
def copy_object(self, user, src_account, src_container, src_name, dest_account, dest_container, dest_name, type, domain, meta={}, replace_meta=False, permissions=None, src_version=None): |
634 |
"""Copy an object's data and metadata."""
|
635 |
|
636 |
logger.debug("copy_object: %s %s %s %s %s %s %s %s %s %s %s %s", src_account, src_container, src_name, dest_account, dest_container, dest_name, type, domain, meta, replace_meta, permissions, src_version) |
637 |
dest_version_id = self._copy_object(user, src_account, src_container, src_name, dest_account, dest_container, dest_name, type, domain, meta, replace_meta, permissions, src_version, False) |
638 |
return dest_version_id
|
639 |
|
640 |
@backend_method
|
641 |
def move_object(self, user, src_account, src_container, src_name, dest_account, dest_container, dest_name, type, domain, meta={}, replace_meta=False, permissions=None): |
642 |
"""Move an object's data and metadata."""
|
643 |
|
644 |
logger.debug("move_object: %s %s %s %s %s %s %s %s %s %s %s", src_account, src_container, src_name, dest_account, dest_container, dest_name, type, domain, meta, replace_meta, permissions) |
645 |
if user != src_account:
|
646 |
raise NotAllowedError
|
647 |
dest_version_id = self._copy_object(user, src_account, src_container, src_name, dest_account, dest_container, dest_name, type, domain, meta, replace_meta, permissions, None, True) |
648 |
if (src_account, src_container, src_name) != (dest_account, dest_container, dest_name):
|
649 |
self._delete_object(user, src_account, src_container, src_name)
|
650 |
return dest_version_id
|
651 |
|
652 |
def _delete_object(self, user, account, container, name, until=None): |
653 |
if user != account:
|
654 |
raise NotAllowedError
|
655 |
|
656 |
if until is not None: |
657 |
path = '/'.join((account, container, name))
|
658 |
node = self.node.node_lookup(path)
|
659 |
if node is None: |
660 |
return
|
661 |
hashes = [] |
662 |
size = 0
|
663 |
h, s = self.node.node_purge(node, until, CLUSTER_NORMAL)
|
664 |
hashes += h |
665 |
size += s |
666 |
h, s = self.node.node_purge(node, until, CLUSTER_HISTORY)
|
667 |
hashes += h |
668 |
size += s |
669 |
for h in hashes: |
670 |
self.store.map_delete(h)
|
671 |
self.node.node_purge(node, until, CLUSTER_DELETED)
|
672 |
try:
|
673 |
props = self._get_version(node)
|
674 |
except NameError: |
675 |
self.permissions.access_clear(path)
|
676 |
self._report_size_change(user, account, -size, {'action': 'object purge'}) |
677 |
return
|
678 |
|
679 |
path, node = self._lookup_object(account, container, name)
|
680 |
src_version_id, dest_version_id = self._put_version_duplicate(user, node, size=0, type='', hash=None, checksum='', cluster=CLUSTER_DELETED) |
681 |
del_size = self._apply_versioning(account, container, src_version_id)
|
682 |
if del_size:
|
683 |
self._report_size_change(user, account, -del_size, {'action': 'object delete'}) |
684 |
self.permissions.access_clear(path)
|
685 |
|
686 |
@backend_method
|
687 |
def delete_object(self, user, account, container, name, until=None): |
688 |
"""Delete/purge an object."""
|
689 |
|
690 |
logger.debug("delete_object: %s %s %s %s", account, container, name, until)
|
691 |
self._delete_object(user, account, container, name, until)
|
692 |
|
693 |
@backend_method
|
694 |
def list_versions(self, user, account, container, name): |
695 |
"""Return a list of all (version, version_timestamp) tuples for an object."""
|
696 |
|
697 |
logger.debug("list_versions: %s %s %s", account, container, name)
|
698 |
self._can_read(user, account, container, name)
|
699 |
path, node = self._lookup_object(account, container, name)
|
700 |
versions = self.node.node_get_versions(node)
|
701 |
return [[x[self.SERIAL], x[self.MTIME]] for x in versions if x[self.CLUSTER] != CLUSTER_DELETED] |
702 |
|
703 |
@backend_method
|
704 |
def get_uuid(self, user, uuid): |
705 |
"""Return the (account, container, name) for the UUID given."""
|
706 |
|
707 |
logger.debug("get_uuid: %s", uuid)
|
708 |
info = self.node.latest_uuid(uuid)
|
709 |
if info is None: |
710 |
raise NameError |
711 |
path, serial = info |
712 |
account, container, name = path.split('/', 2) |
713 |
self._can_read(user, account, container, name)
|
714 |
return (account, container, name)
|
715 |
|
716 |
@backend_method
|
717 |
def get_public(self, user, public): |
718 |
"""Return the (account, container, name) for the public id given."""
|
719 |
|
720 |
logger.debug("get_public: %s", public)
|
721 |
if public is None or public < ULTIMATE_ANSWER: |
722 |
raise NameError |
723 |
path = self.permissions.public_path(public - ULTIMATE_ANSWER)
|
724 |
if path is None: |
725 |
raise NameError |
726 |
account, container, name = path.split('/', 2) |
727 |
self._can_read(user, account, container, name)
|
728 |
return (account, container, name)
|
729 |
|
730 |
@backend_method(autocommit=0) |
731 |
def get_block(self, hash): |
732 |
"""Return a block's data."""
|
733 |
|
734 |
logger.debug("get_block: %s", hash) |
735 |
block = self.store.block_get(binascii.unhexlify(hash)) |
736 |
if not block: |
737 |
raise NameError('Block does not exist') |
738 |
return block
|
739 |
|
740 |
@backend_method(autocommit=0) |
741 |
def put_block(self, data): |
742 |
"""Store a block and return the hash."""
|
743 |
|
744 |
logger.debug("put_block: %s", len(data)) |
745 |
return binascii.hexlify(self.store.block_put(data)) |
746 |
|
747 |
@backend_method(autocommit=0) |
748 |
def update_block(self, hash, data, offset=0): |
749 |
"""Update a known block and return the hash."""
|
750 |
|
751 |
logger.debug("update_block: %s %s %s", hash, len(data), offset) |
752 |
if offset == 0 and len(data) == self.block_size: |
753 |
return self.put_block(data) |
754 |
h = self.store.block_update(binascii.unhexlify(hash), offset, data) |
755 |
return binascii.hexlify(h)
|
756 |
|
757 |
# Path functions.
|
758 |
|
759 |
def _generate_uuid(self): |
760 |
return str(uuidlib.uuid4()) |
761 |
|
762 |
def _put_object_node(self, path, parent, name): |
763 |
path = '/'.join((path, name))
|
764 |
node = self.node.node_lookup(path)
|
765 |
if node is None: |
766 |
node = self.node.node_create(parent, path)
|
767 |
return path, node
|
768 |
|
769 |
def _put_path(self, user, parent, path): |
770 |
node = self.node.node_create(parent, path)
|
771 |
self.node.version_create(node, None, 0, '', None, user, self._generate_uuid(), '', CLUSTER_NORMAL) |
772 |
return node
|
773 |
|
774 |
def _lookup_account(self, account, create=True): |
775 |
node = self.node.node_lookup(account)
|
776 |
if node is None and create: |
777 |
node = self._put_path(account, self.ROOTNODE, account) # User is account. |
778 |
return account, node
|
779 |
|
780 |
def _lookup_container(self, account, container): |
781 |
path = '/'.join((account, container))
|
782 |
node = self.node.node_lookup(path)
|
783 |
if node is None: |
784 |
raise NameError('Container does not exist') |
785 |
return path, node
|
786 |
|
787 |
def _lookup_object(self, account, container, name): |
788 |
path = '/'.join((account, container, name))
|
789 |
node = self.node.node_lookup(path)
|
790 |
if node is None: |
791 |
raise NameError('Object does not exist') |
792 |
return path, node
|
793 |
|
794 |
def _get_properties(self, node, until=None): |
795 |
"""Return properties until the timestamp given."""
|
796 |
|
797 |
before = until if until is not None else inf |
798 |
props = self.node.version_lookup(node, before, CLUSTER_NORMAL)
|
799 |
if props is None and until is not None: |
800 |
props = self.node.version_lookup(node, before, CLUSTER_HISTORY)
|
801 |
if props is None: |
802 |
raise NameError('Path does not exist') |
803 |
return props
|
804 |
|
805 |
def _get_statistics(self, node, until=None): |
806 |
"""Return count, sum of size and latest timestamp of everything under node."""
|
807 |
|
808 |
if until is None: |
809 |
stats = self.node.statistics_get(node, CLUSTER_NORMAL)
|
810 |
else:
|
811 |
stats = self.node.statistics_latest(node, until, CLUSTER_DELETED)
|
812 |
if stats is None: |
813 |
stats = (0, 0, 0) |
814 |
return stats
|
815 |
|
816 |
def _get_version(self, node, version=None): |
817 |
if version is None: |
818 |
props = self.node.version_lookup(node, inf, CLUSTER_NORMAL)
|
819 |
if props is None: |
820 |
raise NameError('Object does not exist') |
821 |
else:
|
822 |
try:
|
823 |
version = int(version)
|
824 |
except ValueError: |
825 |
raise IndexError('Version does not exist') |
826 |
props = self.node.version_get_properties(version)
|
827 |
if props is None or props[self.CLUSTER] == CLUSTER_DELETED: |
828 |
raise IndexError('Version does not exist') |
829 |
return props
|
830 |
|
831 |
def _put_version_duplicate(self, user, node, src_node=None, size=None, type=None, hash=None, checksum=None, cluster=CLUSTER_NORMAL, is_copy=False): |
832 |
"""Create a new version of the node."""
|
833 |
|
834 |
props = self.node.version_lookup(node if src_node is None else src_node, inf, CLUSTER_NORMAL) |
835 |
if props is not None: |
836 |
src_version_id = props[self.SERIAL]
|
837 |
src_hash = props[self.HASH]
|
838 |
src_size = props[self.SIZE]
|
839 |
src_type = props[self.TYPE]
|
840 |
src_checksum = props[self.CHECKSUM]
|
841 |
else:
|
842 |
src_version_id = None
|
843 |
src_hash = None
|
844 |
src_size = 0
|
845 |
src_type = ''
|
846 |
src_checksum = ''
|
847 |
if size is None: # Set metadata. |
848 |
hash = src_hash # This way hash can be set to None (account or container).
|
849 |
size = src_size |
850 |
if type is None: |
851 |
type = src_type |
852 |
if checksum is None: |
853 |
checksum = src_checksum |
854 |
uuid = self._generate_uuid() if (is_copy or src_version_id is None) else props[self.UUID] |
855 |
|
856 |
if src_node is None: |
857 |
pre_version_id = src_version_id |
858 |
else:
|
859 |
pre_version_id = None
|
860 |
props = self.node.version_lookup(node, inf, CLUSTER_NORMAL)
|
861 |
if props is not None: |
862 |
pre_version_id = props[self.SERIAL]
|
863 |
if pre_version_id is not None: |
864 |
self.node.version_recluster(pre_version_id, CLUSTER_HISTORY)
|
865 |
|
866 |
dest_version_id, mtime = self.node.version_create(node, hash, size, type, src_version_id, user, uuid, checksum, cluster) |
867 |
return pre_version_id, dest_version_id
|
868 |
|
869 |
def _put_metadata_duplicate(self, src_version_id, dest_version_id, domain, meta, replace=False): |
870 |
if src_version_id is not None: |
871 |
self.node.attribute_copy(src_version_id, dest_version_id)
|
872 |
if not replace: |
873 |
self.node.attribute_del(dest_version_id, domain, (k for k, v in meta.iteritems() if v == '')) |
874 |
self.node.attribute_set(dest_version_id, domain, ((k, v) for k, v in meta.iteritems() if v != '')) |
875 |
else:
|
876 |
self.node.attribute_del(dest_version_id, domain)
|
877 |
self.node.attribute_set(dest_version_id, domain, ((k, v) for k, v in meta.iteritems())) |
878 |
|
879 |
def _put_metadata(self, user, node, domain, meta, replace=False): |
880 |
"""Create a new version and store metadata."""
|
881 |
|
882 |
src_version_id, dest_version_id = self._put_version_duplicate(user, node)
|
883 |
self._put_metadata_duplicate(src_version_id, dest_version_id, domain, meta, replace)
|
884 |
return src_version_id, dest_version_id
|
885 |
|
886 |
def _list_limits(self, listing, marker, limit): |
887 |
start = 0
|
888 |
if marker:
|
889 |
try:
|
890 |
start = listing.index(marker) + 1
|
891 |
except ValueError: |
892 |
pass
|
893 |
if not limit or limit > 10000: |
894 |
limit = 10000
|
895 |
return start, limit
|
896 |
|
897 |
def _list_objects(self, parent, path, prefix='', delimiter=None, marker=None, limit=10000, virtual=True, domain=None, keys=[], until=None, size_range=None, allowed=[]): |
898 |
cont_prefix = path + '/'
|
899 |
prefix = cont_prefix + prefix |
900 |
start = cont_prefix + marker if marker else None |
901 |
before = until if until is not None else inf |
902 |
filterq = keys if domain else [] |
903 |
sizeq = size_range |
904 |
|
905 |
objects, prefixes = self.node.latest_version_list(parent, prefix, delimiter, start, limit, before, CLUSTER_DELETED, allowed, domain, filterq, sizeq)
|
906 |
objects.extend([(p, None) for p in prefixes] if virtual else []) |
907 |
objects.sort(key=lambda x: x[0]) |
908 |
objects = [(x[0][len(cont_prefix):], x[1]) for x in objects] |
909 |
|
910 |
start, limit = self._list_limits([x[0] for x in objects], marker, limit) |
911 |
return objects[start:start + limit]
|
912 |
|
913 |
# Reporting functions.
|
914 |
|
915 |
def _report_size_change(self, user, account, size, details={}): |
916 |
logger.debug("_report_size_change: %s %s %s %s", user, account, size, details)
|
917 |
account_node = self._lookup_account(account, True)[1] |
918 |
total = self._get_statistics(account_node)[1] |
919 |
details.update({'user': user, 'total': total}) |
920 |
self.queue.send(account, 'diskspace', size, details) |
921 |
|
922 |
# Policy functions.
|
923 |
|
924 |
def _check_policy(self, policy): |
925 |
for k in policy.keys(): |
926 |
if policy[k] == '': |
927 |
policy[k] = self.default_policy.get(k)
|
928 |
for k, v in policy.iteritems(): |
929 |
if k == 'quota': |
930 |
q = int(v) # May raise ValueError. |
931 |
if q < 0: |
932 |
raise ValueError |
933 |
elif k == 'versioning': |
934 |
if v not in ['auto', 'none']: |
935 |
raise ValueError |
936 |
else:
|
937 |
raise ValueError |
938 |
|
939 |
def _put_policy(self, node, policy, replace): |
940 |
if replace:
|
941 |
for k, v in self.default_policy.iteritems(): |
942 |
if k not in policy: |
943 |
policy[k] = v |
944 |
self.node.policy_set(node, policy)
|
945 |
|
946 |
def _get_policy(self, node): |
947 |
policy = self.default_policy.copy()
|
948 |
policy.update(self.node.policy_get(node))
|
949 |
return policy
|
950 |
|
951 |
def _apply_versioning(self, account, container, version_id): |
952 |
"""Delete the provided version if such is the policy.
|
953 |
Return size of object removed.
|
954 |
"""
|
955 |
|
956 |
if version_id is None: |
957 |
return 0 |
958 |
path, node = self._lookup_container(account, container)
|
959 |
versioning = self._get_policy(node)['versioning'] |
960 |
if versioning != 'auto': |
961 |
hash, size = self.node.version_remove(version_id) |
962 |
self.store.map_delete(hash) |
963 |
return size
|
964 |
return 0 |
965 |
|
966 |
# Access control functions.
|
967 |
|
968 |
def _check_groups(self, groups): |
969 |
# raise ValueError('Bad characters in groups')
|
970 |
pass
|
971 |
|
972 |
def _check_permissions(self, path, permissions): |
973 |
# raise ValueError('Bad characters in permissions')
|
974 |
pass
|
975 |
|
976 |
def _get_formatted_paths(self, paths): |
977 |
formatted = [] |
978 |
for p in paths: |
979 |
node = self.node.node_lookup(p)
|
980 |
if node is not None: |
981 |
props = self.node.version_lookup(node, inf, CLUSTER_NORMAL)
|
982 |
if props is not None: |
983 |
if props[self.TYPE] in ('application/directory', 'application/folder'): |
984 |
formatted.append((p.rstrip('/') + '/', self.MATCH_PREFIX)) |
985 |
formatted.append((p, self.MATCH_EXACT))
|
986 |
return formatted
|
987 |
|
988 |
def _get_permissions_path(self, account, container, name): |
989 |
path = '/'.join((account, container, name))
|
990 |
permission_paths = self.permissions.access_inherit(path)
|
991 |
permission_paths.sort() |
992 |
permission_paths.reverse() |
993 |
for p in permission_paths: |
994 |
if p == path:
|
995 |
return p
|
996 |
else:
|
997 |
if p.count('/') < 2: |
998 |
continue
|
999 |
node = self.node.node_lookup(p)
|
1000 |
if node is not None: |
1001 |
props = self.node.version_lookup(node, inf, CLUSTER_NORMAL)
|
1002 |
if props is not None: |
1003 |
if props[self.TYPE] in ('application/directory', 'application/folder'): |
1004 |
return p
|
1005 |
return None |
1006 |
|
1007 |
def _can_read(self, user, account, container, name): |
1008 |
if user == account:
|
1009 |
return True |
1010 |
path = '/'.join((account, container, name))
|
1011 |
if self.permissions.public_get(path) is not None: |
1012 |
return True |
1013 |
path = self._get_permissions_path(account, container, name)
|
1014 |
if not path: |
1015 |
raise NotAllowedError
|
1016 |
if not self.permissions.access_check(path, self.READ, user) and not self.permissions.access_check(path, self.WRITE, user): |
1017 |
raise NotAllowedError
|
1018 |
|
1019 |
def _can_write(self, user, account, container, name): |
1020 |
if user == account:
|
1021 |
return True |
1022 |
path = '/'.join((account, container, name))
|
1023 |
path = self._get_permissions_path(account, container, name)
|
1024 |
if not path: |
1025 |
raise NotAllowedError
|
1026 |
if not self.permissions.access_check(path, self.WRITE, user): |
1027 |
raise NotAllowedError
|
1028 |
|
1029 |
def _allowed_accounts(self, user): |
1030 |
allow = set()
|
1031 |
for path in self.permissions.access_list_paths(user): |
1032 |
allow.add(path.split('/', 1)[0]) |
1033 |
return sorted(allow) |
1034 |
|
1035 |
def _allowed_containers(self, user, account): |
1036 |
allow = set()
|
1037 |
for path in self.permissions.access_list_paths(user, account): |
1038 |
allow.add(path.split('/', 2)[1]) |
1039 |
return sorted(allow) |