git://git.onelab.eu
/
plcapi.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
====
[plcapi.git]
/
PLC
/
Keys.py
diff --git
a/PLC/Keys.py
b/PLC/Keys.py
index
d8e54e6
..
ebabd19
100644
(file)
--- a/
PLC/Keys.py
+++ b/
PLC/Keys.py
@@
-1,5
+1,3
@@
-# $Id$
-# $URL$
import re
from PLC.Faults import *
import re
from PLC.Faults import *
@@
-11,8
+9,8
@@
from PLC.KeyTypes import KeyType, KeyTypes
class Key(Row):
"""
class Key(Row):
"""
- Representation of a row in the keys table. To use, instantiate with a
- dict of values. Update as you would a dict. Commit to the database
+ Representation of a row in the keys table. To use, instantiate with a
+ dict of values. Update as you would a dict. Commit to the database
with sync().
"""
with sync().
"""
@@
-32,18
+30,18
@@
class Key(Row):
key_types = [row['key_type'] for row in KeyTypes(self.api)]
if key_type not in key_types:
raise PLCInvalidArgument, "Invalid key type"
key_types = [row['key_type'] for row in KeyTypes(self.api)]
if key_type not in key_types:
raise PLCInvalidArgument, "Invalid key type"
- return key_type
+
return key_type
def validate_key(self, key):
def validate_key(self, key):
- # Key must not be blacklisted
- rows = self.api.db.selectall("SELECT 1 from keys" \
- " WHERE key = %(key)s" \
+
# Key must not be blacklisted
+
rows = self.api.db.selectall("SELECT 1 from keys" \
+
" WHERE key = %(key)s" \
" AND is_blacklisted IS True",
locals())
" AND is_blacklisted IS True",
locals())
- if rows:
+
if rows:
raise PLCInvalidArgument, "Key is blacklisted and cannot be used"
raise PLCInvalidArgument, "Key is blacklisted and cannot be used"
- return key
+
return key
def validate(self):
# Basic validation
def validate(self):
# Basic validation
@@
-69,13
+67,13
@@
class Key(Row):
def blacklist(self, commit = True):
"""
def blacklist(self, commit = True):
"""
- Permanently blacklist key (and all other identical keys),
- preventing it from ever being added again. Because this could
- affect multiple keys associated with multiple accounts, it
- should be admin only.
- """
+
Permanently blacklist key (and all other identical keys),
+
preventing it from ever being added again. Because this could
+
affect multiple keys associated with multiple accounts, it
+ should be admin only.
+
"""
- assert 'key_id' in self
+
assert 'key_id' in self
assert 'key' in self
# Get all matching keys
assert 'key' in self
# Get all matching keys
@@
-89,7
+87,7
@@
class Key(Row):
self.api.db.do("UPDATE keys SET is_blacklisted = True" \
" WHERE key_id IN (%s)" % ", ".join(map(str, key_ids)))
self.api.db.do("UPDATE keys SET is_blacklisted = True" \
" WHERE key_id IN (%s)" % ", ".join(map(str, key_ids)))
- # But disassociate them from all join tables
+
# But disassociate them from all join tables
for table in self.join_tables:
self.api.db.do("DELETE FROM %s WHERE key_id IN (%s)" % \
(table, ", ".join(map(str, key_ids))))
for table in self.join_tables:
self.api.db.do("DELETE FROM %s WHERE key_id IN (%s)" % \
(table, ", ".join(map(str, key_ids))))
@@
-105,15
+103,17
@@
class Keys(Table):
def __init__(self, api, key_filter = None, columns = None):
Table.__init__(self, api, Key, columns)
def __init__(self, api, key_filter = None, columns = None):
Table.__init__(self, api, Key, columns)
-
- sql = "SELECT %s FROM view_keys WHERE is_blacklisted IS False" % \
+
+
sql = "SELECT %s FROM view_keys WHERE is_blacklisted IS False" % \
", ".join(self.columns)
if key_filter is not None:
", ".join(self.columns)
if key_filter is not None:
- if isinstance(key_filter, (list, tuple, set)):
+ if isinstance(key_filter, (list, tuple, set
, int, long
)):
key_filter = Filter(Key.fields, {'key_id': key_filter})
elif isinstance(key_filter, dict):
key_filter = Filter(Key.fields, key_filter)
key_filter = Filter(Key.fields, {'key_id': key_filter})
elif isinstance(key_filter, dict):
key_filter = Filter(Key.fields, key_filter)
+ else:
+ raise PLCInvalidArgument, "Wrong key filter %r"%key_filter
sql += " AND (%s) %s" % key_filter.sql(api)
sql += " AND (%s) %s" % key_filter.sql(api)
- self.selectall(sql)
+
self.selectall(sql)