forked from algorithmiaio/algorithmia-python
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathacl.py
More file actions
51 lines (43 loc) · 1.6 KB
/
Copy pathacl.py
File metadata and controls
51 lines (43 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
class Acl(object):
def __init__(self, read_acl):
self.read_acl = read_acl
@staticmethod
def from_acl_response(acl_response):
'''Takes JSON response from API and converts to ACL object'''
if 'read' in acl_response:
read_acl = AclType.from_acl_response(acl_response['read'])
return Acl(read_acl)
else:
raise ValueError('Response does not contain read ACL')
def to_api_param(self):
read_acl_string = self.read_acl.acl_string
if read_acl_string is None:
return {'read':[]}
return {'read':[read_acl_string]}
class AclInner(object):
def __init__(self, pseudonym, acl_string):
self.pseudonym = pseudonym
self.acl_string = acl_string
def __repr__(self):
return 'AclType(pseudonym=%s,acl_string=%s)' % (self.pseudonym, self.acl_string)
class AclType(object):
public = AclInner('public','user://*')
my_algos = AclInner('my_algos','algo://.my/*')
private = AclInner('private',None) # Really is an empty list
default = my_algos
types = (public, my_algos, private)
@staticmethod
def from_acl_response(acl_list):
if len(acl_list) == 0:
return AclType.private
else:
acl_string = acl_list[0]
for t in AclType.types:
if t.acl_string == acl_string:
return t
else:
raise ValueError('Invalid acl string %s' % (acl_list[0]))
class ReadAcl(object):
public = Acl(AclType.public)
private = Acl(AclType.private)
my_algos = Acl(AclType.my_algos)