@@ -57,19 +57,16 @@ DOCUMENT = """
57
57
client = GGClient(api_key = API_KEY )
58
58
59
59
# Check the health of the API and the API key used.
60
- health_obj, status = client.health_check()
61
-
62
- if status != codes[r " \o /" ]: # this is 200 but cooler
60
+ if client.health_check().success:
61
+ try :
62
+ scan_result = client.content_scan(DOCUMENT )
63
+ except Exception as exc:
64
+ # Handle exceptions such as schema validation
65
+ traceback.print_exc(2 , file = sys.stderr)
66
+ print (str (exc))
67
+ print (scan_result)
68
+ else :
63
69
print (" Invalid API Key" )
64
-
65
- try :
66
- scan_result = client.content_scan(DOCUMENT )
67
- except Exception as exc:
68
- # Handle exceptions such as schema validation
69
- traceback.print_exc(2 , file = sys.stderr)
70
- print (str (exc))
71
-
72
- print (" Scan results:" , scan_result.has_secrets, " -" , scan_result.policy_break_count)
73
70
```
74
71
75
72
### Scanning multiple files
@@ -79,11 +76,11 @@ API_KEY = os.getenv("GG_API_KEY")
79
76
client = GGClient(api_key = API_KEY )
80
77
# Create a list of dictionaries for scanning
81
78
to_scan = []
82
- for name in glob.glob(" **/*" ):
79
+ for name in glob.glob(" **/*" , recursive = True ):
83
80
with open (name) as fn:
84
81
to_scan.append({" document" : fn.read(), " filename" : os.path.basename(name)})
85
82
86
- scan, status_code = client.multi_content_scan(to_scan)
83
+ scan = client.multi_content_scan(to_scan)
87
84
```
88
85
89
86
### Transform results to dict or JSON
0 commit comments