-
Notifications
You must be signed in to change notification settings - Fork 15
/
content_scan.py
41 lines (33 loc) · 1.07 KB
/
content_scan.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
import os
import sys
import traceback
from requests import codes
from pygitguardian import GGClient
from pygitguardian.models import ScanResult
API_KEY = os.getenv("GITGUARDIAN_API_KEY", "")
FILENAME = ".env"
DOCUMENT = """
import urllib.request
url = 'http://jen_barber:[email protected]/isreal.json'
response = urllib.request.urlopen(url)
consume(response.read())"
"""
client = GGClient(api_key=API_KEY)
# Check the health of the API and the API key used.
health_obj = client.health_check()
if health_obj.status_code == codes[r"\o/"]: # this is 200 but cooler
try:
scan_result = client.content_scan(filename=FILENAME, document=DOCUMENT)
except Exception as exc:
# Handle exceptions such as schema validation
traceback.print_exc(2, file=sys.stderr)
print(str(exc))
if isinstance(scan_result, ScanResult):
print(
"Scan results:",
scan_result.has_secrets,
"-",
scan_result.policy_break_count,
)
else:
print("Invalid API Key")