runbooks 0.2.3__py3-none-any.whl → 0.6.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- conftest.py +26 -0
- jupyter-agent/.env.template +2 -0
- jupyter-agent/.gitattributes +35 -0
- jupyter-agent/README.md +16 -0
- jupyter-agent/app.py +256 -0
- jupyter-agent/cloudops-agent.png +0 -0
- jupyter-agent/ds-system-prompt.txt +154 -0
- jupyter-agent/jupyter-agent.png +0 -0
- jupyter-agent/llama3_template.jinja +123 -0
- jupyter-agent/requirements.txt +9 -0
- jupyter-agent/utils.py +409 -0
- runbooks/__init__.py +71 -3
- runbooks/__main__.py +13 -0
- runbooks/aws/ec2_describe_instances.py +1 -1
- runbooks/aws/ec2_run_instances.py +8 -2
- runbooks/aws/ec2_start_stop_instances.py +17 -4
- runbooks/aws/ec2_unused_volumes.py +5 -1
- runbooks/aws/s3_create_bucket.py +4 -2
- runbooks/aws/s3_list_objects.py +6 -1
- runbooks/aws/tagging_lambda_handler.py +13 -2
- runbooks/aws/tags.json +12 -0
- runbooks/base.py +353 -0
- runbooks/cfat/README.md +49 -0
- runbooks/cfat/__init__.py +74 -0
- runbooks/cfat/app.ts +644 -0
- runbooks/cfat/assessment/__init__.py +40 -0
- runbooks/cfat/assessment/asana-import.csv +39 -0
- runbooks/cfat/assessment/cfat-checks.csv +31 -0
- runbooks/cfat/assessment/cfat.txt +520 -0
- runbooks/cfat/assessment/collectors.py +200 -0
- runbooks/cfat/assessment/jira-import.csv +39 -0
- runbooks/cfat/assessment/runner.py +387 -0
- runbooks/cfat/assessment/validators.py +290 -0
- runbooks/cfat/cli.py +103 -0
- runbooks/cfat/docs/asana-import.csv +24 -0
- runbooks/cfat/docs/cfat-checks.csv +31 -0
- runbooks/cfat/docs/cfat.txt +335 -0
- runbooks/cfat/docs/checks-output.png +0 -0
- runbooks/cfat/docs/cloudshell-console-run.png +0 -0
- runbooks/cfat/docs/cloudshell-download.png +0 -0
- runbooks/cfat/docs/cloudshell-output.png +0 -0
- runbooks/cfat/docs/downloadfile.png +0 -0
- runbooks/cfat/docs/jira-import.csv +24 -0
- runbooks/cfat/docs/open-cloudshell.png +0 -0
- runbooks/cfat/docs/report-header.png +0 -0
- runbooks/cfat/models.py +1026 -0
- runbooks/cfat/package-lock.json +5116 -0
- runbooks/cfat/package.json +38 -0
- runbooks/cfat/report.py +496 -0
- runbooks/cfat/reporting/__init__.py +46 -0
- runbooks/cfat/reporting/exporters.py +337 -0
- runbooks/cfat/reporting/formatters.py +496 -0
- runbooks/cfat/reporting/templates.py +135 -0
- runbooks/cfat/run-assessment.sh +23 -0
- runbooks/cfat/runner.py +69 -0
- runbooks/cfat/src/actions/check-cloudtrail-existence.ts +43 -0
- runbooks/cfat/src/actions/check-config-existence.ts +37 -0
- runbooks/cfat/src/actions/check-control-tower.ts +37 -0
- runbooks/cfat/src/actions/check-ec2-existence.ts +46 -0
- runbooks/cfat/src/actions/check-iam-users.ts +50 -0
- runbooks/cfat/src/actions/check-legacy-cur.ts +30 -0
- runbooks/cfat/src/actions/check-org-cloudformation.ts +30 -0
- runbooks/cfat/src/actions/check-vpc-existence.ts +43 -0
- runbooks/cfat/src/actions/create-asanaimport.ts +14 -0
- runbooks/cfat/src/actions/create-backlog.ts +372 -0
- runbooks/cfat/src/actions/create-jiraimport.ts +15 -0
- runbooks/cfat/src/actions/create-report.ts +616 -0
- runbooks/cfat/src/actions/define-account-type.ts +51 -0
- runbooks/cfat/src/actions/get-enabled-org-policy-types.ts +40 -0
- runbooks/cfat/src/actions/get-enabled-org-services.ts +26 -0
- runbooks/cfat/src/actions/get-idc-info.ts +34 -0
- runbooks/cfat/src/actions/get-org-da-accounts.ts +34 -0
- runbooks/cfat/src/actions/get-org-details.ts +35 -0
- runbooks/cfat/src/actions/get-org-member-accounts.ts +44 -0
- runbooks/cfat/src/actions/get-org-ous.ts +35 -0
- runbooks/cfat/src/actions/get-regions.ts +22 -0
- runbooks/cfat/src/actions/zip-assessment.ts +27 -0
- runbooks/cfat/src/types/index.d.ts +147 -0
- runbooks/cfat/tests/__init__.py +141 -0
- runbooks/cfat/tests/test_cli.py +340 -0
- runbooks/cfat/tests/test_integration.py +290 -0
- runbooks/cfat/tests/test_models.py +505 -0
- runbooks/cfat/tests/test_reporting.py +354 -0
- runbooks/cfat/tsconfig.json +16 -0
- runbooks/cfat/webpack.config.cjs +27 -0
- runbooks/config.py +260 -0
- runbooks/finops/__init__.py +88 -0
- runbooks/finops/aws_client.py +245 -0
- runbooks/finops/cli.py +151 -0
- runbooks/finops/cost_processor.py +410 -0
- runbooks/finops/dashboard_runner.py +448 -0
- runbooks/finops/helpers.py +355 -0
- runbooks/finops/main.py +14 -0
- runbooks/finops/profile_processor.py +174 -0
- runbooks/finops/types.py +66 -0
- runbooks/finops/visualisations.py +80 -0
- runbooks/inventory/.gitignore +354 -0
- runbooks/inventory/ArgumentsClass.py +261 -0
- runbooks/inventory/Inventory_Modules.py +6130 -0
- runbooks/inventory/LandingZone/delete_lz.py +1075 -0
- runbooks/inventory/README.md +1320 -0
- runbooks/inventory/__init__.py +62 -0
- runbooks/inventory/account_class.py +532 -0
- runbooks/inventory/all_my_instances_wrapper.py +123 -0
- runbooks/inventory/aws_decorators.py +201 -0
- runbooks/inventory/cfn_move_stack_instances.py +1526 -0
- runbooks/inventory/check_cloudtrail_compliance.py +614 -0
- runbooks/inventory/check_controltower_readiness.py +1107 -0
- runbooks/inventory/check_landingzone_readiness.py +711 -0
- runbooks/inventory/cloudtrail.md +727 -0
- runbooks/inventory/collectors/__init__.py +20 -0
- runbooks/inventory/collectors/aws_compute.py +518 -0
- runbooks/inventory/collectors/aws_networking.py +275 -0
- runbooks/inventory/collectors/base.py +222 -0
- runbooks/inventory/core/__init__.py +19 -0
- runbooks/inventory/core/collector.py +303 -0
- runbooks/inventory/core/formatter.py +296 -0
- runbooks/inventory/delete_s3_buckets_objects.py +169 -0
- runbooks/inventory/discovery.md +81 -0
- runbooks/inventory/draw_org_structure.py +748 -0
- runbooks/inventory/ec2_vpc_utils.py +341 -0
- runbooks/inventory/find_cfn_drift_detection.py +272 -0
- runbooks/inventory/find_cfn_orphaned_stacks.py +719 -0
- runbooks/inventory/find_cfn_stackset_drift.py +733 -0
- runbooks/inventory/find_ec2_security_groups.py +669 -0
- runbooks/inventory/find_landingzone_versions.py +201 -0
- runbooks/inventory/find_vpc_flow_logs.py +1221 -0
- runbooks/inventory/inventory.sh +659 -0
- runbooks/inventory/list_cfn_stacks.py +558 -0
- runbooks/inventory/list_cfn_stackset_operation_results.py +252 -0
- runbooks/inventory/list_cfn_stackset_operations.py +734 -0
- runbooks/inventory/list_cfn_stacksets.py +453 -0
- runbooks/inventory/list_config_recorders_delivery_channels.py +681 -0
- runbooks/inventory/list_ds_directories.py +354 -0
- runbooks/inventory/list_ec2_availability_zones.py +286 -0
- runbooks/inventory/list_ec2_ebs_volumes.py +244 -0
- runbooks/inventory/list_ec2_instances.py +425 -0
- runbooks/inventory/list_ecs_clusters_and_tasks.py +562 -0
- runbooks/inventory/list_elbs_load_balancers.py +411 -0
- runbooks/inventory/list_enis_network_interfaces.py +526 -0
- runbooks/inventory/list_guardduty_detectors.py +568 -0
- runbooks/inventory/list_iam_policies.py +404 -0
- runbooks/inventory/list_iam_roles.py +518 -0
- runbooks/inventory/list_iam_saml_providers.py +359 -0
- runbooks/inventory/list_lambda_functions.py +882 -0
- runbooks/inventory/list_org_accounts.py +446 -0
- runbooks/inventory/list_org_accounts_users.py +354 -0
- runbooks/inventory/list_rds_db_instances.py +406 -0
- runbooks/inventory/list_route53_hosted_zones.py +318 -0
- runbooks/inventory/list_servicecatalog_provisioned_products.py +575 -0
- runbooks/inventory/list_sns_topics.py +360 -0
- runbooks/inventory/list_ssm_parameters.py +402 -0
- runbooks/inventory/list_vpc_subnets.py +433 -0
- runbooks/inventory/list_vpcs.py +422 -0
- runbooks/inventory/lockdown_cfn_stackset_role.py +224 -0
- runbooks/inventory/models/__init__.py +24 -0
- runbooks/inventory/models/account.py +192 -0
- runbooks/inventory/models/inventory.py +309 -0
- runbooks/inventory/models/resource.py +247 -0
- runbooks/inventory/recover_cfn_stack_ids.py +205 -0
- runbooks/inventory/requirements.txt +12 -0
- runbooks/inventory/run_on_multi_accounts.py +211 -0
- runbooks/inventory/tests/common_test_data.py +3661 -0
- runbooks/inventory/tests/common_test_functions.py +204 -0
- runbooks/inventory/tests/script_test_data.py +0 -0
- runbooks/inventory/tests/setup.py +24 -0
- runbooks/inventory/tests/src.py +18 -0
- runbooks/inventory/tests/test_cfn_describe_stacks.py +208 -0
- runbooks/inventory/tests/test_ec2_describe_instances.py +162 -0
- runbooks/inventory/tests/test_inventory_modules.py +55 -0
- runbooks/inventory/tests/test_lambda_list_functions.py +86 -0
- runbooks/inventory/tests/test_moto_integration_example.py +273 -0
- runbooks/inventory/tests/test_org_list_accounts.py +49 -0
- runbooks/inventory/update_aws_actions.py +173 -0
- runbooks/inventory/update_cfn_stacksets.py +1215 -0
- runbooks/inventory/update_cloudwatch_logs_retention_policy.py +294 -0
- runbooks/inventory/update_iam_roles_cross_accounts.py +478 -0
- runbooks/inventory/update_s3_public_access_block.py +539 -0
- runbooks/inventory/utils/__init__.py +23 -0
- runbooks/inventory/utils/aws_helpers.py +510 -0
- runbooks/inventory/utils/threading_utils.py +493 -0
- runbooks/inventory/utils/validation.py +682 -0
- runbooks/inventory/verify_ec2_security_groups.py +1430 -0
- runbooks/main.py +785 -0
- runbooks/organizations/__init__.py +12 -0
- runbooks/organizations/manager.py +374 -0
- runbooks/security_baseline/README.md +324 -0
- runbooks/security_baseline/checklist/alternate_contacts.py +8 -1
- runbooks/security_baseline/checklist/bucket_public_access.py +4 -1
- runbooks/security_baseline/checklist/cloudwatch_alarm_configuration.py +9 -2
- runbooks/security_baseline/checklist/guardduty_enabled.py +9 -2
- runbooks/security_baseline/checklist/multi_region_instance_usage.py +5 -1
- runbooks/security_baseline/checklist/root_access_key.py +6 -1
- runbooks/security_baseline/config-origin.json +1 -1
- runbooks/security_baseline/config.json +1 -1
- runbooks/security_baseline/permission.json +1 -1
- runbooks/security_baseline/report_generator.py +10 -2
- runbooks/security_baseline/report_template_en.html +8 -8
- runbooks/security_baseline/report_template_jp.html +8 -8
- runbooks/security_baseline/report_template_kr.html +13 -13
- runbooks/security_baseline/report_template_vn.html +8 -8
- runbooks/security_baseline/requirements.txt +7 -0
- runbooks/security_baseline/run_script.py +8 -2
- runbooks/security_baseline/security_baseline_tester.py +10 -2
- runbooks/security_baseline/utils/common.py +5 -1
- runbooks/utils/__init__.py +204 -0
- runbooks-0.6.1.dist-info/METADATA +373 -0
- runbooks-0.6.1.dist-info/RECORD +237 -0
- {runbooks-0.2.3.dist-info → runbooks-0.6.1.dist-info}/WHEEL +1 -1
- runbooks-0.6.1.dist-info/entry_points.txt +7 -0
- runbooks-0.6.1.dist-info/licenses/LICENSE +201 -0
- runbooks-0.6.1.dist-info/top_level.txt +3 -0
- runbooks/python101/calculator.py +0 -34
- runbooks/python101/config.py +0 -1
- runbooks/python101/exceptions.py +0 -16
- runbooks/python101/file_manager.py +0 -218
- runbooks/python101/toolkit.py +0 -153
- runbooks-0.2.3.dist-info/METADATA +0 -435
- runbooks-0.2.3.dist-info/RECORD +0 -61
- runbooks-0.2.3.dist-info/entry_points.txt +0 -3
- runbooks-0.2.3.dist-info/top_level.txt +0 -1
@@ -0,0 +1,318 @@
|
|
1
|
+
#!/usr/bin/env python3
|
2
|
+
|
3
|
+
"""
|
4
|
+
AWS Route53 Hosted Zones Inventory Script
|
5
|
+
|
6
|
+
This script provides comprehensive discovery and inventory capabilities for AWS Route53
|
7
|
+
private hosted zones across multiple accounts and regions. It's designed for enterprise
|
8
|
+
environments where DNS infrastructure visibility and management is critical for
|
9
|
+
networking operations and compliance.
|
10
|
+
|
11
|
+
Key Features:
|
12
|
+
- Multi-account Route53 hosted zone discovery using assume role capabilities
|
13
|
+
- Multi-region scanning with configurable region targeting
|
14
|
+
- Parallel processing with configurable threading for performance optimization
|
15
|
+
- Private hosted zone detection and record count analysis
|
16
|
+
- Detailed zone metadata extraction including zone ID and record counts
|
17
|
+
- Comprehensive error handling for authorization failures and throttling
|
18
|
+
- Enterprise reporting with CSV export and structured output formatting
|
19
|
+
- Profile-based authentication with support for federated access
|
20
|
+
|
21
|
+
Enterprise Use Cases:
|
22
|
+
- DNS Infrastructure auditing and compliance reporting
|
23
|
+
- Multi-account DNS zone consolidation planning
|
24
|
+
- Route53 cost optimization through zone utilization analysis
|
25
|
+
- Networking architecture documentation and change management
|
26
|
+
- Security auditing of DNS configurations across organization
|
27
|
+
- Disaster recovery planning for DNS infrastructure
|
28
|
+
|
29
|
+
Security Considerations:
|
30
|
+
- Uses IAM assume role capabilities for cross-account access
|
31
|
+
- Implements proper error handling for authorization failures
|
32
|
+
- Supports read-only operations with no modification capabilities
|
33
|
+
- Respects AWS API rate limits with controlled threading
|
34
|
+
- Provides audit trail through comprehensive logging
|
35
|
+
|
36
|
+
Output Format:
|
37
|
+
- Tabular display with sortable columns for analysis
|
38
|
+
- CSV export capability for integration with other tools
|
39
|
+
- Color-coded output for enhanced readability
|
40
|
+
- Performance timing metrics for optimization
|
41
|
+
|
42
|
+
Dependencies:
|
43
|
+
- boto3/botocore for AWS API interactions
|
44
|
+
- Threading support for concurrent processing
|
45
|
+
- Inventory_Modules for common utility functions
|
46
|
+
- ArgumentsClass for standardized CLI argument parsing
|
47
|
+
|
48
|
+
Author: AWS CloudOps Team
|
49
|
+
Version: 2023.11.08
|
50
|
+
"""
|
51
|
+
|
52
|
+
import logging
|
53
|
+
import sys
|
54
|
+
from queue import Queue
|
55
|
+
from threading import Thread
|
56
|
+
from time import time
|
57
|
+
|
58
|
+
from ArgumentsClass import CommonArguments
|
59
|
+
from botocore.exceptions import ClientError
|
60
|
+
from colorama import Fore, init
|
61
|
+
from Inventory_Modules import display_results, find_private_hosted_zones2, get_all_credentials
|
62
|
+
|
63
|
+
init()
|
64
|
+
__version__ = "2023.11.08"
|
65
|
+
ERASE_LINE = "\x1b[2K"
|
66
|
+
|
67
|
+
########################
|
68
|
+
|
69
|
+
|
70
|
+
def parse_args(args):
|
71
|
+
"""
|
72
|
+
Parse command line arguments for Route53 hosted zones discovery.
|
73
|
+
|
74
|
+
Configures comprehensive argument parsing for multi-account, multi-region Route53
|
75
|
+
hosted zone inventory operations. Supports enterprise deployment patterns with
|
76
|
+
profile management, region targeting, and output customization.
|
77
|
+
|
78
|
+
Args:
|
79
|
+
args (list): Command line arguments from sys.argv[1:]
|
80
|
+
|
81
|
+
Returns:
|
82
|
+
argparse.Namespace: Parsed arguments containing:
|
83
|
+
- Profiles: List of AWS profiles to process
|
84
|
+
- Regions: Target regions for hosted zone discovery
|
85
|
+
- SkipProfiles/SkipAccounts: Exclusion filters
|
86
|
+
- RootOnly: Limit to organization root accounts
|
87
|
+
- Filename: Output file for CSV export
|
88
|
+
- Time: Enable performance timing metrics
|
89
|
+
- loglevel: Logging verbosity configuration
|
90
|
+
|
91
|
+
Configuration Options:
|
92
|
+
- Multi-region scanning with region filters
|
93
|
+
- Multi-profile support for federated access
|
94
|
+
- Extended arguments for advanced filtering
|
95
|
+
- Root-only mode for organization-level inventory
|
96
|
+
- File output for integration and reporting
|
97
|
+
- Timing metrics for performance optimization
|
98
|
+
- Verbose logging for debugging and audit
|
99
|
+
"""
|
100
|
+
parser = CommonArguments()
|
101
|
+
parser.multiregion()
|
102
|
+
parser.multiprofile()
|
103
|
+
parser.extendedargs()
|
104
|
+
parser.rootOnly()
|
105
|
+
parser.save_to_file()
|
106
|
+
parser.verbosity()
|
107
|
+
parser.timing()
|
108
|
+
parser.version(__version__)
|
109
|
+
return parser.my_parser.parse_args(args)
|
110
|
+
|
111
|
+
|
112
|
+
def find_all_hosted_zones(fAllCredentials):
|
113
|
+
"""
|
114
|
+
Discover Route53 private hosted zones across multiple AWS accounts and regions.
|
115
|
+
|
116
|
+
Implements high-performance parallel processing to efficiently scan large-scale
|
117
|
+
AWS environments for Route53 private hosted zones. Uses multi-threading with
|
118
|
+
configurable worker pools to optimize API call patterns while respecting
|
119
|
+
AWS service limits and throttling constraints.
|
120
|
+
|
121
|
+
Args:
|
122
|
+
fAllCredentials (list): List of credential dictionaries containing:
|
123
|
+
- AccountId: AWS account identifier
|
124
|
+
- ParentProfile: Source profile for assume role
|
125
|
+
- MgmtAccount: Management account identifier
|
126
|
+
- Region: Target AWS region for scanning
|
127
|
+
- Credentials: Temporary AWS credentials
|
128
|
+
|
129
|
+
Returns:
|
130
|
+
list: Collection of hosted zone records with structure:
|
131
|
+
- ParentProfile: Source AWS profile
|
132
|
+
- MgmtAccount: Organization management account
|
133
|
+
- AccountId: Account containing the hosted zone
|
134
|
+
- Region: AWS region of the hosted zone
|
135
|
+
- PHZName: Private hosted zone name/domain
|
136
|
+
- Records: Number of resource records in zone
|
137
|
+
- PHZId: Route53 hosted zone identifier
|
138
|
+
|
139
|
+
Threading Architecture:
|
140
|
+
- Worker pool limited to min(credentials, 25) threads
|
141
|
+
- Queue-based work distribution for load balancing
|
142
|
+
- Daemon threads for clean shutdown handling
|
143
|
+
- Progress indicators with real-time feedback
|
144
|
+
|
145
|
+
Error Handling:
|
146
|
+
- KeyError: Account access credential issues
|
147
|
+
- AttributeError: Profile configuration problems
|
148
|
+
- ClientError: AWS API authorization and throttling
|
149
|
+
- Regional opt-in validation for new AWS regions
|
150
|
+
|
151
|
+
Performance Optimizations:
|
152
|
+
- Concurrent processing across accounts/regions
|
153
|
+
- Worker thread pool tuning for API efficiency
|
154
|
+
- Queue-based work distribution
|
155
|
+
- Progress tracking for operational visibility
|
156
|
+
"""
|
157
|
+
|
158
|
+
class FindZones(Thread):
|
159
|
+
"""
|
160
|
+
Worker thread class for concurrent Route53 hosted zone discovery.
|
161
|
+
|
162
|
+
Processes work items from shared queue to discover private hosted zones
|
163
|
+
in individual AWS accounts and regions. Implements proper error handling
|
164
|
+
and progress reporting for enterprise-scale operations.
|
165
|
+
"""
|
166
|
+
|
167
|
+
def __init__(self, queue):
|
168
|
+
"""Initialize worker thread with shared work queue."""
|
169
|
+
Thread.__init__(self)
|
170
|
+
self.queue = queue
|
171
|
+
|
172
|
+
def run(self):
|
173
|
+
"""
|
174
|
+
Main worker thread execution loop.
|
175
|
+
|
176
|
+
Continuously processes credential sets from the work queue, discovers
|
177
|
+
Route53 private hosted zones, and aggregates results. Handles various
|
178
|
+
AWS API error conditions with appropriate retry and logging strategies.
|
179
|
+
"""
|
180
|
+
while True:
|
181
|
+
c_account_credentials, c_PlaceCount = self.queue.get()
|
182
|
+
logging.info(f"De-queued info for account number {c_account_credentials['AccountId']}")
|
183
|
+
try:
|
184
|
+
# Call Route53 API to discover private hosted zones in this account/region
|
185
|
+
HostedZones = find_private_hosted_zones2(c_account_credentials, c_account_credentials["Region"])
|
186
|
+
logging.info(
|
187
|
+
f"Account: {c_account_credentials['AccountId']} Region: {c_account_credentials['Region']} | Found {len(HostedZones['HostedZones'])} zones"
|
188
|
+
)
|
189
|
+
|
190
|
+
# Process each discovered hosted zone and extract metadata
|
191
|
+
if len(HostedZones["HostedZones"]) > 0:
|
192
|
+
for zone in HostedZones["HostedZones"]:
|
193
|
+
ThreadedHostedZones.append(
|
194
|
+
{
|
195
|
+
"ParentProfile": c_account_credentials["ParentProfile"],
|
196
|
+
"MgmtAccount": c_account_credentials["MgmtAccount"],
|
197
|
+
"AccountId": c_account_credentials["AccountId"],
|
198
|
+
"Region": c_account_credentials["Region"],
|
199
|
+
"PHZName": zone["Name"],
|
200
|
+
"Records": zone["ResourceRecordSetCount"],
|
201
|
+
"PHZId": zone["Id"],
|
202
|
+
}
|
203
|
+
)
|
204
|
+
except KeyError as my_Error:
|
205
|
+
# Handle credential or account access failures
|
206
|
+
logging.error(f"Account Access failed - trying to access {c_account_credentials['AccountId']}")
|
207
|
+
logging.info(f"Actual Error: {my_Error}")
|
208
|
+
pass
|
209
|
+
except AttributeError as my_Error:
|
210
|
+
# Handle profile configuration issues
|
211
|
+
logging.error("Error: Likely that one of the supplied profiles was wrong")
|
212
|
+
logging.warning(my_Error)
|
213
|
+
continue
|
214
|
+
except ClientError as my_Error:
|
215
|
+
# Handle AWS API errors including authorization and throttling
|
216
|
+
if "AuthFailure" in str(my_Error):
|
217
|
+
logging.error(
|
218
|
+
f"Authorization Failure accessing account {c_account_credentials['AccountId']} in {c_account_credentials['Region']} region"
|
219
|
+
)
|
220
|
+
logging.warning(
|
221
|
+
f"It's possible that the region {c_account_credentials['Region']} hasn't been opted-into"
|
222
|
+
)
|
223
|
+
continue
|
224
|
+
else:
|
225
|
+
logging.error("Error: Likely throttling errors from too much activity")
|
226
|
+
logging.warning(my_Error)
|
227
|
+
continue
|
228
|
+
finally:
|
229
|
+
# Provide progress feedback and mark work item complete
|
230
|
+
print(".", end="")
|
231
|
+
self.queue.task_done()
|
232
|
+
|
233
|
+
# Initialize threading infrastructure for parallel processing
|
234
|
+
checkqueue = Queue()
|
235
|
+
ThreadedHostedZones = []
|
236
|
+
PlaceCount = 0
|
237
|
+
WorkerThreads = min(len(fAllCredentials), 25) # Limit worker threads for API efficiency
|
238
|
+
|
239
|
+
# Start worker thread pool for concurrent processing
|
240
|
+
for x in range(WorkerThreads):
|
241
|
+
worker = FindZones(checkqueue)
|
242
|
+
worker.daemon = True
|
243
|
+
worker.start()
|
244
|
+
|
245
|
+
# Queue all credential sets for processing by worker threads
|
246
|
+
for credential in fAllCredentials:
|
247
|
+
logging.info(f"Beginning to queue data - starting with {credential['AccountId']}")
|
248
|
+
try:
|
249
|
+
checkqueue.put((credential, PlaceCount))
|
250
|
+
PlaceCount += 1
|
251
|
+
except ClientError as my_Error:
|
252
|
+
# Handle authorization errors during queue operations
|
253
|
+
if "AuthFailure" in str(my_Error):
|
254
|
+
logging.error(
|
255
|
+
f"Authorization Failure accessing account {credential['AccountId']} in {credential['Region']} region"
|
256
|
+
)
|
257
|
+
logging.warning(f"It's possible that the region {credential['Region']} hasn't been opted-into")
|
258
|
+
pass
|
259
|
+
|
260
|
+
# Wait for all work items to be processed
|
261
|
+
checkqueue.join()
|
262
|
+
return ThreadedHostedZones
|
263
|
+
|
264
|
+
|
265
|
+
if __name__ == "__main__":
|
266
|
+
args = parse_args(sys.argv[1:])
|
267
|
+
pProfiles = args.Profiles
|
268
|
+
pRegionList = args.Regions
|
269
|
+
pSkipProfiles = args.SkipProfiles
|
270
|
+
pSkipAccounts = args.SkipAccounts
|
271
|
+
pRootOnly = args.RootOnly
|
272
|
+
pAccounts = args.Accounts
|
273
|
+
pFilename = args.Filename
|
274
|
+
pTiming = args.Time
|
275
|
+
verbose = args.loglevel
|
276
|
+
# Setup logging levels
|
277
|
+
logging.basicConfig(level=verbose, format="[%(filename)s:%(lineno)s - %(funcName)20s() ] %(message)s")
|
278
|
+
logging.getLogger("boto3").setLevel(logging.CRITICAL)
|
279
|
+
logging.getLogger("botocore").setLevel(logging.CRITICAL)
|
280
|
+
logging.getLogger("s3transfer").setLevel(logging.CRITICAL)
|
281
|
+
logging.getLogger("urllib3").setLevel(logging.CRITICAL)
|
282
|
+
|
283
|
+
begin_time = time()
|
284
|
+
# Get Credentials
|
285
|
+
AllCredentials = get_all_credentials(
|
286
|
+
pProfiles, pTiming, pSkipProfiles, pSkipAccounts, pRootOnly, pAccounts, pRegionList
|
287
|
+
)
|
288
|
+
AllAccountList = list(set([x["AccountId"] for x in AllCredentials]))
|
289
|
+
AllRegionList = list(set([x["Region"] for x in AllCredentials]))
|
290
|
+
# Find the hosted zones
|
291
|
+
AllHostedZones = find_all_hosted_zones(AllCredentials)
|
292
|
+
# Display results
|
293
|
+
print()
|
294
|
+
|
295
|
+
display_dict = {
|
296
|
+
# 'ParentProfile': {'DisplayOrder': 1, 'Heading': 'Parent Profile'},
|
297
|
+
"MgmtAccount": {"DisplayOrder": 1, "Heading": "Mgmt Acct"},
|
298
|
+
"AccountId": {"DisplayOrder": 2, "Heading": "Acct Number"},
|
299
|
+
"Region": {"DisplayOrder": 3, "Heading": "Region"},
|
300
|
+
"PHZName": {"DisplayOrder": 4, "Heading": "Zone Name"},
|
301
|
+
"Records": {"DisplayOrder": 5, "Heading": "# of Records"},
|
302
|
+
"PHZId": {"DisplayOrder": 6, "Heading": "Zone ID"},
|
303
|
+
}
|
304
|
+
sorted_results = sorted(
|
305
|
+
AllHostedZones, key=lambda x: (x["ParentProfile"], x["MgmtAccount"], x["AccountId"], x["PHZName"], x["Region"])
|
306
|
+
)
|
307
|
+
display_results(sorted_results, display_dict, None, pFilename)
|
308
|
+
|
309
|
+
print(
|
310
|
+
f"{Fore.RED}Found {len(AllHostedZones)} Hosted Zones across {len(AllAccountList)} accounts across {len(AllRegionList)} regions{Fore.RESET}"
|
311
|
+
)
|
312
|
+
print()
|
313
|
+
if pTiming:
|
314
|
+
print(ERASE_LINE)
|
315
|
+
print(f"{Fore.GREEN}This script took {time() - begin_time:.2f} seconds{Fore.RESET}")
|
316
|
+
print(ERASE_LINE)
|
317
|
+
print("Thanks for using this script...")
|
318
|
+
print()
|