summaryrefslogtreecommitdiff
path: root/python/skytools/dbstruct.py
diff options
context:
space:
mode:
authorMarko Kreen2011-12-30 12:00:58 +0000
committerMarko Kreen2011-12-30 12:00:58 +0000
commite40699ce2dcd8f21945b8952094bb395d0b17b78 (patch)
tree781a50419d24a0cd78b509c24236c606cab9ff82 /python/skytools/dbstruct.py
parentb3691e0fd914ed09f87d49798953a475bd3343a8 (diff)
dbstruct: support grants 'WITH GRANT OPTION'
Diffstat (limited to 'python/skytools/dbstruct.py')
-rw-r--r--python/skytools/dbstruct.py28
1 files changed, 23 insertions, 5 deletions
diff --git a/python/skytools/dbstruct.py b/python/skytools/dbstruct.py
index 617f6dc2..5311889a 100644
--- a/python/skytools/dbstruct.py
+++ b/python/skytools/dbstruct.py
@@ -313,7 +313,18 @@ class TGrant(TElem):
def acl_to_grants(self, acl):
if acl == "arwdRxt": # ALL for tables
return "ALL"
- return ", ".join([ self.acl_map[c] for c in acl ])
+ i = 0
+ lst1 = []
+ lst2 = []
+ while i < len(acl):
+ a = self.acl_map[acl[i]]
+ if i+1 < len(acl) and acl[i+1] == '*':
+ lst2.append(a)
+ i += 2
+ else:
+ lst1.append(a)
+ i += 1
+ return ", ".join(lst1), ", ".join(lst2)
def parse_relacl(self, relacl):
"""Parse ACL to tuple of (user, acl, who)"""
@@ -336,11 +347,18 @@ class TGrant(TElem):
if not new_name:
new_name = self.name
+ qtarget = quote_fqident(new_name)
+
sql_list = []
- for user, acl, who in self.acl_list:
- astr = self.acl_to_grants(acl)
- sql = "GRANT %s ON %s\n TO %s;" % (astr, quote_fqident(new_name), quote_ident(user))
- sql_list.append(sql)
+ for role, acl, who in self.acl_list:
+ qrole = quote_ident(role)
+ astr1, astr2 = self.acl_to_grants(acl)
+ if astr1:
+ sql = "GRANT %s ON %s\n TO %s;" % (astr1, qtarget, qrole)
+ sql_list.append(sql)
+ if astr2:
+ sql = "GRANT %s ON %s\n TO %s WITH GRANT OPTION;" % (astr2, qtarget, qrole)
+ sql_list.append(sql)
return "\n".join(sql_list)
def get_drop_sql(self, curs):