-
Notifications
You must be signed in to change notification settings - Fork 0
/
defs.py
117 lines (105 loc) · 4.59 KB
/
defs.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import requests
import vars
import json
import os
def get_token():
global token
url = 'https://auth.apps.paloaltonetworks.com/oauth2/access_token'
headers = {
'Content-Type': 'application/x-www-form-urlencoded',
}
data = 'grant_type=client_credentials&scope=tsg_id:' + vars.tsgid
response = requests.post(
url,
headers=headers,
data=data,
auth=(vars.clientid, vars.clientsecret),
)
output=json.loads(response.text)
token = output['access_token']
if response.status_code != 200:
print('error: ' + str(response.status_code))
else:
return token
token = get_token()
payload={}
headers = {
'Accept': 'application/json',
'Authorization': 'Bearer ' + token
}
headersPost = {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + token
}
def get_running_config():
url = "https://api.sase.paloaltonetworks.com/sse/config/v1/config-versions/running"
response = requests.request("GET", url, headers=headers, data=payload)
print(response.text)
def get_config():
#currently set as version 33
url = "https://api.sase.paloaltonetworks.com/sse/config/v1/config-versions/33"
response = requests.request("GET", url, headers=headers, data=payload)
print(response.text)
def list_candidate():
url = "https://api.sase.paloaltonetworks.com/sse/config/v1/config-versions"
response = requests.request("GET", url, headers=headers, data=payload)
print(response.text)
def get_shared_post_security_rules():
url = "https://api.sase.paloaltonetworks.com/sse/config/v1/security-rules?position=post&folder=Shared"
response = requests.request("GET", url, headers=headers, data=payload)
print(response.text)
with open(os.path.join("output/shared_post_security_rules.json"), "a") as file:
json.dump(response.json(), file)
def put_shared_post_security_rules():
url = "https://api.sase.paloaltonetworks.com/sse/config/v1/security-rules?position=post&folder=Shared"
with open(os.path.join("output/shared_post_security_rules.json"), "r") as file:
payload = json.load(file)
response = requests.request("POST", url, headers=headersPost, json=payload)
print(response.text)
def get_global_url_access_profiles():
url = "https://api.sase.paloaltonetworks.com/sse/config/v1/url-access-profiles?folder=Shared"
response = requests.request("GET", url, headers=headers, data=payload)
print(response.text)
with open(os.path.join("output/global_url_access_profile.json"), "a") as file:
json.dump(response.json(), file)
def put_global_url_access_profiles():
url = "https://api.sase.paloaltonetworks.com/sse/config/v1/url-access-profiles?folder=All"
with open(os.path.join("output/global_url_access_profile.json"), "r") as file:
payload = json.load(file)
response = requests.request("POST", url, headers=headersPost, json=payload)
print(response.text)
def get_global_file_blocking_profiles():
url = "https://api.sase.paloaltonetworks.com/sse/config/v1/file-blocking-profiles?folder=Shared"
response = requests.request("GET", url, headers=headers, data=payload)
print(response.text)
with open(os.path.join("output/global_file_blocking_profile.json"), "a") as file:
json.dump(response.json(), file)
def put_global_file_blocking_profiles():
url = "https://api.sase.paloaltonetworks.com/sse/config/v1/file-blocking-profiles?folder=All"
with open(os.path.join("output/global_file_blocking_profile.json"), "r") as file:
payload = json.load(file)
response = requests.request("POST", url, headers=headersPost, json=payload)
print(response.text)
def get_global_objects_services():
url = "https://api.sase.paloaltonetworks.com/sse/config/v1/services?folder=Shared"
response = requests.request("GET", url, headers=headers, data=payload)
print(response.text)
with open(os.path.join("output/global_objects_services.json"), "a") as file:
json.dump(response.json(), file)
def put_global_objects_services():
url = "https://api.sase.paloaltonetworks.com/sse/config/v1/services?folder=All"
with open(os.path.join("output/global_objects_services.json"), "r") as file:
payload = json.load(file)
response = requests.request("POST", url, headers=headersPost, json=payload)
print(response.text)
#list_candidate()
#get_config()
#get_running_config()
#get_shared_post_security_rules()
#put_shared_post_security_rules()
#get_global_url_access_profiles()
#put_global_url_access_profiles()
#get_global_file_blocking_profiles()
#put_global_file_blocking_profiles()
#get_global_objects_services()
#put_global_objects_services()