Revision 4a105ce2 snf-pithos-backend/pithos/backends/lib/sqlite/public.py

b/snf-pithos-backend/pithos/backends/lib/sqlite/public.py
33 33

  
34 34
from dbworker import DBWorker
35 35

  
36
from pithos.backends.random_word import get_word
36
from pithos.backends.random_word import get_random_word
37

  
38
import logging
39

  
40
logger = logging.getLogger(__name__)
37 41

  
38 42
class Public(DBWorker):
39 43
    """Paths can be marked as public."""
......
52 56
        execute(""" create unique index if not exists idx_public_url
53 57
                    on public(url) """)
54 58

  
55
    def get_unique_url(self, serial, public_url_min_length, public_url_alphabet):
56
        l = public_url_min_length
59
    def get_unique_url(self, public_url_security, public_url_alphabet):
60
        l = public_url_security
57 61
        while 1:
58
            candidate = get_word(serial, length=l, alphabet=public_url_alphabet)
62
            candidate = get_random_word(length=l, alphabet=public_url_alphabet)
59 63
            if self.public_path(candidate) is None:
60 64
                return candidate
61 65
            l +=1
62 66

  
63
    def public_set(self, path, public_url_min_length, public_url_alphabet):
67
    def public_set(self, path, public_url_security, public_url_alphabet):
64 68
        q = "select public_id from public where path = ?"
65 69
        self.execute(q, (path,))
66 70
        row = self.fetchone()
67 71

  
68 72
        if not row:
69
            q = "insert into public(path, active) values(?, ?)"
70
            serial = self.execute(q, (path, active)).lastrowid
71 73
            url = self.get_unique_url(
72
                serial, public_url_min_length, public_url_alphabet
74
                public_url_security, public_url_alphabet
73 75
            )
74
            q = "update public set url=url where public_id = ?"
75
            self.execute(q, (serial,))
76
            q = "insert into public(path, active, url) values(?, 1, ?)"
77
            self.execute(q, (path, url))
78
            logger.info('Public url: %s set for path: %s' % (url, path))
76 79

  
77 80
    def public_unset(self, path):
78 81
        q = "delete from public where path = ?"
79 82
        self.execute(q, (path,))
83
        logger.info('Public url unset for path: %s' % (path))
80 84

  
81 85
    def public_unset_bulk(self, paths):
82 86
        placeholders = ','.join('?' for path in paths)
83
        q = "delete from public where path in (%s)"
87
        q = "delete from public where path in (%s)" % placeholders
84 88
        self.execute(q, paths)
85 89

  
86 90
    def public_get(self, path):

Also available in: Unified diff