Revision e0f916bb pithos/backends/simple.py
b/pithos/backends/simple.py | ||
---|---|---|
85 | 85 |
sql = '''create table if not exists groups ( |
86 | 86 |
account text, name text, users text, primary key (account, name))''' |
87 | 87 |
self.con.execute(sql) |
88 |
sql = '''create table if not exists policy ( |
|
89 |
name text, key text, value text, primary key (name, key))''' |
|
90 |
self.con.execute(sql) |
|
88 | 91 |
sql = '''create table if not exists permissions ( |
89 | 92 |
name text, read text, write text, primary key (name))''' |
90 | 93 |
self.con.execute(sql) |
91 |
sql = '''create table if not exists policy (
|
|
92 |
name text, key text, value text, primary key (name, key))'''
|
|
94 |
sql = '''create table if not exists public (
|
|
95 |
name text, primary key (name))'''
|
|
93 | 96 |
self.con.execute(sql) |
94 | 97 |
self.con.commit() |
95 | 98 |
|
... | ... | |
351 | 354 |
"""Return the public URL of the object if applicable.""" |
352 | 355 |
|
353 | 356 |
logger.debug("get_object_public: %s %s %s", account, container, name) |
357 |
self._can_read(user, account, container, name) |
|
358 |
path = self._get_objectinfo(account, container, name)[0] |
|
359 |
if self._get_public(path): |
|
360 |
return '/public/' + path |
|
354 | 361 |
return None |
355 | 362 |
|
356 | 363 |
def update_object_public(self, user, account, container, name, public): |
357 | 364 |
"""Update the public status of the object.""" |
358 | 365 |
|
359 | 366 |
logger.debug("update_object_public: %s %s %s %s", account, container, name, public) |
360 |
return |
|
367 |
self._can_write(user, account, container, name) |
|
368 |
path = self._get_objectinfo(account, container, name)[0] |
|
369 |
self._put_public(path, public) |
|
361 | 370 |
|
362 | 371 |
def get_object_hashmap(self, user, account, container, name, version=None): |
363 | 372 |
"""Return the object's size and a list with partial hashes.""" |
... | ... | |
649 | 658 |
if user == account: |
650 | 659 |
return True |
651 | 660 |
path = os.path.join(account, container, name) |
661 |
if op == 'read' and self._get_public(path): |
|
662 |
return True |
|
652 | 663 |
perm_path, perms = self._get_permissions(path) |
653 | 664 |
|
654 | 665 |
# Expand groups. |
... | ... | |
723 | 734 |
self.con.execute(sql, (path, r, w)) |
724 | 735 |
self.con.commit() |
725 | 736 |
|
737 |
def _get_public(self, path): |
|
738 |
sql = 'select name from public where name = ?' |
|
739 |
c = self.con.execute(sql, (path,)) |
|
740 |
row = c.fetchone() |
|
741 |
if not row: |
|
742 |
return False |
|
743 |
return True |
|
744 |
|
|
745 |
def _put_public(self, path, public): |
|
746 |
if not public: |
|
747 |
sql = 'delete from public where name = ?' |
|
748 |
else: |
|
749 |
sql = 'insert or replace into public (name) values (?)' |
|
750 |
self.con.execute(sql, (path,)) |
|
751 |
self.con.commit() |
|
752 |
|
|
726 | 753 |
def _list_objects(self, path, prefix='', delimiter=None, marker=None, limit=10000, virtual=True, keys=[], until=None): |
727 | 754 |
cont_prefix = path + '/' |
728 | 755 |
if keys and len(keys) > 0: |
Also available in: Unified diff