Skip to content

Commit 3962ee4

Browse files
author
Dan Hertz
committed
add request metadata
1 parent 97abe6d commit 3962ee4

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

nightfall/api.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
import json
1212
import logging
1313
import os
14-
from functools import wraps
15-
from typing import List, Tuple, Optional
14+
from typing import Dict, List, Tuple, Optional
1615

1716
import requests
1817
from requests.adapters import HTTPAdapter
@@ -119,7 +118,8 @@ def _scan_text_v3(self, data: dict):
119118

120119
def scan_file(self, location: str, webhook_url: Optional[str] = None, policy_uuid: Optional[str] = None,
121120
detection_rules: Optional[List[DetectionRule]] = None,
122-
detection_rule_uuids: Optional[List[str]] = None) -> Tuple[str, str]:
121+
detection_rule_uuids: Optional[List[str]] = None,
122+
request_metadata: Optional[Dict[str, str]] = None) -> Tuple[str, str]:
123123
"""Scan file with Nightfall.
124124
At least one of policy_uuid, detection_rule_uuids or detection_rules is required.
125125
@@ -153,7 +153,8 @@ def scan_file(self, location: str, webhook_url: Optional[str] = None, policy_uui
153153
response = self._file_scan_scan(session_id,
154154
detection_rules=detection_rules,
155155
detection_rule_uuids=detection_rule_uuids,
156-
webhook_url=webhook_url, policy_uuid=policy_uuid)
156+
webhook_url=webhook_url, policy_uuid=policy_uuid,
157+
request_metadata=request_metadata)
157158
_validate_response(response, 200)
158159
parsed_response = response.json()
159160

@@ -200,7 +201,8 @@ def _file_scan_finalize(self, session_id: str):
200201

201202
def _file_scan_scan(self, session_id: str, detection_rules: Optional[List[DetectionRule]] = None,
202203
detection_rule_uuids: Optional[List[str]] = None, webhook_url: Optional[str] = None,
203-
policy_uuid: Optional[str] = None) -> requests.Response:
204+
policy_uuid: Optional[str] = None, request_metadata: Optional[Dict[str, str]] = None) \
205+
-> requests.Response:
204206
if policy_uuid:
205207
data = {"policyUUID": policy_uuid}
206208
else:
@@ -210,6 +212,9 @@ def _file_scan_scan(self, session_id: str, detection_rules: Optional[List[Detect
210212
if detection_rules:
211213
data["policy"]["detectionRules"] = [d.as_dict() for d in detection_rules]
212214

215+
if request_metadata:
216+
data["requestMetadata"] = request_metadata
217+
213218
response = self.session.post(url=self.FILE_SCAN_SCAN_ENDPOINT.format(session_id), data=json.dumps(data))
214219
return response
215220

0 commit comments

Comments
 (0)