-
Notifications
You must be signed in to change notification settings - Fork 619
/
Copy pathutils.py
42 lines (33 loc) · 989 Bytes
/
utils.py
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
import requests
from django.conf import settings
def purge_url(path):
"""
Purge a Fastly.com URL given a path. path argument must begin with a slash
"""
if settings.DEBUG:
return
api_key = getattr(settings, 'FASTLY_API_KEY', None)
if api_key:
response = requests.request(
'PURGE',
f'https://www.python.org{path}',
headers={'Fastly-Key': api_key},
)
return response
return None
def purge_surrogate_key(key):
"""
Purge a Fastly.com Surrogate-Key given a key.
"""
if settings.DEBUG:
return
api_key = getattr(settings, 'FASTLY_API_KEY', None)
service_id = getattr(settings, 'FASTLY_SERVICE_ID', None)
if api_key and service_id:
response = requests.request(
"POST",
f'https://api.fastly.com/service/{service_id}/purge/{key}',
headers={'Fastly-Key': api_key},
)
return response
return None