Skip to content

Instantly share code, notes, and snippets.

@cbare
Last active December 24, 2015 06:38
Show Gist options
  • Select an option

  • Save cbare/6758004 to your computer and use it in GitHub Desktop.

Select an option

Save cbare/6758004 to your computer and use it in GitHub Desktop.
A Python script for bulk manipulation of ACLs in Synapse
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