-
Notifications
You must be signed in to change notification settings - Fork 723
/
Copy pathaccesssettings.py
82 lines (68 loc) · 2.02 KB
/
accesssettings.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
import sendgrid
import os
sg = sendgrid.SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
##################################################
# Retrieve all recent access attempts #
# GET /access_settings/activity #
params = {'limit': 1}
response = sg.client.access_settings.activity.get(query_params=params)
print(response.status_code)
print(response.body)
print(response.headers)
##################################################
# Add one or more IPs to the whitelist #
# POST /access_settings/whitelist #
data = {
"ips": [
{
"ip": "192.168.1.1"
},
{
"ip": "192.*.*.*"
},
{
"ip": "192.168.1.3/32"
}
]
}
response = sg.client.access_settings.whitelist.post(request_body=data)
print(response.status_code)
print(response.body)
print(response.headers)
##################################################
# Retrieve a list of currently whitelisted IPs #
# GET /access_settings/whitelist #
response = sg.client.access_settings.whitelist.get()
print(response.status_code)
print(response.body)
print(response.headers)
##################################################
# Remove one or more IPs from the whitelist #
# DELETE /access_settings/whitelist #
data = {
"ids": [
1,
2,
3
]
}
response = sg.client.access_settings.whitelist.delete(request_body=data)
print(response.status_code)
print(response.body)
print(response.headers)
##################################################
# Retrieve a specific whitelisted IP #
# GET /access_settings/whitelist/{rule_id} #
rule_id = "test_url_param"
response = sg.client.access_settings.whitelist._(rule_id).get()
print(response.status_code)
print(response.body)
print(response.headers)
##################################################
# Remove a specific IP from the whitelist #
# DELETE /access_settings/whitelist/{rule_id} #
rule_id = "test_url_param"
response = sg.client.access_settings.whitelist._(rule_id).delete()
print(response.status_code)
print(response.body)
print(response.headers)