@@ -984,7 +984,7 @@ def _formdata(self, fields, valid=[]):
984984 data [key ] = fields [key ]
985985 if isinstance (data [key ], bool ):
986986 data [key ] = str (int (data [key ]))
987- return urllib .urlencode (data )
987+ return urllib .parse . urlencode (data )
988988
989989 def get_acl (self , service_id , version_number , name ):
990990 content = self ._fetch ("/service/{}/version/{}/acl/{}" .format (service_id , version_number , name ))
@@ -998,6 +998,56 @@ def create_acl(self, service_id, version_number, name):
998998 content = self ._fetch ("/service/{}/version/{}/acl" .format (service_id , version_number ), method = "POST" , body = body )
999999 return FastlyACL (self , content )
10001000
1001+ def create_acl_entry (self , service_id , acl_id , ip , subnet = None ):
1002+ body = self ._formdata ({
1003+ "ip" : ip ,
1004+ "subnet" : subnet ,
1005+ }, ["ip" , "subnet" ])
1006+
1007+ content = self ._fetch ("/service/{}/acl/{}/entry" .format (service_id , acl_id ), method = "POST" , body = body )
1008+ return FastlyACLEntry (self , content )
1009+
1010+ def get_acl_entries (self , service_id , acl_id ):
1011+ content = self ._fetch ("/service/{}/acl/{}/entries" .format (service_id , acl_id ))
1012+ result = []
1013+ for el in content :
1014+ result .append (FastlyACLEntry (self , el ))
1015+
1016+ return result
1017+
1018+ def delete_acl_entry (self , service_id , acl_id , id ):
1019+ content = self ._fetch ("/service/{}/acl/{}/entry/{}" .format (service_id , acl_id , id ), method = "DELETE" )
1020+ return self ._status (content )
1021+
1022+ def get_dic (self , service_id , version_number , name ):
1023+ content = self ._fetch ("/service/{}/version/{}/dictionary/{}" .format (service_id , version_number , name ))
1024+ return FastlyDictionary (self , content )
1025+
1026+ def create_dic (self , service_id , version_number , name ):
1027+ body = self ._formdata ({
1028+ "name" : name ,
1029+ }, ["name" ])
1030+
1031+ content = self ._fetch ("/service/{}/version/{}/dictionary" .format (service_id , version_number ), method = "POST" , body = body )
1032+ return FastlyDictionary (self , content )
1033+
1034+ def create_dic_entry (self , service_id , dic_id , key , value ):
1035+ body = self ._formdata ({
1036+ "item_key" : key ,
1037+ "item_value" : value ,
1038+ }, ["item_key" , "item_value" ])
1039+
1040+ content = self ._fetch ("/service/{}/dictionary/{}/item" .format (service_id , dic_id ), method = "POST" , body = body )
1041+ return FastlyDictionaryItem (self , content )
1042+
1043+ def get_dic_entry (self , service_id , dic_id , key ):
1044+ content = self ._fetch ("/service/{}/dictionary/{}/item/{}" .format (service_id , dic_id , key ))
1045+ return FastlyDictionaryItem (self , content )
1046+
1047+ def delete_dic_entry (self , service_id , dic_id , key ):
1048+ content = self ._fetch ("/service/{}/dictionary/{}/item/{}" .format (service_id , dic_id , key ), method = "DELETE" )
1049+ return self ._status (content )
1050+
10011051 def _fetch (self , url , method = "GET" , body = None , headers = {}):
10021052 hdrs = {}
10031053 hdrs .update (headers )
@@ -1014,6 +1064,7 @@ def _fetch(self, url, method="GET", body=None, headers={}):
10141064
10151065 conn = httplib2 .Http (disable_ssl_certificate_validation = False , timeout = 10 )
10161066 endpoint = "%s://%s%s" % (FASTLY_SCHEME , FASTLY_HOST , url )
1067+ print (endpoint )
10171068 return self ._check (* conn .request (endpoint , method , body = body , headers = hdrs ))
10181069
10191070 def _check (self , resp , content ):
@@ -1544,7 +1595,7 @@ class FastlyWordpress(FastlyObject, IServiceVersionObject):
15441595 ]
15451596
15461597
1547- class FastlyACL (FastlyObject ):
1598+ class FastlyACL (FastlyObject , object ):
15481599 """An ACL is a named access control list for matching against a client's IP address during VCL processing"""
15491600 FIELDS = [
15501601 "id" ,
@@ -1557,6 +1608,50 @@ class FastlyACL(FastlyObject):
15571608 ]
15581609
15591610
1611+ class FastlyACLEntry (FastlyObject , object ):
1612+ """An ACL entry holds an IP address with optional subnet to make up an entry in an ACL"""
1613+ FIELDS = [
1614+ "ip" ,
1615+ "subnet" ,
1616+ "acl_id" ,
1617+ "negated" ,
1618+ "comment" ,
1619+ "id" ,
1620+ "service_id" ,
1621+ ]
1622+
1623+
1624+ class FastlyDictionary (FastlyObject , object ):
1625+ """A Dictionary is a table that stores key value pairs accessible to VCL functions during VCL processing"""
1626+ FIELDS = [
1627+ "id" ,
1628+ "name" ,
1629+ "version" ,
1630+ "service_id" ,
1631+ "created_at" ,
1632+ "updated_at" ,
1633+ "deleted_at" ,
1634+ ]
1635+
1636+
1637+ class FastlyDictionaryItem (FastlyObject , object ):
1638+ """A DictionaryItem holds a key and value that make up an entry in a Dictionary"""
1639+ FIELDS = [
1640+ "item_key" ,
1641+ "item_value" ,
1642+ "dictionary_id" ,
1643+ "service_id" ,
1644+ ]
1645+
1646+ @property
1647+ def key (self ):
1648+ return self .item_key
1649+
1650+ @property
1651+ def value (self ):
1652+ return self .item_value
1653+
1654+
15601655def connect (token ):
15611656 conn = FastlyConnection (token )
15621657 return conn
0 commit comments