-
Notifications
You must be signed in to change notification settings - Fork 172
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 #482 from awslabs/get-supported-resources-programa…
…tically Get supported resources via script
- Loading branch information
Showing
6 changed files
with
187 additions
and
20 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,78 @@ | ||
import argparse | ||
from selenium import webdriver | ||
from selenium.webdriver.common.keys import Keys | ||
from selenium.webdriver.common.by import By | ||
from selenium.webdriver.chrome.options import Options | ||
from selenium.common.exceptions import NoSuchElementException | ||
import json | ||
import logging | ||
from concurrent import futures | ||
from collections import Counter | ||
import os | ||
import time | ||
import re | ||
import yaml | ||
|
||
""" | ||
Summary | ||
This is a simple web scraper to list the resource types supported by AWS Config. | ||
It will write its output to supported_resource_types.yaml -- this should be moved to the rdk subfolder after validating. | ||
""" | ||
|
||
all_resources = ["ALL"] # Special string to support all resource types"] | ||
|
||
undocumented_but_supported = [ | ||
"AWS::EventSchemas::Registry", | ||
"AWS::IoTTwinMaker::ComponentType", | ||
] | ||
|
||
all_resources += undocumented_but_supported | ||
|
||
url = "https://docs.aws.amazon.com/config/latest/developerguide/resource-config-reference.html" | ||
# Start the browser | ||
chrome_options = Options() | ||
chrome_options.add_argument("--headless=new") | ||
chrome_options.add_argument("--no-sandbox") | ||
chrome_options.add_experimental_option("excludeSwitches", ["enable-logging"]) | ||
driver = webdriver.Chrome( | ||
options=chrome_options, | ||
) | ||
|
||
# Open the login page | ||
driver.get(url) | ||
driver.implicitly_wait(2) | ||
|
||
# Iterate through every h2 header | ||
services = driver.find_elements(By.CLASS_NAME, "table-contents") | ||
|
||
# Walk through the table items | ||
for service in services: | ||
if service.text == "": | ||
continue | ||
navigator = service | ||
try: | ||
# Find everything with a class of code and get its text | ||
resources = navigator.find_elements(By.CLASS_NAME, "code") | ||
except NoSuchElementException: | ||
logging.info(f"No resources found for {service.text}") | ||
continue | ||
if len(resources) == 0: | ||
logging.info(f"No resources found for {service.text}") | ||
continue | ||
# Assert that it matches "AWS::*" | ||
for resource in resources: | ||
if re.match(r"AWS::.*", resource.text): | ||
# Remove any asterisks | ||
resource_type = resource.text.replace("*", "") | ||
# Add it to the output list | ||
all_resources.append(resource_type) | ||
logging.info(resource_type) | ||
|
||
driver.quit() | ||
|
||
# Return the output list, sorted | ||
yaml_output = {"supported_resources": sorted(list(set((all_resources))))} | ||
yaml_output_string = yaml.dump(yaml_output) | ||
with open("supported_resource_types.yaml", "w") as f: | ||
f.write(yaml_output_string) |
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 |
---|---|---|
|
@@ -7,7 +7,7 @@ | |
# or in the "license" file accompanying this file. This file 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. | ||
[tool.poetry] | ||
name = "rdk" | ||
version = "0.17.6" | ||
version = "0.17.7" | ||
description = "Rule Development Kit CLI for AWS Config" | ||
authors = [ | ||
"AWS RDK Maintainers <[email protected]>", | ||
|
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
Oops, something went wrong.