-
Notifications
You must be signed in to change notification settings - Fork 0
/
symantecClass.py
57 lines (52 loc) · 1.96 KB
/
symantecClass.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
import json
import datetime
import requests
from urllib.parse import urlparse
from requests.packages.urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
class connector(object):
def __init__(self, url_base, proxy):
self.token = "Bearer "
self.domainId = ""
self.proxy = proxy
self.url_base = url_base
self.connect = requests.session()
self.connect.verify = False
self.disable_warnings = True
def authorize(self, uname, pwd):
self.connect.headers.update({'Content-Type':'application/json'})
payload = {
"username" : uname,
"password" : pwd
}
try:
resp = self.connect.post('{0}/identity/authenticate'.format(self.url_base), data=json.dumps(payload), proxies=self.proxy)
if resp.status_code >= 200 and resp.status_code < 300:
self.token = self.token + resp.json()['token']
self.domainId = resp.json()['domainid']
return resp.status_code, self.domainId
except Exception as e:
return 0, e
def get_list(self, list_name):
self.connect.headers.update({'Content-Type':'application/json'})
self.connect.headers.update({'Authorization':self.token})
try:
resp = self.connect.get('{0}/policy-objects/fingerprints'.format(self.url_base), params={'name':list_name}, proxies=self.proxy)
return resp.status_code, resp.json()
except Exception as e:
return 0, e
def update_list(self, list_id, list_name, hash_type, description, list):
self.connect.headers.update({'Content-Type':'application/json'})
self.connect.headers.update({'Authorization':self.token})
payload = {
'name': list_name,
'hashType': hash_type,
'description': description,
'data': list,
'domainId': self.domainId
}
try:
resp = self.connect.post('{0}/policy-objects/fingerprints/{1}'.format(self.url_base, list_id), data=json.dumps(payload), proxies=self.proxy)
return resp.status_code, ""
except Exception as e:
return 0, e