Last active
December 24, 2015 06:38
-
-
Save cbare/6758004 to your computer and use it in GitHub Desktop.
A Python script for bulk manipulation of ACLs in Synapse
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import collections | |
| import synapseclient | |
| from synapseclient.utils import id_of | |
| syn = synapseclient.Synapse() | |
| syn.login() | |
| def copy_acl(source_entity, destination_entities, overwrite_existing=False): | |
| acl = syn._getACL(source_entity) | |
| for key in ['id','url','etag','creationDate']: | |
| if key in acl: | |
| del acl[key] | |
| return apply_acl(acl, entities=destination_entities, overwrite_existing=overwrite_existing) | |
| def apply_acl(acl, entities, overwrite_existing=False): | |
| if not isinstance(entities, collections.Iterable): | |
| entities = [entities] | |
| new_acls = [] | |
| for entity in entities: | |
| existing = syn._getACL(entity) | |
| if existing['id']==id_of(entity): | |
| if overwrite_existing: | |
| existing['resourceAccess'] = acl['resourceAccess'] | |
| new_acls.append(syn._storeACL(entity, existing)) | |
| else: | |
| raise Exception('entity %s already has it\'s own ACL' % id_of(entity)) | |
| else: | |
| new_acls.append(syn._storeACL(entity, acl)) | |
| return new_acls |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment