Skip to content

Commit 5db101d

Browse files
author
João Guerreiro
committed
fix(example): update examples with 1.0.3
1 parent 0aeddda commit 5db101d

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

examples/content_scan.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
client = GGClient(api_key=API_KEY)
2020

2121
# Check the health of the API and the API key used.
22-
health_obj, status = client.health_check()
22+
health_obj = client.health_check()
2323

24-
if status == codes[r"\o/"]: # this is 200 but cooler
24+
if health_obj.status_code == codes[r"\o/"]: # this is 200 but cooler
2525
try:
2626
scan_result = client.content_scan(filename=FILENAME, document=DOCUMENT)
2727
except Exception as exc:

examples/directory_scan.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
# Create a list of dictionaries for scanning
1515
to_scan = []
16-
for name in glob.glob("**/*"):
16+
for name in glob.glob("**/*", recursive=True):
1717
with open(name) as fn:
1818
to_scan.append({"document": fn.read(), "filename": os.path.basename(name)})
1919

@@ -22,14 +22,21 @@
2222
for i in range(0, len(to_scan), MULTI_DOCUMENT_LIMIT):
2323
chunk = to_scan[i : i + MULTI_DOCUMENT_LIMIT]
2424
try:
25-
scan, status_code = client.multi_content_scan(chunk)
25+
scan = client.multi_content_scan(chunk)
2626
except Exception as exc:
2727
# Handle exceptions such as schema validation
2828
traceback.print_exc(2, file=sys.stderr)
2929
print(str(exc))
30-
if status_code != 200:
30+
if not scan.success:
3131
print("Error scanning some files. Results may be incomplete.")
32-
to_process.extend(scan)
32+
print(scan)
33+
to_process.extend(scan.scan_results)
34+
continue
3335

34-
for scan_result in to_process:
35-
print("Scan results:", scan_result.has_secrets, "-", scan_result.policy_break_count)
36+
for i, scan_result in enumerate(to_process):
37+
if scan_result.has_secrets:
38+
print(f"{chunk[i]['filename']}: {scan_result.policy_break_count} break/s found")
39+
for policy_break in scan_result.policy_breaks:
40+
print(f"\t{policy_break.break_type}:")
41+
for match in policy_break.matches:
42+
print(f"\t\t{match.match_type}:{match.match}")

0 commit comments

Comments
 (0)