-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
45 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from cxone_api import AuthUS, ApiUS, paged_api, CxOneClient | ||
from cxone_api.repo import ProjectRepoConfig | ||
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 | ||
|
||
asyncio.run(main()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
class ProjectRepoConfig: | ||
|
||
def __init__(self, cxone_client, project_data): | ||
self.__client = cxone_client | ||
self.__project_data = project_data | ||
self.__fetched_undocumented_config = False | ||
self.__lock = asyncio.Lock() | ||
|
||
async def __get_logical_repo_url(self): | ||
# The documented project API seems to have a bug and does not return the repoUrl. The undocumented | ||
# API used by the UI has it. The undocumented API will no longer be called when the project | ||
# API is fixed. | ||
async with self.__lock: | ||
if len(self.__project_data['repoUrl']) == 0 and not self.__fetched_undocumented_config: | ||
self.__fetched_undocumented_config = True | ||
config = (await self.__client.get_project_configuration(self.__project_data['id'])).json() | ||
|
||
for entry in config: | ||
if entry['key'] == "scan.handler.git.repository": | ||
self.__project_data['repoUrl'] = entry['value'] | ||
|
||
return self.__project_data['repoUrl'] | ||
|
||
@property | ||
async def primary_branch(self): | ||
return self.__project_data['mainBranch'] if len(self.__project_data['mainBranch']) > 0 else None | ||
|
||
@property | ||
async def repo_url(self): | ||
url = await self.__get_logical_repo_url() | ||
return url if len(url) > 0 else None |