Skip to content

Commit

Permalink
Add possibility to retrieve results from API action scans->get_results
Browse files Browse the repository at this point in the history
  • Loading branch information
cristianp-fossid committed Apr 13, 2024
1 parent bab9d6e commit 0440837
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions workbench-agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,36 @@ def get_scan_identified_licenses(self, scan_code: str):
)
)

def get_results(self, scan_code: str):
"""
Retrieve the list matches from one scan.
Args:
scan_code (str): The unique identifier for the scan.
Returns:
dict: The JSON response from the API.
"""
payload = {
"group": "scans",
"action": "get_results",
"data": {
"username": self.api_user,
"key": self.api_token,
"scan_code": scan_code,
"unique": "1",
},
}
response = self._send_request(payload)
if response["status"] == "1" and "data" in response.keys():
return response["data"]
raise builtins.Exception(
"Error getting scans ->get_results \
result: {}".format(
response
)
)

def _get_dependency_analysis_result(self, scan_code: str):
"""
Retrieve dependency analysis results.
Expand Down Expand Up @@ -1046,6 +1076,15 @@ def non_empty_string(s):
action="store_true",
default=False,
)
optional.add_argument(
"--scans_get_results",
help="By default at the end of scanning the list of licenses identified will be retrieved.\n"
"When passing this parameter the agent will return information about policy warnings found in this scan\n"
"based on policy rules set at Project level.\n"
"This argument expects no value, not passing this argument is equivalent to assigning false.",
action="store_true",
default=False,
)

args = parser.parse_args()
return args
Expand Down Expand Up @@ -1287,6 +1326,15 @@ def main():
print(json.dumps(info_policy))
save_results(params=params, results=info_policy)
sys.exit(0)
# When scan finished retrieve project policy warnings info
# projects -> get_policy_warnings_info
elif params.scans_get_results:

print(f"Scan {params.scan_code} results: ")
results = workbench.get_results(params.scan_code)
print(json.dumps(results))
save_results(params=params, results=results)
sys.exit(0)
else:
print("Identified licenses: ")
identified_licenses = workbench.get_scan_identified_licenses(params.scan_code)
Expand Down

0 comments on commit 0440837

Please sign in to comment.