arnmatch 0.1.0__tar.gz
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.
- arnmatch-0.1.0/.claude/settings.local.json +16 -0
- arnmatch-0.1.0/.gitignore +216 -0
- arnmatch-0.1.0/.python-version +1 -0
- arnmatch-0.1.0/CLAUDE.md +0 -0
- arnmatch-0.1.0/Makefile +21 -0
- arnmatch-0.1.0/PKG-INFO +6 -0
- arnmatch-0.1.0/README.md +0 -0
- arnmatch-0.1.0/codegen/.gitignore +1 -0
- arnmatch-0.1.0/codegen/codegen.py +314 -0
- arnmatch-0.1.0/codegen/scraper.py +140 -0
- arnmatch-0.1.0/pyproject.toml +26 -0
- arnmatch-0.1.0/src/arnmatch/__init__.py +131 -0
- arnmatch-0.1.0/src/arnmatch/arn_patterns.py +2796 -0
- arnmatch-0.1.0/uv.lock +185 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"permissions": {
|
|
3
|
+
"allow": [
|
|
4
|
+
"mcp__plugin_adaptivegears_adaptivegears__search",
|
|
5
|
+
"mcp__plugin_adaptivegears_adaptivegears__read",
|
|
6
|
+
"Bash(uv init:*)",
|
|
7
|
+
"Bash(uv venv:*)",
|
|
8
|
+
"Bash(uv add:*)",
|
|
9
|
+
"Bash(uv run:*)",
|
|
10
|
+
"Bash(uv sync:*)"
|
|
11
|
+
]
|
|
12
|
+
},
|
|
13
|
+
"enabledPlugins": {
|
|
14
|
+
"adaptivegears@adaptivegears-marketplace": true
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[codz]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
share/python-wheels/
|
|
24
|
+
*.egg-info/
|
|
25
|
+
.installed.cfg
|
|
26
|
+
*.egg
|
|
27
|
+
MANIFEST
|
|
28
|
+
|
|
29
|
+
# PyInstaller
|
|
30
|
+
# Usually these files are written by a python script from a template
|
|
31
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
32
|
+
*.manifest
|
|
33
|
+
*.spec
|
|
34
|
+
|
|
35
|
+
# Installer logs
|
|
36
|
+
pip-log.txt
|
|
37
|
+
pip-delete-this-directory.txt
|
|
38
|
+
|
|
39
|
+
# Unit test / coverage reports
|
|
40
|
+
htmlcov/
|
|
41
|
+
.tox/
|
|
42
|
+
.nox/
|
|
43
|
+
.coverage
|
|
44
|
+
.coverage.*
|
|
45
|
+
.cache
|
|
46
|
+
nosetests.xml
|
|
47
|
+
coverage.xml
|
|
48
|
+
*.cover
|
|
49
|
+
*.py.cover
|
|
50
|
+
.hypothesis/
|
|
51
|
+
.pytest_cache/
|
|
52
|
+
cover/
|
|
53
|
+
|
|
54
|
+
# Translations
|
|
55
|
+
*.mo
|
|
56
|
+
*.pot
|
|
57
|
+
|
|
58
|
+
# Django stuff:
|
|
59
|
+
*.log
|
|
60
|
+
local_settings.py
|
|
61
|
+
db.sqlite3
|
|
62
|
+
db.sqlite3-journal
|
|
63
|
+
|
|
64
|
+
# Flask stuff:
|
|
65
|
+
instance/
|
|
66
|
+
.webassets-cache
|
|
67
|
+
|
|
68
|
+
# Scrapy stuff:
|
|
69
|
+
.scrapy
|
|
70
|
+
|
|
71
|
+
# Sphinx documentation
|
|
72
|
+
docs/_build/
|
|
73
|
+
|
|
74
|
+
# PyBuilder
|
|
75
|
+
.pybuilder/
|
|
76
|
+
target/
|
|
77
|
+
|
|
78
|
+
# Jupyter Notebook
|
|
79
|
+
.ipynb_checkpoints
|
|
80
|
+
|
|
81
|
+
# IPython
|
|
82
|
+
profile_default/
|
|
83
|
+
ipython_config.py
|
|
84
|
+
|
|
85
|
+
# pyenv
|
|
86
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
87
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
88
|
+
# .python-version
|
|
89
|
+
|
|
90
|
+
# pipenv
|
|
91
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
92
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
93
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
94
|
+
# install all needed dependencies.
|
|
95
|
+
# Pipfile.lock
|
|
96
|
+
|
|
97
|
+
# UV
|
|
98
|
+
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
|
|
99
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
100
|
+
# commonly ignored for libraries.
|
|
101
|
+
# uv.lock
|
|
102
|
+
|
|
103
|
+
# poetry
|
|
104
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
105
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
106
|
+
# commonly ignored for libraries.
|
|
107
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
108
|
+
# poetry.lock
|
|
109
|
+
# poetry.toml
|
|
110
|
+
|
|
111
|
+
# pdm
|
|
112
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
113
|
+
# pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
|
|
114
|
+
# https://pdm-project.org/en/latest/usage/project/#working-with-version-control
|
|
115
|
+
# pdm.lock
|
|
116
|
+
# pdm.toml
|
|
117
|
+
.pdm-python
|
|
118
|
+
.pdm-build/
|
|
119
|
+
|
|
120
|
+
# pixi
|
|
121
|
+
# Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
|
|
122
|
+
# pixi.lock
|
|
123
|
+
# Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
|
|
124
|
+
# in the .venv directory. It is recommended not to include this directory in version control.
|
|
125
|
+
.pixi
|
|
126
|
+
|
|
127
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
128
|
+
__pypackages__/
|
|
129
|
+
|
|
130
|
+
# Celery stuff
|
|
131
|
+
celerybeat-schedule
|
|
132
|
+
celerybeat.pid
|
|
133
|
+
|
|
134
|
+
# Redis
|
|
135
|
+
*.rdb
|
|
136
|
+
*.aof
|
|
137
|
+
*.pid
|
|
138
|
+
|
|
139
|
+
# RabbitMQ
|
|
140
|
+
mnesia/
|
|
141
|
+
rabbitmq/
|
|
142
|
+
rabbitmq-data/
|
|
143
|
+
|
|
144
|
+
# ActiveMQ
|
|
145
|
+
activemq-data/
|
|
146
|
+
|
|
147
|
+
# SageMath parsed files
|
|
148
|
+
*.sage.py
|
|
149
|
+
|
|
150
|
+
# Environments
|
|
151
|
+
.env
|
|
152
|
+
.envrc
|
|
153
|
+
.venv
|
|
154
|
+
env/
|
|
155
|
+
venv/
|
|
156
|
+
ENV/
|
|
157
|
+
env.bak/
|
|
158
|
+
venv.bak/
|
|
159
|
+
|
|
160
|
+
# Spyder project settings
|
|
161
|
+
.spyderproject
|
|
162
|
+
.spyproject
|
|
163
|
+
|
|
164
|
+
# Rope project settings
|
|
165
|
+
.ropeproject
|
|
166
|
+
|
|
167
|
+
# mkdocs documentation
|
|
168
|
+
/site
|
|
169
|
+
|
|
170
|
+
# mypy
|
|
171
|
+
.mypy_cache/
|
|
172
|
+
.dmypy.json
|
|
173
|
+
dmypy.json
|
|
174
|
+
|
|
175
|
+
# Pyre type checker
|
|
176
|
+
.pyre/
|
|
177
|
+
|
|
178
|
+
# pytype static type analyzer
|
|
179
|
+
.pytype/
|
|
180
|
+
|
|
181
|
+
# Cython debug symbols
|
|
182
|
+
cython_debug/
|
|
183
|
+
|
|
184
|
+
# PyCharm
|
|
185
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
186
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
187
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
188
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
189
|
+
# .idea/
|
|
190
|
+
|
|
191
|
+
# Abstra
|
|
192
|
+
# Abstra is an AI-powered process automation framework.
|
|
193
|
+
# Ignore directories containing user credentials, local state, and settings.
|
|
194
|
+
# Learn more at https://abstra.io/docs
|
|
195
|
+
.abstra/
|
|
196
|
+
|
|
197
|
+
# Visual Studio Code
|
|
198
|
+
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
|
|
199
|
+
# that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
|
|
200
|
+
# and can be added to the global gitignore or merged into this file. However, if you prefer,
|
|
201
|
+
# you could uncomment the following to ignore the entire vscode folder
|
|
202
|
+
# .vscode/
|
|
203
|
+
|
|
204
|
+
# Ruff stuff:
|
|
205
|
+
.ruff_cache/
|
|
206
|
+
|
|
207
|
+
# PyPI configuration file
|
|
208
|
+
.pypirc
|
|
209
|
+
|
|
210
|
+
# Marimo
|
|
211
|
+
marimo/_static/
|
|
212
|
+
marimo/_lsp/
|
|
213
|
+
__marimo__/
|
|
214
|
+
|
|
215
|
+
# Streamlit
|
|
216
|
+
.streamlit/secrets.toml
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
3.12
|
arnmatch-0.1.0/CLAUDE.md
ADDED
|
File without changes
|
arnmatch-0.1.0/Makefile
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
.DEFAULT_GOAL := help
|
|
2
|
+
|
|
3
|
+
.PHONY: help
|
|
4
|
+
help: ## Show this help
|
|
5
|
+
@egrep -h '\s##\s' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'
|
|
6
|
+
|
|
7
|
+
.PHONY: lint
|
|
8
|
+
lint: ## Run linter
|
|
9
|
+
uv run ruff check .
|
|
10
|
+
|
|
11
|
+
.PHONY: check
|
|
12
|
+
check: lint ## Run lint and test
|
|
13
|
+
|
|
14
|
+
.PHONY: build
|
|
15
|
+
build: ## Build package
|
|
16
|
+
cp codegen/build/arn_patterns.py src/arnmatch/arn_patterns.py
|
|
17
|
+
uv build
|
|
18
|
+
|
|
19
|
+
.PHONY: clean
|
|
20
|
+
clean: ## Clean build artifacts
|
|
21
|
+
rm -rf dist/ __pycache__/ .pytest_cache/ .ruff_cache/
|
arnmatch-0.1.0/PKG-INFO
ADDED
arnmatch-0.1.0/README.md
ADDED
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
!build
|
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
# /// script
|
|
2
|
+
# requires-python = ">=3.10"
|
|
3
|
+
# dependencies = ["requests", "joblib", "beautifulsoup4"]
|
|
4
|
+
# ///
|
|
5
|
+
|
|
6
|
+
import logging
|
|
7
|
+
import re
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
from scraper import AWSScraper
|
|
11
|
+
|
|
12
|
+
log = logging.getLogger(__name__)
|
|
13
|
+
|
|
14
|
+
CODEGEN_DIR = Path(__file__).parent
|
|
15
|
+
BUILD_DIR = CODEGEN_DIR / "build"
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class ARNIndexer:
|
|
19
|
+
"""Processes raw ARN resources into a clean, sorted index."""
|
|
20
|
+
|
|
21
|
+
# ARNs to exclude (have multiple resource types or other issues)
|
|
22
|
+
EXCLUDED_ARNS = {
|
|
23
|
+
"arn:${Partition}:${Vendor}:${Region}:*:${ResourceType}:${RecoveryPointId}",
|
|
24
|
+
"arn:${Partition}:rtbfabric:${Region}:${Account}:gateway/${GatewayId}/link/${LinkId}",
|
|
25
|
+
"arn:${Partition}:rtbfabric:${Region}:${Account}:gateway/${GatewayId}",
|
|
26
|
+
"arn:${Partition}:aws-marketplace::${Account}:${Catalog}/ReportingData/${FactTable}/Dashboard/${DashboardName}",
|
|
27
|
+
"arn:${Partition}:iot:${Region}:${Account}:thinggroup/${ThingGroupName}",
|
|
28
|
+
"arn:${Partition}:mediapackagev2:${Region}:${Account}:channelGroup/${ChannelGroupName}/channel/${ChannelName}",
|
|
29
|
+
"arn:${Partition}:mediapackagev2:${Region}:${Account}:channelGroup/${ChannelGroupName}/channel/${ChannelName}/originEndpoint/${OriginEndpointName}",
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
# Specific resource types to exclude
|
|
33
|
+
EXCLUDED_RESOURCE_TYPES = {
|
|
34
|
+
("backup", "recoveryPoint"),
|
|
35
|
+
("connect", "wildcard-agent-status"),
|
|
36
|
+
("ebs", "snapshot"),
|
|
37
|
+
("connect", "wildcard-contact-flow"),
|
|
38
|
+
("connect", "wildcard-legacy-phone-number"),
|
|
39
|
+
("connect", "wildcard-phone-number"),
|
|
40
|
+
("connect", "wildcard-queue"),
|
|
41
|
+
("connect", "wildcard-quick-connect"),
|
|
42
|
+
("identitystore", "AllGroupMemberships"),
|
|
43
|
+
("identitystore", "AllGroups"),
|
|
44
|
+
("identitystore", "AllUsers"),
|
|
45
|
+
("imagebuilder", "allComponentBuildVersions"),
|
|
46
|
+
("imagebuilder", "allImageBuildVersions"),
|
|
47
|
+
("imagebuilder", "allWorkflowBuildVersions"),
|
|
48
|
+
("mobiletargeting", "apps"),
|
|
49
|
+
("mobiletargeting", "recommenders"),
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
# Pattern overrides: (service, resource_type) -> corrected arn_pattern
|
|
53
|
+
# Used when AWS docs have wildcards instead of capture groups
|
|
54
|
+
PATTERN_OVERRIDES = {
|
|
55
|
+
# amplifybackend: wildcards replaced with capture groups
|
|
56
|
+
("amplifybackend", "api"): "arn:${Partition}:amplifybackend:${Region}:${Account}:/backend/${AppId}/api/${ApiId}",
|
|
57
|
+
("amplifybackend", "auth"): "arn:${Partition}:amplifybackend:${Region}:${Account}:/backend/${AppId}/auth/${AuthId}",
|
|
58
|
+
("amplifybackend", "token"): "arn:${Partition}:amplifybackend:${Region}:${Account}:/backend/${AppId}/challenge/${ChallengeId}",
|
|
59
|
+
("amplifybackend", "config"): "arn:${Partition}:amplifybackend:${Region}:${Account}:/backend/${AppId}/config/${ConfigId}",
|
|
60
|
+
("amplifybackend", "environment"): "arn:${Partition}:amplifybackend:${Region}:${Account}:/backend/${AppId}/environments/${EnvironmentId}",
|
|
61
|
+
("amplifybackend", "job"): "arn:${Partition}:amplifybackend:${Region}:${Account}:/backend/${AppId}/job/${JobId}",
|
|
62
|
+
("amplifybackend", "storage"): "arn:${Partition}:amplifybackend:${Region}:${Account}:/backend/${AppId}/storage/${StorageId}",
|
|
63
|
+
("amplifybackend", "backend"): "arn:${Partition}:amplifybackend:${Region}:${Account}:/backend/${AppId}/${SubResourceId}",
|
|
64
|
+
("amplifybackend", "created-backend"): "arn:${Partition}:amplifybackend:${Region}:${Account}:/backend/${BackendId}",
|
|
65
|
+
# artifact: wildcards replaced with capture groups
|
|
66
|
+
("artifact", "agreement"): "arn:${Partition}:artifact:::agreement/${AgreementId}",
|
|
67
|
+
("artifact", "customer-agreement"): "arn:${Partition}:artifact::${Account}:customer-agreement/${CustomerAgreementId}",
|
|
68
|
+
# dms: wildcards replaced with capture groups
|
|
69
|
+
("dms", "ReplicationTaskAssessmentRun"): "arn:${Partition}:dms:${Region}:${Account}:assessment-run:${AssessmentRunId}",
|
|
70
|
+
("dms", "Certificate"): "arn:${Partition}:dms:${Region}:${Account}:cert:${CertificateId}",
|
|
71
|
+
("dms", "DataMigration"): "arn:${Partition}:dms:${Region}:${Account}:data-migration:${DataMigrationId}",
|
|
72
|
+
("dms", "DataProvider"): "arn:${Partition}:dms:${Region}:${Account}:data-provider:${DataProviderId}",
|
|
73
|
+
("dms", "Endpoint"): "arn:${Partition}:dms:${Region}:${Account}:endpoint:${EndpointId}",
|
|
74
|
+
("dms", "EventSubscription"): "arn:${Partition}:dms:${Region}:${Account}:es:${EventSubscriptionId}",
|
|
75
|
+
("dms", "ReplicationTaskIndividualAssessment"): "arn:${Partition}:dms:${Region}:${Account}:individual-assessment:${IndividualAssessmentId}",
|
|
76
|
+
("dms", "InstanceProfile"): "arn:${Partition}:dms:${Region}:${Account}:instance-profile:${InstanceProfileId}",
|
|
77
|
+
("dms", "MigrationProject"): "arn:${Partition}:dms:${Region}:${Account}:migration-project:${MigrationProjectId}",
|
|
78
|
+
("dms", "ReplicationInstance"): "arn:${Partition}:dms:${Region}:${Account}:rep:${ReplicationInstanceId}",
|
|
79
|
+
("dms", "ReplicationConfig"): "arn:${Partition}:dms:${Region}:${Account}:replication-config:${ReplicationConfigId}",
|
|
80
|
+
("dms", "ReplicationTask"): "arn:${Partition}:dms:${Region}:${Account}:task:${TaskId}",
|
|
81
|
+
("dms", "ReplicationSubnetGroup"): "arn:${Partition}:dms:${Region}:${Account}:subgrp:${SubnetGroupName}",
|
|
82
|
+
# ec2: add account (modern format)
|
|
83
|
+
("ec2", "image"): "arn:${Partition}:ec2:${Region}:${Account}:image/${ImageId}",
|
|
84
|
+
("ec2", "snapshot"): "arn:${Partition}:ec2:${Region}:${Account}:snapshot/${SnapshotId}",
|
|
85
|
+
# health: wildcards replaced with capture groups
|
|
86
|
+
("health", "event"): "arn:${Partition}:health:${Region}:${Account}:event/${Service}/${EventTypeCode}/${EventId}",
|
|
87
|
+
# neptune-db: wildcard replaced with capture group
|
|
88
|
+
("neptune-db", "database"): "arn:${Partition}:neptune-db:${Region}:${Account}:${ClusterResourceId}/${DatabaseId}",
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
# Additional patterns not in AWS docs (service, arn_pattern, resource_type)
|
|
92
|
+
PATTERN_INCLUDES = [
|
|
93
|
+
# EKS Kubernetes resources (from Resource Explorer)
|
|
94
|
+
("eks", "arn:${Partition}:eks:${Region}:${Account}:deployment/${ClusterName}/${Namespace}/${DeploymentName}/${UUID}", "deployment"),
|
|
95
|
+
("eks", "arn:${Partition}:eks:${Region}:${Account}:replicaset/${ClusterName}/${Namespace}/${ReplicaSetName}/${UUID}", "replicaset"),
|
|
96
|
+
("eks", "arn:${Partition}:eks:${Region}:${Account}:service/${ClusterName}/${Namespace}/${ServiceName}/${UUID}", "service"),
|
|
97
|
+
("eks", "arn:${Partition}:eks:${Region}:${Account}:endpointslice/${ClusterName}/${Namespace}/${EndpointSliceName}/${UUID}", "endpointslice"),
|
|
98
|
+
("eks", "arn:${Partition}:eks:${Region}:${Account}:namespace/${ClusterName}/${NamespaceName}/${UUID}", "namespace"),
|
|
99
|
+
("eks", "arn:${Partition}:eks:${Region}:${Account}:ingress/${ClusterName}/${Namespace}/${IngressName}/${UUID}", "ingress"),
|
|
100
|
+
("eks", "arn:${Partition}:eks:${Region}:${Account}:statefulset/${ClusterName}/${Namespace}/${StatefulSetName}/${UUID}", "statefulset"),
|
|
101
|
+
("eks", "arn:${Partition}:eks:${Region}:${Account}:persistentvolume/${ClusterName}/${PersistentVolumeName}/${UUID}", "persistentvolume"),
|
|
102
|
+
("eks", "arn:${Partition}:eks:${Region}:${Account}:daemonset/${ClusterName}/${Namespace}/${DaemonSetName}/${UUID}", "daemonset"),
|
|
103
|
+
# Inspector (legacy)
|
|
104
|
+
("inspector", "arn:${Partition}:inspector:${Region}:${Account}:target/${TargetId}/template/${TemplateId}", "target-template"),
|
|
105
|
+
]
|
|
106
|
+
|
|
107
|
+
def process(self, resources):
|
|
108
|
+
"""Process raw resources: add arn_service, apply overrides, filter, dedupe, add includes, sort."""
|
|
109
|
+
# Add arn_service and apply overrides
|
|
110
|
+
for r in resources:
|
|
111
|
+
r["arn_service"] = self.extract_arn_service(r["arn_pattern"])
|
|
112
|
+
key = (r["service"], r["resource_type"])
|
|
113
|
+
if key in self.PATTERN_OVERRIDES:
|
|
114
|
+
r["arn_pattern"] = self.PATTERN_OVERRIDES[key]
|
|
115
|
+
|
|
116
|
+
# Filter
|
|
117
|
+
resources = [
|
|
118
|
+
r for r in resources
|
|
119
|
+
if r["arn_pattern"] not in self.EXCLUDED_ARNS
|
|
120
|
+
and (r["service"], r["resource_type"]) not in self.EXCLUDED_RESOURCE_TYPES
|
|
121
|
+
]
|
|
122
|
+
log.info(f"After filtering: {len(resources)} resources")
|
|
123
|
+
|
|
124
|
+
# Deduplicate
|
|
125
|
+
resources = self.deduplicate(resources)
|
|
126
|
+
log.info(f"After deduplication: {len(resources)} resources")
|
|
127
|
+
|
|
128
|
+
# Add included patterns
|
|
129
|
+
for service, arn_pattern, resource_type in self.PATTERN_INCLUDES:
|
|
130
|
+
resources.append({
|
|
131
|
+
"service": service,
|
|
132
|
+
"arn_service": service,
|
|
133
|
+
"resource_type": resource_type,
|
|
134
|
+
"arn_pattern": arn_pattern,
|
|
135
|
+
})
|
|
136
|
+
log.info(f"After includes: {len(resources)} resources")
|
|
137
|
+
|
|
138
|
+
# Sort
|
|
139
|
+
resources = self.sort_by_specificity(resources)
|
|
140
|
+
|
|
141
|
+
return resources
|
|
142
|
+
|
|
143
|
+
def extract_arn_service(self, arn_pattern):
|
|
144
|
+
"""Extract service from ARN pattern (3rd colon-separated part)."""
|
|
145
|
+
parts = arn_pattern.split(":")
|
|
146
|
+
if len(parts) >= 3:
|
|
147
|
+
return parts[2]
|
|
148
|
+
return ""
|
|
149
|
+
|
|
150
|
+
def deduplicate(self, resources):
|
|
151
|
+
"""Deduplicate ARN patterns, keeping authoritative service."""
|
|
152
|
+
by_arn = {}
|
|
153
|
+
for r in resources:
|
|
154
|
+
arn = r["arn_pattern"]
|
|
155
|
+
if arn not in by_arn:
|
|
156
|
+
by_arn[arn] = []
|
|
157
|
+
by_arn[arn].append(r)
|
|
158
|
+
|
|
159
|
+
results = []
|
|
160
|
+
for arn, group in by_arn.items():
|
|
161
|
+
if len(group) == 1:
|
|
162
|
+
results.append(group[0])
|
|
163
|
+
else:
|
|
164
|
+
# Prefer resource where arn_service matches service
|
|
165
|
+
matches = [r for r in group if r["arn_service"] == r["service"]]
|
|
166
|
+
results.append(matches[0] if matches else group[0])
|
|
167
|
+
|
|
168
|
+
return results
|
|
169
|
+
|
|
170
|
+
def sort_by_specificity(self, resources):
|
|
171
|
+
"""Sort patterns: more specific (more segments, literals) first."""
|
|
172
|
+
return sorted(resources, key=self.sort_key)
|
|
173
|
+
|
|
174
|
+
def sort_key(self, r):
|
|
175
|
+
arn = r["arn_pattern"]
|
|
176
|
+
parts = arn.split(":", 5)
|
|
177
|
+
service = parts[2] if len(parts) > 2 else ""
|
|
178
|
+
region = parts[3] if len(parts) > 3 else ""
|
|
179
|
+
account = parts[4] if len(parts) > 4 else ""
|
|
180
|
+
resource = parts[5] if len(parts) > 5 else ""
|
|
181
|
+
|
|
182
|
+
segments = self.parse_segments(resource)
|
|
183
|
+
seg_count = len(segments)
|
|
184
|
+
|
|
185
|
+
norm_service = self.normalize_for_sort(service)
|
|
186
|
+
norm_region = self.normalize_for_sort(region)
|
|
187
|
+
norm_account = self.normalize_for_sort(account)
|
|
188
|
+
norm_segments = [self.normalize_for_sort(s) for s in segments]
|
|
189
|
+
|
|
190
|
+
return (norm_service, norm_region, norm_account, -seg_count, norm_segments)
|
|
191
|
+
|
|
192
|
+
def parse_segments(self, resource):
|
|
193
|
+
"""Split resource into segments by /, : and variables."""
|
|
194
|
+
var_pattern = re.compile(r"(\$\{[^}]+\})")
|
|
195
|
+
parts = [s1 for s0 in resource.split("/") for s1 in s0.split(":")]
|
|
196
|
+
segments = []
|
|
197
|
+
for part in parts:
|
|
198
|
+
splits = var_pattern.split(part)
|
|
199
|
+
segments.extend([s for s in splits if s])
|
|
200
|
+
return segments
|
|
201
|
+
|
|
202
|
+
def normalize_for_sort(self, value):
|
|
203
|
+
"""Replace variables and wildcards so they sort after literals."""
|
|
204
|
+
value = re.sub(r"\$\{[^}]+\}", "~", value)
|
|
205
|
+
value = value.replace("*", "~~")
|
|
206
|
+
return value
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
class CodeGenerator:
|
|
210
|
+
"""Generates Python code from processed ARN resources."""
|
|
211
|
+
|
|
212
|
+
# Placeholder patterns: map placeholder name -> regex pattern
|
|
213
|
+
# Based on AWS regex: ^arn:[\w+=/,.@-]+:service:[\w+=/,.@-]*:[0-9]+:...
|
|
214
|
+
PLACEHOLDER_PATTERNS = {
|
|
215
|
+
"Partition": r"[\w-]+", # aws, aws-cn, aws-us-gov
|
|
216
|
+
"Region": r"[\w-]*", # us-east-1, eu-west-1, or empty
|
|
217
|
+
"Account": r"\d{12}", # AWS accounts are always 12 digits
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
# Type aliases: map AWS doc type -> list of known aliases
|
|
221
|
+
TYPE_ALIASES = {
|
|
222
|
+
("elasticloadbalancing", "loadbalancer/app/"): ["loadbalancer/app"],
|
|
223
|
+
("elasticloadbalancing", "loadbalancer/net/"): ["loadbalancer/net"],
|
|
224
|
+
("elasticloadbalancing", "loadbalancer/gwy/"): ["loadbalancer/gwy"],
|
|
225
|
+
("events", "rule-on-default-event-bus"): ["rule"],
|
|
226
|
+
("secretsmanager", "Secret"): ["secret"],
|
|
227
|
+
("mq", "configurations"): ["configuration"],
|
|
228
|
+
("inspector", "target-template"): ["target/template"],
|
|
229
|
+
("backup", "backupPlan"): ["backup-plan"],
|
|
230
|
+
("backup", "backupVault"): ["backup-vault"],
|
|
231
|
+
("ssm", "resourcedatasync"): ["resource-data-sync"],
|
|
232
|
+
("s3", "storagelensconfiguration"): ["storage-lens"],
|
|
233
|
+
("dms", "ReplicationSubnetGroup"): ["subgrp"],
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
def generate(self, resources, output_path):
|
|
237
|
+
"""Generate Python file with ARN patterns."""
|
|
238
|
+
# Group by service
|
|
239
|
+
by_service = {}
|
|
240
|
+
for r in resources:
|
|
241
|
+
service = r["arn_service"]
|
|
242
|
+
if service not in by_service:
|
|
243
|
+
by_service[service] = []
|
|
244
|
+
regex = self.pattern_to_regex(r["arn_pattern"])
|
|
245
|
+
type_names = self.get_type_names(service, r["resource_type"])
|
|
246
|
+
by_service[service].append((regex, type_names))
|
|
247
|
+
|
|
248
|
+
# Write Python file
|
|
249
|
+
with open(output_path, "w") as f:
|
|
250
|
+
f.write("# Auto-generated ARN patterns for matching\n")
|
|
251
|
+
f.write("# Patterns are ordered: most specific first\n")
|
|
252
|
+
f.write("import re\n\n")
|
|
253
|
+
f.write("ARN_PATTERNS = {\n")
|
|
254
|
+
|
|
255
|
+
for service, patterns in by_service.items():
|
|
256
|
+
f.write(f" {service!r}: [\n")
|
|
257
|
+
for regex, type_names in patterns:
|
|
258
|
+
f.write(f' (re.compile(r"{regex}"), {type_names!r}),\n')
|
|
259
|
+
f.write(" ],\n")
|
|
260
|
+
|
|
261
|
+
f.write("}\n")
|
|
262
|
+
|
|
263
|
+
log.info(f"Wrote {len(resources)} patterns for {len(by_service)} services to {output_path}")
|
|
264
|
+
|
|
265
|
+
def pattern_to_regex(self, arn_pattern):
|
|
266
|
+
"""Convert ARN pattern to regex with named capture groups."""
|
|
267
|
+
placeholders = []
|
|
268
|
+
|
|
269
|
+
def capture_var(m):
|
|
270
|
+
placeholders.append(m.group(1))
|
|
271
|
+
return f"\x00{len(placeholders) - 1}\x00"
|
|
272
|
+
|
|
273
|
+
result = re.sub(r"\$\{([^}]+)\}", capture_var, arn_pattern)
|
|
274
|
+
result = result.replace("*", "\x01")
|
|
275
|
+
result = re.escape(result)
|
|
276
|
+
result = result.replace("\\-", "-")
|
|
277
|
+
|
|
278
|
+
for i, name in enumerate(placeholders):
|
|
279
|
+
pattern = self.PLACEHOLDER_PATTERNS.get(name, ".+?")
|
|
280
|
+
result = result.replace(f"\x00{i}\x00", f"(?P<{name}>{pattern})")
|
|
281
|
+
|
|
282
|
+
result = result.replace("\x01", ".*")
|
|
283
|
+
return f"^{result}$"
|
|
284
|
+
|
|
285
|
+
def get_type_names(self, service, resource_type):
|
|
286
|
+
"""Get list of type names: primary type + any aliases."""
|
|
287
|
+
types = [resource_type]
|
|
288
|
+
aliases = self.TYPE_ALIASES.get((service, resource_type), [])
|
|
289
|
+
types.extend(aliases)
|
|
290
|
+
return types
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
def main():
|
|
294
|
+
logging.basicConfig(level=logging.INFO, format="%(message)s")
|
|
295
|
+
|
|
296
|
+
# Scrape
|
|
297
|
+
scraper = AWSScraper()
|
|
298
|
+
services = scraper.get_services()
|
|
299
|
+
resources = []
|
|
300
|
+
for svc in services:
|
|
301
|
+
resources.extend(scraper.get_resources(svc["href"]))
|
|
302
|
+
|
|
303
|
+
# Process
|
|
304
|
+
indexer = ARNIndexer()
|
|
305
|
+
resources = indexer.process(resources)
|
|
306
|
+
|
|
307
|
+
# Generate
|
|
308
|
+
BUILD_DIR.mkdir(exist_ok=True)
|
|
309
|
+
generator = CodeGenerator()
|
|
310
|
+
generator.generate(resources, BUILD_DIR / "arn_patterns.py")
|
|
311
|
+
|
|
312
|
+
|
|
313
|
+
if __name__ == "__main__":
|
|
314
|
+
main()
|