arnmatch 2026.1.3__py3-none-any.whl → 2026.2.0__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.
arnmatch/__init__.py CHANGED
@@ -1,17 +1,12 @@
1
1
  """ARN pattern matching using regex patterns."""
2
2
 
3
- __version__ = "2026.01.3"
3
+ __version__ = "2026.02.0"
4
4
 
5
5
  import sys
6
6
  from dataclasses import dataclass
7
7
  from functools import cached_property
8
8
 
9
- from .arn_patterns import (
10
- ARN_PATTERNS,
11
- AWS_SDK_SERVICES,
12
- AWS_SDK_SERVICES_DEFAULT,
13
- AWS_SDK_SERVICES_OVERRIDE,
14
- )
9
+ from .arn_patterns import ARN_PATTERNS, AWS_SDK_SERVICES
15
10
 
16
11
  # Standard groups that are not resource-specific
17
12
  STANDARD_GROUPS = {"Partition", "Region", "Account"}
@@ -34,6 +29,8 @@ class ARN:
34
29
  resource_type: str # canonical type (from AWS docs)
35
30
  resource_types: list[str] # all known names including Resource Explorer
36
31
  attributes: dict[str, str]
32
+ aws_sdk_service: str | None = None
33
+ cloudformation_resource: str | None = None
37
34
 
38
35
  @cached_property
39
36
  def resource_id(self) -> str:
@@ -93,26 +90,6 @@ class ARN:
93
90
  """
94
91
  return AWS_SDK_SERVICES.get(self.aws_service, [])
95
92
 
96
- @cached_property
97
- def aws_sdk_service(self) -> str | None:
98
- """Get the AWS SDK (boto3) client name for this resource.
99
-
100
- Returns single client name. Checks resource-level overrides first,
101
- then falls back to service default. Returns None if no SDK exists.
102
- """
103
- # Check resource-level override
104
- overrides = AWS_SDK_SERVICES_OVERRIDE.get(self.aws_service)
105
- if overrides and self.resource_type in overrides:
106
- return overrides[self.resource_type]
107
-
108
- # Fall back to service-level
109
- sdks = self.aws_sdk_services
110
- if len(sdks) == 1:
111
- return sdks[0]
112
- if len(sdks) > 1:
113
- return AWS_SDK_SERVICES_DEFAULT.get(self.aws_service)
114
- return None
115
-
116
93
 
117
94
  def arnmatch(arn: str) -> ARN:
118
95
  """Match ARN against patterns.
@@ -131,17 +108,19 @@ def arnmatch(arn: str) -> ARN:
131
108
  if service not in ARN_PATTERNS:
132
109
  raise ARNError(f"Unknown service: {service}")
133
110
 
134
- for regex, type_names in ARN_PATTERNS[service]:
135
- match = regex.match(arn)
111
+ for pattern in ARN_PATTERNS[service]:
112
+ match = pattern['regex'].match(arn)
136
113
  if match:
137
114
  return ARN(
138
115
  aws_partition=partition,
139
116
  aws_service=service,
140
117
  aws_region=region,
141
118
  aws_account=account,
142
- resource_type=type_names[0], # canonical
143
- resource_types=type_names, # all known names
119
+ resource_type=pattern['names'][0], # canonical
120
+ resource_types=pattern['names'], # all known names
144
121
  attributes=match.groupdict(),
122
+ aws_sdk_service=pattern['sdk'],
123
+ cloudformation_resource=pattern['cfn'],
145
124
  )
146
125
 
147
126
  raise ARNError(f"No pattern matched ARN: {arn}")
@@ -164,6 +143,7 @@ def main() -> None:
164
143
  print(f"resource_type: {result.resource_type}")
165
144
  print(f"resource_id: {result.resource_id}")
166
145
  print(f"resource_name: {result.resource_name}")
146
+ print(f"cloudformation_resource: {result.cloudformation_resource}")
167
147
  except ARNError as e:
168
148
  print(f"Error: {e}", file=sys.stderr)
169
149
  sys.exit(1)