-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #261 from sudiptob2/feat/260/cloud-domains-crawler
Feat/260/cloud domains crawler
- Loading branch information
Showing
11 changed files
with
137 additions
and
8 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 |
---|---|---|
|
@@ -92,5 +92,8 @@ | |
}, | ||
"datastore_kinds": { | ||
"fetch": true | ||
}, | ||
"registered_domains": { | ||
"fetch": true | ||
} | ||
} |
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,38 @@ | ||
# Copyright 2023 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from googleapiclient import discovery | ||
from httplib2 import Credentials | ||
|
||
from .interface_client import IClient | ||
|
||
|
||
class DomainsClient(IClient): | ||
"""Cloud DomainsClient class.""" | ||
|
||
def get_service(self, credentials: Credentials) -> discovery.Resource: | ||
"""Get discovery service for cloud domains resource. | ||
Args: | ||
credentials: An google.oauth2.credentials.Credentials object. | ||
Returns: | ||
An object of discovery.Resource | ||
""" | ||
return discovery.build( | ||
"domains", | ||
"v1", | ||
credentials=credentials, | ||
cache_discovery=False, | ||
) |
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,55 @@ | ||
# Copyright 2023 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
import logging | ||
import sys | ||
from typing import List, Dict, Any, Union | ||
|
||
from googleapiclient import discovery | ||
|
||
from gcp_scanner.crawler.interface_crawler import ICrawler | ||
|
||
|
||
class DomainsCrawler(ICrawler): | ||
"""Handle crawling of cloud domains data.""" | ||
|
||
def crawl(self, project_name: str, service: discovery.Resource, | ||
config: Dict[str, Union[bool, str]] = None) -> List[Dict[str, Any]]: | ||
"""Retrieve a list of cloud domains available in the project. | ||
Args: | ||
project_name: The name of the project to query information about. | ||
service: A resource object for interacting with the GCP API. | ||
config: Configuration options for the crawler (Optional). | ||
Returns: | ||
A list of resource objects representing the crawled data. | ||
""" | ||
logging.info("Retrieving list of registered cloud domains names") | ||
registered_domains_list = list() | ||
parent = f"projects/{project_name}/locations/-" | ||
try: | ||
request = service.projects().locations().registrations().list(parent=parent) | ||
while request is not None: | ||
response = request.execute() | ||
if response.get("registrations", None) is not None: | ||
registered_domains_list.extend([registration['name'] for registration in response.get("registrations")]) | ||
request = service.projects().locations().registrations().list_next( | ||
previous_request=request, | ||
previous_response=response, | ||
) | ||
except Exception: | ||
logging.info("Failed to enumerate cloud domains in the %s", project_name) | ||
logging.info(sys.exc_info()) | ||
|
||
return registered_domains_list |
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
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
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,3 @@ | ||
[ | ||
CHECK "projects/test-gcp-scanner-2/locations/global/registrations/gcpscanner.com" | ||
] |
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