Skip to content

Commit

Permalink
feat: implemented crawler for listing cloud source repositories (goog…
Browse files Browse the repository at this point in the history
…le#19)

Signed-off-by: Sudipto Baral <sudiptobaral.me@gmail.com>
  • Loading branch information
sudiptob2 committed Feb 23, 2023
1 parent 3292c4c commit 4a6cdb5
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/gcp_scanner/crawl.py
Original file line number Diff line number Diff line change
Expand Up @@ -1005,3 +1005,38 @@ def list_services(project_id: str, credentials: Credentials) -> List[Any]:
logging.info(sys.exc_info())

return list_of_services


def list_sourcerepo(project_id: str, credentials: Credentials) -> List[Any]:
"""Retrieve a list of cloud source repositories enabled in the project.
Args:
project_id: An id of a project to query info about.
credentials: An google.oauth2.credentials.Credentials object.
Returns:
A list of cloud source repositories in the project.
"""

logging.info("Retrieving cloud source repositories %s", project_id)
list_of_repos = list()
service = discovery.build("sourcerepo", "v1", credentials=credentials)

request = service.projects().repos().list(
name="projects/" + project_id,
pageSize=200
)
try:
while request is not None:
response = request.execute()
list_of_repos.append(response.get("repos", None))

request = service.services().list_next(
previous_request=request,
previous_response=response
)
except Exception:
logging.info("Failed to retrieve cloud source repos for project %s", project_id)
logging.info(sys.exc_info())

return list_of_repos

0 comments on commit 4a6cdb5

Please sign in to comment.