-
Notifications
You must be signed in to change notification settings - Fork 0
/
bigid_data.py
executable file
·84 lines (69 loc) · 2.44 KB
/
bigid_data.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
import os
import json
import requests
import urllib3
from getpass import getpass
# Gather BigID-related Information
# Disable HTTPS Cert Warnings
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
if "BIGID_UI_HOST_EXT" in list(os.environ):
bigid_url = os.environ["BIGID_UI_HOST_EXT"]
bigid_api_url = bigid_url + "/api/v1"
else:
bigid_url = input("BigID URL (https://<host>): ")
bigid_api_url = bigid_url + "/api/v1"
if "BIGID_USER" in list(os.environ):
bigid_user = os.environ["BIGID_USER"]
else:
bigid_user = input("BigID Username: ")
if "BIGID_PASSWORD" in list(os.environ):
bigid_password = os.environ["BIGID_PASSWORD"]
else:
bigid_password = getpass("BigID Password: ")
def bigid_token():
"""Retrieve Access Token from BigID"""
url = bigid_api_url + '/sessions'
headers = {"Accept": "application/json"}
data = {"username": bigid_user, "password": bigid_password}
response = requests.post(url, data=data, headers=headers, verify=False)
if response.status_code != 200:
print("Status:", response.status_code, "Headers:", response.headers,
"Response:", response.json())
print("Cookies", response.cookies)
data = response.json()
return data["auth_token"]
def bigid_release():
"""Get BigID Release"""
url = bigid_url + "/about.html"
headers = {}
result = {
"release-info": requests.get(url, verify=False,
headers=headers).text.replace("\n",' ')
}
return result
def config(source):
"""
Get configuration for SAR, Data Source or Entity Source
Accepted parameters:
ds_connections: Return Data Source configuration
id_connections: Return Entity Source configuration
sar/config: Returns SAR Configuration
"""
token = bigid_token()
url = bigid_api_url + "/" + source
payload = {}
headers = {"Authorization": token}
response = requests.request("GET", url, headers=headers, data=payload,
verify=False)
result = response.json()
return result
def bigid_logs():
"""Retrieve BigID Services Logs
TODO: Enhance function to pull/request individual logs
"""
log_url = bigid_api_url + "/services-logs"
token = bigid_token()
headers = {"Authorization": token}
response = requests.get(log_url, headers=headers, stream=True)
with open("services-logs.zip", "wb") as f:
f.write(response.content)