Skip to content

Commit 4f8f5cb

Browse files
committed
Remove backward compatibility for single policy/thing group parameters
- Remove deprecated IoTPolicy and IoTThingGroup CloudFormation parameters - Remove POLICY_NAME and THING_GROUP_NAME environment variables - Simplify product verifier to only use POLICY_NAMES and THING_GROUP_NAMES - Simplify bulk importer to only process multi-value arrays - Update sam-integration-full.toml to use new parameter names - Remove backward compatibility tests and update remaining tests - Fix bug where old TOML files with single naming convention don't work Files changed: - template.yaml: Remove deprecated parameters and env vars - src/product_verifier/main.py: Remove fallback logic - src/bulk_importer/bulk_importer/main.py: Remove legacy processing - configs/sam-integration-full.toml: Use IoTPolicies/IoTThingGroups - test/: Update tests to use new parameter names only Net reduction: 162 lines of backward compatibility code removed
1 parent 57e7a7d commit 4f8f5cb

File tree

6 files changed

+21
-183
lines changed

6 files changed

+21
-183
lines changed

configs/sam-integration-full.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ version = 0.1
22
[default.deploy.parameters]
33
resolve_s3 = true
44
capabilities = "CAPABILITY_IAM"
5-
parameter_overrides = "IamUserArn=\"None\" IoTPolicy=\"BasicTestPolicy\" IoTThingGroup=\"BasicTestGroup\" IoTThingType=\"BasicTestType\" InfineonCertBundleType=\"E0E0\" ConcurrentExecutions=\"10\" DLQRetentionPeriod=\"1209600\" QueueVisibilityTimeout=\"900\" IdempotencyExpirySeconds=\"3600\" AutoThrottlingEnabled=\"true\" ThrottlingBaseDelay=\"30\" ThrottlingBatchInterval=\"3\" MaxQueueDepth=\"1000\" ProviderConcurrencyLimit=\"5\" LambdaMemorySize=\"2048\" LambdaTimeout=\"300\""
5+
parameter_overrides = "IamUserArn=\"None\" IoTPolicies=\"BasicTestPolicy\" IoTThingGroups=\"BasicTestGroup\" IoTThingType=\"BasicTestType\" InfineonCertBundleType=\"E0E0\" ConcurrentExecutions=\"10\" DLQRetentionPeriod=\"1209600\" QueueVisibilityTimeout=\"900\" IdempotencyExpirySeconds=\"3600\" AutoThrottlingEnabled=\"true\" ThrottlingBaseDelay=\"30\" ThrottlingBatchInterval=\"3\" MaxQueueDepth=\"1000\" ProviderConcurrencyLimit=\"5\" LambdaMemorySize=\"2048\" LambdaTimeout=\"300\""
66
image_repositories = []

src/bulk_importer/bulk_importer/main.py

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -115,38 +115,22 @@ def process_sqs(config, session: Session=default_session):
115115
certificate_arn=certificate_arn,
116116
session=session)
117117

118-
# Process multiple policies (backward compatible)
118+
# Process multiple policies
119119
policies = config.get('policies', [])
120-
if policies:
121-
for policy_info in policies:
122-
process_policy(policy_name=policy_info['name'],
123-
certificate_arn=certificate_arn,
124-
session=session)
125-
else:
126-
# Legacy single policy support
127-
policy_name = config.get(ImporterMessageKey.POLICY_NAME.value)
128-
if policy_name:
129-
process_policy(policy_name=policy_name,
130-
certificate_arn=certificate_arn,
131-
session=session)
120+
for policy_info in policies:
121+
process_policy(policy_name=policy_info['name'],
122+
certificate_arn=certificate_arn,
123+
session=session)
132124

133125
thing_arn = get_thing_arn(config.get(ImporterMessageKey.THING_NAME.value),
134126
session=session)
135127

136-
# Process multiple thing groups (backward compatible)
128+
# Process multiple thing groups
137129
thing_groups = config.get('thing_groups', [])
138-
if thing_groups:
139-
for thing_group_info in thing_groups:
140-
process_thing_group(thing_group_arn=thing_group_info['arn'],
141-
thing_arn=thing_arn,
142-
session=session)
143-
else:
144-
# Legacy single thing group support
145-
thing_group_arn = config.get(ImporterMessageKey.THING_GROUP_ARN.value)
146-
if thing_group_arn:
147-
process_thing_group(thing_group_arn=thing_group_arn,
148-
thing_arn=thing_arn,
149-
session=session)
130+
for thing_group_info in thing_groups:
131+
process_thing_group(thing_group_arn=thing_group_info['arn'],
132+
thing_arn=thing_arn,
133+
session=session)
150134

