X-Git-Url: https://git.decadent.org.uk/gitweb/?p=dak.git;a=blobdiff_plain;f=dak%2Facl.py;h=a6fdddd953c041d13bd74a348bc9aec3fb7d8975;hp=075c722b5842bfd05f3b3269818480369c115a87;hb=519c1dbf89c13557afc15a429164616ac563d379;hpb=9eff87cf703b5fe3310570ab30ff922e62f2957a diff --git a/dak/acl.py b/dak/acl.py index 075c722b..a6fdddd9 100644 --- a/dak/acl.py +++ b/dak/acl.py @@ -20,12 +20,20 @@ import apt_pkg import sys from daklib.config import Config -from daklib.dbconn import DBConn, Fingerprint, Uid, ACL +from daklib.dbconn import DBConn, Fingerprint, Keyring, Uid, ACL def usage(): - print """Usage: dak acl set-fingerprints + print """Usage: + dak acl set-fingerprints + dak acl export-per-source -Reads list of fingerprints from stdin and sets the ACL to these. + set-fingerprints: + Reads list of fingerprints from stdin and sets the ACL to these. + Accepted input formats are "uid:", "name:" and + "fpr:". + + export-per-source: + Export per source upload rights for ACL . """ def get_fingerprint(entry, session): @@ -36,6 +44,7 @@ def get_fingerprint(entry, session): uid: name: fpr: + keyring: @type entry: string @param entry: ACL entry @@ -46,7 +55,7 @@ def get_fingerprint(entry, session): @return: fingerprint for the entry """ field, value = entry.split(":", 1) - q = session.query(Fingerprint) + q = session.query(Fingerprint).join(Fingerprint.keyring).filter(Keyring.active == True) if field == 'uid': q = q.join(Fingerprint.uid).filter(Uid.uid == value) @@ -54,6 +63,10 @@ def get_fingerprint(entry, session): q = q.join(Fingerprint.uid).filter(Uid.name == value) elif field == 'fpr': q = q.filter(Fingerprint.fingerprint == value) + elif field == 'keyring': + q = q.filter(Keyring.keyring_name == value) + else: + raise Exception('Unknown selector "{0}".'.format(field)) return q.all() @@ -64,6 +77,9 @@ def acl_set_fingerprints(acl_name, entries): acl.fingerprints.clear() for entry in entries: entry = entry.strip() + if entry.startswith('#') or len(entry) == 0: + continue + fps = get_fingerprint(entry, session) if len(fps) == 0: print "Unknown key for '{0}'".format(entry) @@ -76,14 +92,17 @@ def acl_export_per_source(acl_name): session = DBConn().session() acl = session.query(ACL).filter_by(name=acl_name).one() - query = """ + query = r""" SELECT f.fingerprint, (SELECT COALESCE(u.name, '') || ' <' || u.uid || '>' FROM uid u JOIN fingerprint f2 ON u.id = f2.uid WHERE f2.id = f.id) AS name, - STRING_AGG(a.source, ' ' ORDER BY a.source) + STRING_AGG( + a.source + || COALESCE(' (' || (SELECT fingerprint FROM fingerprint WHERE id = a.created_by_id) || ')', ''), + E',\n ' ORDER BY a.source) FROM acl_per_source a JOIN fingerprint f ON a.fingerprint_id = f.id LEFT JOIN uid u ON f.uid = u.id