X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=dak%2Facl.py;h=568e21e46b6c28990c24e6e54f1eb8335068d5ae;hb=c8349f01107a0ba259421b8527d9adfd64606576;hp=f38a3a600a3f2ec5cddfb42c0ca91a158d690df2;hpb=56c0f386e8da9aaac70dcb60a5eb1ef9a9e38877;p=dak.git diff --git a/dak/acl.py b/dak/acl.py index f38a3a60..568e21e4 100644 --- a/dak/acl.py +++ b/dak/acl.py @@ -23,9 +23,17 @@ from daklib.config import Config from daklib.dbconn import DBConn, Fingerprint, 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): @@ -72,12 +80,47 @@ def acl_set_fingerprints(acl_name, entries): session.commit() +def acl_export_per_source(acl_name): + session = DBConn().session() + acl = session.query(ACL).filter_by(name=acl_name).one() + + query = """ + 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) + FROM acl_per_source a + JOIN fingerprint f ON a.fingerprint_id = f.id + LEFT JOIN uid u ON f.uid = u.id + WHERE a.acl_id = :acl_id + GROUP BY f.id, f.fingerprint + ORDER BY name + """ + + for row in session.execute(query, {'acl_id': acl.id}): + print "Fingerprint:", row[0] + print "Uid:", row[1] + print "Allow:", row[2] + print + + session.rollback() + session.close() + def main(argv=None): if argv is None: argv = sys.argv - if len(argv) != 3 or argv[1] != 'set-fingerprints': + if len(argv) != 3: usage() sys.exit(1) - acl_set_fingerprints(argv[2], sys.stdin) + if argv[1] == 'set-fingerprints': + acl_set_fingerprints(argv[2], sys.stdin) + elif argv[1] == 'export-per-source': + acl_export_per_source(argv[2]) + else: + usage() + sys.exit(1)