Skip to content

Commit

Permalink
example update
Browse files Browse the repository at this point in the history
  • Loading branch information
nleach999 committed Apr 27, 2024
1 parent 19de70e commit ae8b4d7
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 10 deletions.
28 changes: 20 additions & 8 deletions api_example.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,31 @@
from cxone_api import AuthUS, ApiUS, paged_api, CxOneClient
from cxone_api.repo import ProjectRepoConfig
from cxone_api.repo import download_files_to_directory
import os, asyncio


async def main():
cxone_client = CxOneClient.create_with_oauth(os.environ["OAUTH_CLIENTID"], os.environ["OAUTH_CLIENTSECRET"], "CxOneAPIExample",
AuthUS(os.environ["TENANT"]), ApiUS())

#async for scan in paged_api(cxone_client.get_scans, "scans", statuses=['Completed']):
# print(f"Scan Id: {scan['id']} ProjectId: {scan['projectId']} Branch: {scan['branch']}")
# pass

# print ((await cxone_client.get_repostore_project_tree("153a99d4-686e-4fe9-970d-c68b5d0f83c7")).json())

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

for scan in cxone_client.get_project_last_scans(limit=20):
print(f"Scan Id: {scan['id']}")
pass
# print((await cxone_client.get_repostore_file("153a99d4-686e-4fe9-970d-c68b5d0f83c7", "input/client/src/index.js")).text)

# async for scan in paged_api(cxone_client.get_scans, "scans", statuses=['Completed']):
# print(f"Scan Id: {scan['id']} ProjectId: {scan['projectId']} Branch: {scan['branch']}")

# print((await cxone_client.get_scan("153a99d4-686e-4fe9-970d-c68b5d0f83c7")).json())

# await download_files_to_directory('153a99d4-686e-4fe9-970d-c68b5d0f83c7', 'test')

last_scan_dict = (await cxone_client.get_project_last_scans(limit=20)).json()

for scan in last_scan_dict:
print(f"Scan Id: {last_scan_dict[scan]}")
# Paging has to be redone manually without page_api



asyncio.run(main())
9 changes: 7 additions & 2 deletions cxone_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,8 @@ async def get_project(self, projectid):

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

async def get_project_configuration(self, projectid):
url = urljoin(self.api_endpoint, f"configuration/project?project-id={projectid}")
Expand All @@ -383,7 +384,11 @@ async def get_scans(self, **kwargs):
url = urljoin(self.api_endpoint, "scans")
url = CxOneClient.__join_query_dict(url, kwargs)
return await self.__exec_request(requests.get, url)


async def get_scan(self, scanid):
url = urljoin(self.api_endpoint, f"scans/{scanid}")
return await self.__exec_request(requests.get, url)

@dashargs("scan-ids")
async def get_sast_scans_metadata(self, **kwargs):
url = urljoin(self.api_endpoint, "sast-metadata")
Expand Down
4 changes: 4 additions & 0 deletions cxone_api/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,7 @@ async def primary_branch(self):
async def repo_url(self):
url = await self.__get_logical_repo_url()
return url if len(url) > 0 else None


async def download_files_to_directory(cxone_client, scanid, dest_directory):
pass

0 comments on commit ae8b4d7

Please sign in to comment.