Skip to content
This repository was archived by the owner on Feb 5, 2024. It is now read-only.

Commit 0c3d93a

Browse files
committed
Add some ACL and Dictionary functionalities
1 parent 8b32710 commit 0c3d93a

3 files changed

Lines changed: 125 additions & 4 deletions

File tree

fastly/__init__.py

Lines changed: 123 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -967,7 +967,72 @@ def delete_wordpress(self, service_id, version_number, name):
967967
def delete_version(self, service_id, version_number):
968968
content = self._fetch("/service/%s/version/%d" % (service_id, version_number), method="DELETE")
969969
return self._status(content)
970-
970+
971+
# ACL related methods
972+
def get_acl(self, service_id, version_number, name):
973+
content = self._fetch("/service/{}/version/{}/acl/{}".format(service_id, version_number, name))
974+
return FastlyACL(self, content)
975+
976+
def create_acl(self, service_id, version_number, name):
977+
body = self._formdata({
978+
"name": name,
979+
}, ["name"])
980+
981+
content = self._fetch("/service/{}/version/{}/acl".format(service_id, version_number), method="POST", body=body)
982+
return FastlyACL(self, content)
983+
984+
def create_acl_entry(self, service_id, acl_id, ip, subnet=None):
985+
body = self._formdata({
986+
"ip": ip,
987+
"subnet": subnet,
988+
}, ["ip", "subnet"])
989+
990+
content = self._fetch("/service/{}/acl/{}/entry".format(service_id, acl_id), method="POST", body=body)
991+
return FastlyACLEntry(self, content)
992+
993+
def get_acl_entries(self, service_id, acl_id):
994+
content = self._fetch("/service/{}/acl/{}/entries".format(service_id, acl_id))
995+
result = []
996+
for el in content:
997+
result.append(FastlyACLEntry(self, el))
998+
999+
return result
1000+
1001+
def delete_acl_entry(self, service_id, acl_id, id):
1002+
content = self._fetch("/service/{}/acl/{}/entry/{}".format(service_id, acl_id, id), method="DELETE")
1003+
return self._status(content)
1004+
1005+
# Dictionary related methods
1006+
def get_dic(self, service_id, version_number, name):
1007+
content = self._fetch("/service/{}/version/{}/dictionary/{}".format(service_id, version_number, name))
1008+
return FastlyDictionary(self, content)
1009+
1010+
def create_dic(self, service_id, version_number, name):
1011+
body = self._formdata({
1012+
"name": name,
1013+
}, ["name"])
1014+
1015+
content = self._fetch("/service/{}/version/{}/dictionary".format(service_id, version_number), method="POST", body=body)
1016+
return FastlyDictionary(self, content)
1017+
1018+
def create_dic_item(self, service_id, dic_id, key, value):
1019+
body = self._formdata({
1020+
"item_key": key,
1021+
"item_value": value,
1022+
}, ["item_key", "item_value"])
1023+
1024+
content = self._fetch("/service/{}/dictionary/{}/item".format(service_id, dic_id), method="POST", body=body)
1025+
return FastlyDictionaryItem(self, content)
1026+
1027+
def get_dic_item(self, service_id, dic_id, key):
1028+
content = self._fetch("/service/{}/dictionary/{}/item/{}".format(service_id, dic_id, key))
1029+
return FastlyDictionaryItem(self, content)
1030+
1031+
def delete_dic_item(self, service_id, dic_id, key):
1032+
key = urllib.parse.quote(key, safe='')
1033+
content = self._fetch("/service/{}/dictionary/{}/item/{}".format(service_id, dic_id, key), method="DELETE")
1034+
return self._status(content)
1035+
9711036
def _status(self, status):
9721037
if not isinstance(status, FastlyStatus):
9731038
status = FastlyStatus(self, status)
@@ -990,7 +1055,6 @@ def _fetch(self, url, method="GET", body=None, headers={}):
9901055
hdrs = {}
9911056
hdrs.update(headers)
9921057

993-
print("Fetch: %s %s" % (method, url))
9941058
if body:
9951059
print("Body: %s" % body)
9961060
hdrs["Fastly-Key"] = self._token
@@ -1532,6 +1596,63 @@ class FastlyWordpress(FastlyObject, IServiceVersionObject):
15321596
]
15331597

15341598

1599+
class FastlyACL(FastlyObject, object):
1600+
"""An ACL is a named access control list for matching against a client's IP address during VCL processing"""
1601+
FIELDS = [
1602+
"id",
1603+
"name",
1604+
"version",
1605+
"service_id",
1606+
"created_at",
1607+
"updated_at",
1608+
"deleted_at",
1609+
]
1610+
1611+
1612+
class FastlyACLEntry(FastlyObject, object):
1613+
"""An ACL entry holds an IP address with optional subnet to make up an entry in an ACL"""
1614+
FIELDS = [
1615+
"ip",
1616+
"subnet",
1617+
"acl_id",
1618+
"negated",
1619+
"comment",
1620+
"id",
1621+
"service_id",
1622+
]
1623+
1624+
1625+
class FastlyDictionary(FastlyObject, object):
1626+
"""A Dictionary is a table that stores key value pairs accessible to VCL functions during VCL processing"""
1627+
FIELDS = [
1628+
"id",
1629+
"name",
1630+
"version",
1631+
"service_id",
1632+
"created_at",
1633+
"updated_at",
1634+
"deleted_at",
1635+
]
1636+
1637+
1638+
class FastlyDictionaryItem(FastlyObject, object):
1639+
"""A DictionaryItem holds a key and value that make up an entry in a Dictionary"""
1640+
FIELDS = [
1641+
"item_key",
1642+
"item_value",
1643+
"dictionary_id",
1644+
"service_id",
1645+
]
1646+
1647+
@property
1648+
def key(self):
1649+
return self.item_key
1650+
1651+
@property
1652+
def value(self):
1653+
return self.item_value
1654+
1655+
15351656
def connect(token):
15361657
conn = FastlyConnection(token)
15371658
return conn

fastly/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '1.0.5'
1+
__version__ = '1.1.0'

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ def read(fname):
66

77
setup(
88
name="fastly-python",
9-
version="1.0.5",
9+
version="1.1.0",
1010
author="Chris Zacharias",
1111
author_email="chris@imgix.com",
1212
description=("A Python client libary for the Fastly API."),

0 commit comments

Comments
 (0)