cfn-check 0.3.1__py3-none-any.whl → 0.3.2__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.

Potentially problematic release.


This version of cfn-check might be problematic. Click here for more details.

@@ -146,7 +146,7 @@ class Token:
146
146
  (idx, item)
147
147
  for idx, item in enumerate(node)
148
148
  if self.selector.match(item) or (
149
- isinstance(item, dict, list)
149
+ isinstance(item, (dict, list))
150
150
  and any([
151
151
  self.selector.match(val)
152
152
  for val in item
@@ -155,8 +155,8 @@ class Token:
155
155
  ]
156
156
 
157
157
  return (
158
- [str(idx) for idx in matches],
159
- [item for item in matches]
158
+ [str(idx) for idx, _ in matches],
159
+ [item for _, item in matches]
160
160
  )
161
161
 
162
162
  def _match_unbound_range(
@@ -185,14 +185,29 @@ class Token:
185
185
  ) for idx, value in enumerate(node) if (
186
186
  str(value) == self.selector
187
187
  ) or (
188
- isinstance(value, dict, list)
189
- and value in self.selector
188
+ isinstance(value, (dict, list))
189
+ and self.selector in value
190
190
  )
191
191
  ]
192
192
 
193
+ for idx, match in enumerate(matches):
194
+ match_idx, item = match
195
+
196
+ if isinstance(item, dict):
197
+ matches[idx] = (
198
+ match_idx,
199
+ item.get(self.selector),
200
+ )
201
+
202
+ elif isinstance(item, list):
203
+ match_idx[idx] = (
204
+ match_idx,
205
+ matches[match_idx],
206
+ )
207
+
193
208
  return (
194
- [str(idx) for idx in matches],
195
- [item for item in matches]
209
+ [str(idx) for idx, _ in matches],
210
+ [item for _, item in matches]
196
211
  )
197
212
 
198
213
  def _match_nested_range(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cfn-check
3
- Version: 0.3.1
3
+ Version: 0.3.2
4
4
  Summary: Validate Cloud Formation
5
5
  Author-email: Ada Lundhe <adalundhe@lundhe.audio>
6
6
  License: MIT License
@@ -50,7 +50,7 @@ Dynamic: license-file
50
50
 
51
51
  | Package | cfn-check |
52
52
  | ----------- | ----------- |
53
- | Version | 0.2.0 |
53
+ | Version | 0.3.2 |
54
54
  | Download | https://pypi.org/project/cfn-check/ |
55
55
  | Source | https://github.com/adalundhe/cfn-check |
56
56
  | Keywords | cloud-formation, testing, aws, cli |
@@ -314,7 +314,7 @@ class ValidateSecurityGroups(Collection):
314
314
  "Resources::SecurityGroup::Properties::(SecurityGroup)",
315
315
  "It checks Security Groups are correctly definined",
316
316
  )
317
- def validate_test(self, value: list[dict]):
317
+ def validate_security_groups(self, value: list[dict]):
318
318
  assert len(value) > 0
319
319
 
320
320
  for item in value:
@@ -352,7 +352,7 @@ To select all `Resource` objects, then further extract the `Type` field from eac
352
352
  Ranges allow you to perform sophisticated selection of objects or data within a CloudFormation document.
353
353
 
354
354
  > [!IMPORTANT]
355
- > Range Tokens *only* work on list items. This means that any
355
+ > Range Tokens *only* work on arrays. This means that any
356
356
  > values or other objects/data in the selected section of the
357
357
  > CloudFormation document will be *ignored* and filtered out.
358
358
 
@@ -456,7 +456,7 @@ The Rule will fail as below:
456
456
  error: ❌ No results matching results for query Resources::[*]::Type
457
457
  ```
458
458
 
459
- As we're selecting objects, not an array! A valid use would be in validating the deeply nested zipfile code of a Lambda's `AppendItemToListFunction`:
459
+ as we're selecting objects, not an array! A valid use would be in validating the deeply nested zipfile code of a Lambda's `AppendItemToListFunction`:
460
460
 
461
461
  ```yaml
462
462
  AppendItemToListFunction:
@@ -514,7 +514,7 @@ will select any EC2 ImageIds that start with either `AWSRegion` or `Custom`.
514
514
 
515
515
  ### Nested Ranges
516
516
 
517
- CloudFormation often involes nested arrays, and navigates these can make for long and difficult-to-read Queries. To help reduce Query length, `cfn-check` supports nesting Range Tokens. For example, when evaluating:
517
+ CloudFormation often involes nested arrays, and navigating these can make for long and difficult-to-read Queries. To help reduce Query length, `cfn-check` supports nesting Range Tokens. For example, when evaluating:
518
518
 
519
519
  ```yaml
520
520
  ZipFile: !Join
@@ -13,7 +13,7 @@ cfn_check/evaluation/evaluator.py,sha256=weFBAYKVc9TjTB2zNMIVX77Bi9kIaWp2KRJa1IS
13
13
  cfn_check/evaluation/validate.py,sha256=yy8byYAoHxFqkS2HfewHup22B3bYtrUH2PhPuNAc--A,1547
14
14
  cfn_check/evaluation/parsing/__init__.py,sha256=s5TxU4mzsbNIpbMynbwibGR8ac0dTcf_2qUfGkAEDvQ,52
15
15
  cfn_check/evaluation/parsing/query_parser.py,sha256=4J3CJQKAyb11gugfx6OZT-mfSdNDB5Al8Jiy9DbJZMw,3459
16
- cfn_check/evaluation/parsing/token.py,sha256=Z-KRbQdMmbJTTLqobpzCG-fH5_VzDJIG2mnChhCwub8,6561
16
+ cfn_check/evaluation/parsing/token.py,sha256=_mf1hMnnu5TFXvnyfxAy-GjdVW9kvhgv1NLaSh4GF4k,6993
17
17
  cfn_check/evaluation/parsing/token_type.py,sha256=E5AVBerinBszMLjjc7ejwSSWEc0p0Ju_CNFhpoZi63c,325
18
18
  cfn_check/loader/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
19
19
  cfn_check/loader/loader.py,sha256=7yiDLLW_vNp_8O47erLXjQQtAB47fU3nimb91N5N_R8,532
@@ -25,10 +25,10 @@ cfn_check/shared/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,
25
25
  cfn_check/shared/types.py,sha256=-om3DyZsjK_tJd-I8SITkoE55W0nB2WA3LOc87Cs7xI,414
26
26
  cfn_check/validation/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
27
27
  cfn_check/validation/validator.py,sha256=FGPeb8Uc8lvX3Y5rs-fxeJKIOqzUXwXh_gCFcy6d3b0,1182
28
- cfn_check-0.3.1.dist-info/licenses/LICENSE,sha256=EbCpGNzOkyQ53ig7J2Iwgmy4Og0dgHe8COo3WylhIKk,1069
29
- example/rules.py,sha256=-xr-X0tnkV-ill2VRfJKMjctRXeuE-ehTpJ3LKt8dio,2809
30
- cfn_check-0.3.1.dist-info/METADATA,sha256=GEq5W-bVyzD0gVulqugwSnoDFl1wWjDL3sIPoef-HQ0,19039
31
- cfn_check-0.3.1.dist-info/WHEEL,sha256=zaaOINJESkSfm_4HQVc5ssNzHCPXhJm0kEUakpsEHaU,91
32
- cfn_check-0.3.1.dist-info/entry_points.txt,sha256=B4lCHoDHmwisABxKgRLShwqqFv7QwwDAFXoAChOnkwg,53
33
- cfn_check-0.3.1.dist-info/top_level.txt,sha256=hUn9Ya50yY1fpgWxEhG5iMgfMDDVX7qWQnM1xrgZnhM,18
34
- cfn_check-0.3.1.dist-info/RECORD,,
28
+ cfn_check-0.3.2.dist-info/licenses/LICENSE,sha256=EbCpGNzOkyQ53ig7J2Iwgmy4Og0dgHe8COo3WylhIKk,1069
29
+ example/rules.py,sha256=mWHB0DK283lb0CeSHgnyO5qiVTJJpybuwWXb4Yoa3zQ,3148
30
+ cfn_check-0.3.2.dist-info/METADATA,sha256=aAqR3dS-h4J_kHL4K6vCtl2DSFgYvOCHps_PvoraX5Q,19047
31
+ cfn_check-0.3.2.dist-info/WHEEL,sha256=zaaOINJESkSfm_4HQVc5ssNzHCPXhJm0kEUakpsEHaU,91
32
+ cfn_check-0.3.2.dist-info/entry_points.txt,sha256=B4lCHoDHmwisABxKgRLShwqqFv7QwwDAFXoAChOnkwg,53
33
+ cfn_check-0.3.2.dist-info/top_level.txt,sha256=hUn9Ya50yY1fpgWxEhG5iMgfMDDVX7qWQnM1xrgZnhM,18
34
+ cfn_check-0.3.2.dist-info/RECORD,,
example/rules.py CHANGED
@@ -41,7 +41,7 @@ class ResourcesChecks(Collection):
41
41
  "Resources::SecurityGroup::Properties::(SecurityGroup)::[]",
42
42
  "It checks Security Groups are correctly definined",
43
43
  )
44
- def validate_test(self, value: list[dict]):
44
+ def validate_security_groups(self, value: list[dict]):
45
45
  assert len(value) > 0
46
46
 
47
47
  for item in value:
@@ -68,4 +68,13 @@ class ResourcesChecks(Collection):
68
68
  def validate_lambda_code_zipfile(self, value: list[str]):
69
69
  assert value is not None, '❌ Lambda zipfile code is not defined'
70
70
  assert isinstance(value, list), '❌ Lambda execution zipfile code not a list'
71
- assert len(value) > 0,'❌ Lambda execution zipfile code empty'
71
+ assert len(value) > 0,'❌ Lambda execution zipfile code empty'
72
+
73
+ @Rule(
74
+ "Resources::SecurityGroup::Properties::(SecurityGroup)::[IpProtocol]",
75
+ "It checks Security Groups IpProtocols are tcp",
76
+ )
77
+ def validate_ip_protocols(self, ip_protocol: str):
78
+ assert ip_protocol is not None
79
+ assert isinstance(ip_protocol, str)
80
+ assert ip_protocol == "tcp"