151135
# Process thing type (singular - AWS IoT allows only one thing type per thing)
152136
thing_type_name = config.get(ImporterMessageKey.THING_TYPE_NAME.value)

src/product_verifier/main.py

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,25 +60,13 @@ def lambda_handler(event,
6060
6161
Expects the following environment variables to be set:
6262
QUEUE_TARGET_ESPRESSIF, QUEUE_TARGET_INFINEON, QUEUE_TARGET_MICROCHIP, QUEUE_TARGET_GENERATED
63-
64-
Supports both new multi-value and legacy single-value parameters:
65-
New: POLICY_NAMES, THING_GROUP_NAMES (comma-delimited)
66-
Legacy: POLICY_NAME, THING_GROUP_NAME (single values)
67-
Thing Type: THING_TYPE_NAME (always singular - AWS IoT limitation)
63+
POLICY_NAMES, THING_GROUP_NAMES (comma-delimited), THING_TYPE_NAME
6864
"""
6965
config = {}
7066

71-
# Try new multi-value parameters first, fall back to legacy
67+
# Get multi-value parameters
7268
e_policies = os.environ.get('POLICY_NAMES', '')
7369
e_thing_groups = os.environ.get('THING_GROUP_NAMES', '')
74-
75-
# Backward compatibility: if new params empty, try legacy
76-
if not e_policies:
77-
e_policies = os.environ.get('POLICY_NAME', '')
78-
if not e_thing_groups:
79-
e_thing_groups = os.environ.get('THING_GROUP_NAME', '')
80-
81-
# Thing type is always singular (AWS IoT limitation: one thing type per thing)
8270
e_thing_type = os.environ.get('THING_TYPE_NAME', '')
8371

8472
# Handle both raw dict and S3Event object formats

template.yaml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,12 @@ Parameters:
3434
manifests.
3535
Type: String
3636

37-
IoTPolicy:
38-
Default: None
39-
Type: String
40-
Description: (DEPRECATED - Use IoTPolicies) Single AWS IoT Policy for backward compatibility.
41-
4237
IoTPolicies:
4338
Default: None
4439
Type: CommaDelimitedList
4540
Description: Comma-separated list of AWS IoT Policies to apply to certificates.
4641
Use 'None' for no policies. Example policy1,policy2,policy3
4742

48-
IoTThingGroup:
49-
Default: None
50-
Type: String
51-
Description: (DEPRECATED - Use IoTThingGroups) Single Thing Group for backward compatibility.
52-
5343
IoTThingGroups:
5444
Default: None
5545
Type: CommaDelimitedList
@@ -388,8 +378,6 @@ Resources:
388378
QUEUE_TARGET_GENERATED: !Ref ThingpressGeneratedProviderQueue
389379
POLICY_NAMES: !Join [',', !Ref IoTPolicies]
390380
THING_GROUP_NAMES: !Join [',', !Ref IoTThingGroups]
391-
POLICY_NAME: !Ref IoTPolicy
392-
THING_GROUP_NAME: !Ref IoTThingGroup
393381
THING_TYPE_NAME: !Ref IoTThingType
394382
Events:
395383
EV1:

test/integration/end_to_end/e2e_test_framework.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -613,26 +613,19 @@ def _get_expected_config_from_stack(self) -> dict:
613613
param_key = param['ParameterKey']
614614
param_value = param['ParameterValue']
615615

616-
# Handle new multi-value parameters (comma-delimited)
616+
# Handle multi-value parameters (comma-delimited)
617617
if param_key == 'IoTPolicies' and param_value and param_value != 'None':
618618
expected_config['policies'] = [
619619
p.strip() for p in param_value.split(',')
620620
if p.strip() and p.strip() != 'None'
621621
]
622-
# Handle legacy single-value parameter (backward compatibility)
623-
elif param_key == 'IoTPolicy' and param_value and param_value != 'None':
624-
if not expected_config['policies']: # Only use if multi-value not set
625-
expected_config['policies'] = [param_value]
626622

627623
# Handle thing groups
628624
elif param_key == 'IoTThingGroups' and param_value and param_value != 'None':
629625
expected_config['thing_groups'] = [
630626
g.strip() for g in param_value.split(',')
631627
if g.strip() and g.strip() != 'None'
632628
]
633-
elif param_key == 'IoTThingGroup' and param_value and param_value != 'None':
634-
if not expected_config['thing_groups']:
635-
expected_config['thing_groups'] = [param_value]
636629

637630
# Handle thing type (singular - AWS IoT allows only one thing type per thing)
638631
elif param_key == 'IoTThingType' and param_value and param_value != 'None':

test/unit/test_product_verifier.py

Lines changed: 7 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,8 @@ def test_pos_invoke_export(self):
153153
""" The number of items in the queue should be 7 since there are
154154
seven certificates in the test file """
155155

156-
os.environ['POLICY_NAME'] = 'dev_policy'
157-
os.environ['THING_GROUP_NAME'] = "None"
156+
os.environ['POLICY_NAMES'] = 'dev_policy'
157+
os.environ['THING_GROUP_NAMES'] = "None"
158158
os.environ['THING_TYPE_NAME'] = "None"
159159
os.environ['QUEUE_TARGET_ESPRESSIF'] = self.env_queue_target_espressif
160160

@@ -212,8 +212,8 @@ def test_neg_invoke_export(self):
212212
""" The number of items in the queue should be 7 since there are
213213
seven certificates in the test file """
214214

215-
os.environ['POLICY_NAME'] = 'dev_policy'
216-
os.environ['THING_GROUP_NAME'] = "None"
215+
os.environ['POLICY_NAMES'] = 'dev_policy'
216+
os.environ['THING_GROUP_NAMES'] = "None"
217217
os.environ['THING_TYPE_NAME'] = "None"
218218
os.environ['QUEUE_TARGET_ESPRESSIF'] = self.env_queue_target_espressif
219219
reset_circuit('iot_get_policy')
@@ -265,9 +265,7 @@ def test_neg_invoke_export(self):
265265
def tearDown(self):
266266
# Clean up environment variables to prevent test pollution
267267
env_vars_to_clear = [
268-
'POLICY_NAME', 'POLICY_NAMES',
269-
'THING_GROUP_NAME', 'THING_GROUP_NAMES',
270-
'THING_TYPE_NAME',
268+
'POLICY_NAMES', 'THING_GROUP_NAMES', 'THING_TYPE_NAME',
271269
'QUEUE_TARGET_ESPRESSIF', 'QUEUE_TARGET_INFINEON',
272270
'QUEUE_TARGET_MICROCHIP', 'QUEUE_TARGET_GENERATED'
273271
]
@@ -310,8 +308,8 @@ def tearDown(self):
310308
pass
311309
def test_pos_lambda_handler_generated(self):
312310
"""Test the lambda handler with a generated certificates file"""
313-
os.environ['POLICY_NAME'] = self.env_policy_name_pos
314-
os.environ['THING_GROUP_NAME'] = self.env_thing_group_name_pos
311+
os.environ['POLICY_NAMES'] = self.env_policy_name_pos
312+
os.environ['THING_GROUP_NAMES'] = self.env_thing_group_name_pos
315313
os.environ['THING_TYPE_NAME'] = self.env_thing_type_name_pos
316314
os.environ['QUEUE_TARGET_GENERATED'] = self.env_queue_target_generated
317315

@@ -569,116 +567,3 @@ def test_lambda_handler_multiple_thing_groups(self):
569567
group_names = [g['name'] for g in message_body['thing_groups']]
570568
self.assertIn('test-group-1', group_names)
571569
self.assertIn('test-group-2', group_names)
572-
573-
def test_lambda_handler_backward_compatibility(self):
574-
"""Test backward compatibility with legacy single-value parameters"""
575-
reset_circuit('iot_get_policy')
576-
reset_circuit('iot_get_thing_group')
577-
578-
# Setup
579-
iot_client = self.session.client('iot')
580-
sqs_client = self.session.client('sqs')
581-
s3_client = self.session.client('s3')
582-
583-
# Create single policy and thing group
584-
iot_client.create_policy(policyName='legacy-policy', policyDocument=json.dumps(self.IOT_POLICY))
585-
iot_client.create_thing_group(thingGroupName='legacy-group')
586-
587-
# Set ONLY legacy environment variables (new ones empty)
588-
os.environ['POLICY_NAMES'] = ''
589-
os.environ['THING_GROUP_NAMES'] = ''
590-
os.environ['POLICY_NAME'] = 'legacy-policy'
591-
os.environ['THING_GROUP_NAME'] = 'legacy-group'
592-
os.environ['THING_TYPE_NAME'] = 'None'
593-
os.environ['QUEUE_TARGET_GENERATED'] = self.env_queue_target_generated
594-
595-
# Create S3 bucket and upload object
596-
s3_client.create_bucket(Bucket=self.bucket_generated_pos)
597-
s3_client.put_object(Bucket=self.bucket_generated_pos, Key=self.obj_generated, Body=b'test')
598-
599-
# Create SQS queue
600-
sqs_client.create_queue(QueueName=self.env_queue_target_generated)
601-
602-
# Create S3 event
603-
s3_event = {
604-
"Records": [{
605-
"eventSource": "aws:s3",
606-
"s3": {
607-
"bucket": {"name": self.bucket_generated_pos},
608-
"object": {"key": self.obj_generated}
609-
}
610-
}]
611-
}
612-
613-
# Execute
614-
result = lambda_handler(S3Event(s3_event), LambdaContext())
615-
616-
# Verify message sent to SQS
617-
queue_url = sqs_client.get_queue_url(QueueName=self.env_queue_target_generated)['QueueUrl']
618-
messages = sqs_client.receive_message(QueueUrl=queue_url, MaxNumberOfMessages=10)
619-
620-
self.assertIn('Messages', messages)
621-
message_body = json.loads(messages['Messages'][0]['Body'])
622-
623-
# Verify legacy format works - should have policies list with one item
624-
self.assertIn('policies', message_body)
625-
self.assertEqual(len(message_body['policies']), 1)
626-
self.assertEqual(message_body['policies'][0]['name'], 'legacy-policy')
627-
628-
def test_lambda_handler_mixed_parameters(self):
629-
"""Test mixing new multi-value and legacy single-value parameters"""
630-
reset_circuit('iot_get_policy')
631-
reset_circuit('iot_get_thing_group')
632-
633-
# Setup
634-
iot_client = self.session.client('iot')
635-
sqs_client = self.session.client('sqs')
636-
s3_client = self.session.client('s3')
637-
638-
# Create policies and thing group
639-
iot_client.create_policy(policyName='policy-1', policyDocument=json.dumps(self.IOT_POLICY))
640-
iot_client.create_policy(policyName='policy-2', policyDocument=json.dumps(self.IOT_POLICY))
641-
iot_client.create_thing_group(thingGroupName='legacy-group')
642-
643-
# New multi-value for policies, legacy for thing group
644-
os.environ['POLICY_NAMES'] = 'policy-1,policy-2'
645-
os.environ['THING_GROUP_NAMES'] = ''
646-
os.environ['THING_GROUP_NAME'] = 'legacy-group'
647-
os.environ['QUEUE_TARGET_GENERATED'] = self.env_queue_target_generated
648-
649-
# Create S3 bucket and upload object
650-
s3_client.create_bucket(Bucket=self.bucket_generated_pos)
651-
s3_client.put_object(Bucket=self.bucket_generated_pos, Key=self.obj_generated, Body=b'test')
652-
653-
# Create SQS queue
654-
sqs_client.create_queue(QueueName=self.env_queue_target_generated)
655-
656-
# Create S3 event
657-
s3_event = {
658-
"Records": [{
659-
"eventSource": "aws:s3",
660-
"s3": {
661-
"bucket": {"name": self.bucket_generated_pos},
662-
"object": {"key": self.obj_generated}
663-
}
664-
}]
665-
}
666-
667-
# Execute
668-
result = lambda_handler(S3Event(s3_event), LambdaContext())
669-
670-
# Verify message sent to SQS
671-
queue_url = sqs_client.get_queue_url(QueueName=self.env_queue_target_generated)['QueueUrl']
672-
messages = sqs_client.receive_message(QueueUrl=queue_url, MaxNumberOfMessages=10)
673-
674-
self.assertIn('Messages', messages)
675-
message_body = json.loads(messages['Messages'][0]['Body'])
676-
677-
# Verify new policies used
678-
self.assertIn('policies', message_body)
679-
self.assertEqual(len(message_body['policies']), 2)
680-
681-
# Verify legacy thing group used
682-
self.assertIn('thing_groups', message_body)
683-
self.assertEqual(len(message_body['thing_groups']), 1)
684-
self.assertEqual(message_body['thing_groups'][0]['name'], 'legacy-group')

0 commit comments

Comments
 (0)