Skip to content

Commit b761f7f

Browse files
committed
pylint fixes continued
1 parent a9c673f commit b761f7f

File tree

3 files changed

+38
-21
lines changed

3 files changed

+38
-21
lines changed

src/bulk_importer/main.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@
3131

3232
#config = None
3333

34-
def get_certificate(certificateId):
34+
def get_certificate(certificate_id):
3535
"""Verify that the certificate is in IoT Core"""
3636
iot_client = boto3client('iot')
3737
try:
38-
response = iot_client.describe_certificate(certificateId=certificateId)
38+
response = iot_client.describe_certificate(certificateId=certificate_id)
3939
return response["certificateDescription"].get("certificateId")
4040
except ClientError as error:
4141
assert error.response['Error']['Code'] == 'ResourceNotFoundException'
@@ -144,7 +144,7 @@ def process_thing(thing_name, certificate_id, thing_type_name):
144144
print(error)
145145
return None
146146

147-
def requeue():
147+
def requeue(config):
148148
"""
149149
Requeues the message for processing in case of unrecoverable error such
150150
as throttling. The structure is:
@@ -199,35 +199,40 @@ def process_certificate(config, requeue_cb):
199199
return None
200200

201201
def process_thing_group(thing_group_name, thing_name):
202+
"""Attaches the configured thing group to the iot thing"""
202203
iot_client = boto3client('iot')
203204
try:
204205
thing_group_arn = get_thing_group(thing_group_name)
205206
thing_arn = get_thing(thing_name)
206-
207207
iot_client.add_thing_to_thing_group(thingGroupName=thing_group_name,
208208
thingGroupArn=thing_group_arn,
209209
thingName=thing_name,
210210
thingArn=thing_arn,
211211
overrideDynamicGroups=False)
212-
except Exception as e:
213-
print(e)
214-
return None
212+
except ClientError as error:
213+
print(error)
214+
215+
return None
215216

216217
def get_name_from_certificate(certificate_id):
218+
"""Assume the certificate cn is the thing name.
219+
TODO: Evaluate for deprecation, thing name identifier better
220+
evaluated in the vendor specific provider.
221+
"""
217222
iot_client = boto3client('iot')
218223
response = iot_client.describe_certificate(certificateId=certificate_id)
219224
certificate_text = response["certificateDescription"].get("certificatePem")
220225
certificate_obj = x509.load_pem_x509_certificate(data=certificate_text.encode('ascii'),
221226
backend=default_backend())
222227
cn = certificate_obj.subject.get_attributes_for_oid(NameOID.COMMON_NAME)[0].value
223228
cn.replace(" ", "")
224-
# TODO: This must be really old because thing name is prescribed to the
229+
# TODO: This must be really old because thing name is prescribed to the
225230
# sqs message from the beginning, this might be eliminated
226231
logger.info("Certificate common name [%s] to be IoT Thing name", cn)
227232
return cn
228233

229234
def process_sqs(config):
230-
certificate = config.get('certificate')
235+
"""Main processing function to procedurally run through processing steps."""
231236
policy_name = config.get('policy_name')
232237
thing_group_name = config.get('thing_group_name')
233238
thing_type_name = config.get('thing_type_name')
@@ -244,6 +249,7 @@ def process_sqs(config):
244249
process_thing_group(thing_group_name, thing_name)
245250

246251
def lambda_handler(event, context):
252+
"""Lambda function main entry point"""
247253
if event.get('Records') is None:
248254
print("ERROR: Configuration incorrect: no event record on invoke")
249255
return {

test/unit/src/test_bulk_importer.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
1+
"""
2+
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
# SPDX-License-Identifier: MIT-0
4+
5+
Unit tests for bulk_importer
6+
"""
17
import sys
28
import os
3-
import io
9+
#import io
10+
from unittest import TestCase
11+
#from unittest.mock import MagicMock, patch
412
import pytest
513

614
import botocore
@@ -11,8 +19,6 @@
1119

1220
from aws_lambda_powertools.utilities.validation import validate
1321

14-
from unittest import TestCase
15-
from unittest.mock import MagicMock, patch
1622
sys.path.append('./src/bulk_importer')
1723
os.environ['AWS_DEFAULT_REGION'] = "us-east-1"
1824
from src.bulk_importer.testable import LambdaSQSClass # pylint: disable=wrong-import-position

test/unit/src/test_provider_infineon.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,27 @@
1+
"""
2+
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
# SPDX-License-Identifier: MIT-0
4+
5+
Unit tests for provider_infineon
6+
"""
17
import sys
28
import os
39
import io
10+
from unittest import TestCase
411
import pytest
512

613
import botocore
7-
814
from boto3 import resource, client
9-
from moto import mock_aws, settings
10-
from aws_lambda_powertools.utilities.validation import validate
15+
from moto import mock_aws
16+
#from moto import mock_aws, settings
17+
#from aws_lambda_powertools.utilities.validation import validate
1118

12-
from unittest import TestCase
13-
from unittest.mock import MagicMock, patch
19+
#from unittest.mock import MagicMock, patch
1420
sys.path.append('./src/provider_infineon')
1521
os.environ['AWS_DEFAULT_REGION'] = "us-east-1"
16-
from src.provider_infineon.testable import LambdaS3Class, LambdaSQSClass # pylint: disable=wrong-import-position
17-
from src.provider_infineon.main import lambda_handler, s3_filebuf_bytes, invoke_export # pylint: disable=wrong-import-position
18-
from src.provider_infineon.main import s3_object_stream
19-
from src.provider_infineon.schemas import INPUT_SCHEMA # pylint: disable=wrong-import-position
22+
from src.provider_infineon.testable import LambdaS3Class, LambdaSQSClass
23+
from src.provider_infineon.main import lambda_handler, s3_object_stream, s3_filebuf_bytes, invoke_export
24+
from src.provider_infineon.schemas import INPUT_SCHEMA
2025

2126
@mock_aws(config={
2227
"core": {

0 commit comments

Comments
 (0)