This repository has been archived by the owner on Feb 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cache.py
91 lines (69 loc) · 2.44 KB
/
cache.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import os
import boto3
import time
client = boto3.client('cloudfront')
def display_title_bar():
os.system('clear')
print("\n\n")
print("\t**********************************************")
print("\t*** cdn and cache control ***")
print("\t**********************************************")
print("\n")
def get_user_choice():
print("\t[1] Listar Distribuições.")
print("\t[q] Sair.")
print("\n")
return input("\tEscolha uma opção: ")
def show_distributions():
display_title_bar()
response = client.list_distributions()
dlist = response['DistributionList']
lines = dlist['Quantity']
if (lines <= 0):
print("\tNenhuma distribuição encontrada.")
return
dists = []
count = 0
for dist in dlist['Items']:
id = dist['Id']
print("\t[%s] " % count + id + " (" + dist['Status'] + ")")
print("\t" + dist['DomainName'])
dists.insert(count, id)
count += 1
if ('Items' in dist['Aliases']):
for domain in dist['Aliases']['Items']:
print("\t" + domain)
else:
for domain in dist['Origins']['Items']:
print("\t" + domain['DomainName'])
print("\n")
option = input("\tQual cache deseja limpar? (ou 'q' para sair): ")
if option == 'q':
print("\n")
return
path = input("\tCaminho do arquivo ou pattern: ")
if len(dists) >= int(option):
selected = dists[int(option)]
print("\n\tCache Zerado: %s" % selected)
invalidation = client.create_invalidation(DistributionId=selected,
InvalidationBatch={
'Paths': {
'Quantity': 1,
'Items': [path]
},
'CallerReference': str(time.time())
})
print("\tStatus: %s" % invalidation['Invalidation']['Status'])
print("\n")
else:
show_distributions()
def menu():
if choice == '1':
show_distributions()
elif choice == 'q':
print("\n\tVolte sempre!")
else:
print("\n\tOpção Inválida.")
display_title_bar()
choice = get_user_choice()
menu()