Skip to content

Commit ae8b4d7

Browse files
committed
example update
1 parent 19de70e commit ae8b4d7

File tree

3 files changed

+31
-10
lines changed

3 files changed

+31
-10
lines changed

api_example.py

+20-8
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,31 @@
11
from cxone_api import AuthUS, ApiUS, paged_api, CxOneClient
2-
from cxone_api.repo import ProjectRepoConfig
2+
from cxone_api.repo import download_files_to_directory
33
import os, asyncio
44

55

66
async def main():
77
cxone_client = CxOneClient.create_with_oauth(os.environ["OAUTH_CLIENTID"], os.environ["OAUTH_CLIENTSECRET"], "CxOneAPIExample",
88
AuthUS(os.environ["TENANT"]), ApiUS())
9-
10-
#async for scan in paged_api(cxone_client.get_scans, "scans", statuses=['Completed']):
11-
# print(f"Scan Id: {scan['id']} ProjectId: {scan['projectId']} Branch: {scan['branch']}")
12-
# pass
139

10+
# print ((await cxone_client.get_repostore_project_tree("153a99d4-686e-4fe9-970d-c68b5d0f83c7")).json())
11+
12+
# print((await cxone_client.get_repostore_folder("153a99d4-686e-4fe9-970d-c68b5d0f83c7", "input/client/public")).json())
1413

15-
for scan in cxone_client.get_project_last_scans(limit=20):
16-
print(f"Scan Id: {scan['id']}")
17-
pass
14+
# print((await cxone_client.get_repostore_file("153a99d4-686e-4fe9-970d-c68b5d0f83c7", "input/client/src/index.js")).text)
15+
16+
# async for scan in paged_api(cxone_client.get_scans, "scans", statuses=['Completed']):
17+
# print(f"Scan Id: {scan['id']} ProjectId: {scan['projectId']} Branch: {scan['branch']}")
18+
19+
# print((await cxone_client.get_scan("153a99d4-686e-4fe9-970d-c68b5d0f83c7")).json())
20+
21+
# await download_files_to_directory('153a99d4-686e-4fe9-970d-c68b5d0f83c7', 'test')
22+
23+
last_scan_dict = (await cxone_client.get_project_last_scans(limit=20)).json()
24+
25+
for scan in last_scan_dict:
26+
print(f"Scan Id: {last_scan_dict[scan]}")
27+
# Paging has to be redone manually without page_api
28+
29+
1830

1931
asyncio.run(main())

cxone_api/__init__.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,8 @@ async def get_project(self, projectid):
368368

369369
async def get_project_last_scans(self, **kwargs):
370370
url = urljoin(self.api_endpoint, f"projects/last-scan")
371-
return await self.__exec_request(requests.get, url, json=kwargs)
371+
url = CxOneClient.__join_query_dict(url, kwargs)
372+
return await self.__exec_request(requests.get, url)
372373

373374
async def get_project_configuration(self, projectid):
374375
url = urljoin(self.api_endpoint, f"configuration/project?project-id={projectid}")
@@ -383,7 +384,11 @@ async def get_scans(self, **kwargs):
383384
url = urljoin(self.api_endpoint, "scans")
384385
url = CxOneClient.__join_query_dict(url, kwargs)
385386
return await self.__exec_request(requests.get, url)
386-
387+
388+
async def get_scan(self, scanid):
389+
url = urljoin(self.api_endpoint, f"scans/{scanid}")
390+
return await self.__exec_request(requests.get, url)
391+
387392
@dashargs("scan-ids")
388393
async def get_sast_scans_metadata(self, **kwargs):
389394
url = urljoin(self.api_endpoint, "sast-metadata")

cxone_api/repo.py

+4
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,7 @@ async def primary_branch(self):
3232
async def repo_url(self):
3333
url = await self.__get_logical_repo_url()
3434
return url if len(url) > 0 else None
35+
36+
37+
async def download_files_to_directory(cxone_client, scanid, dest_directory):
38+
pass

0 commit comments

Comments
 (0)