diff --git a/src/nrfcloud_utils/claim_and_provision_device.py b/src/nrfcloud_utils/claim_and_provision_device.py index ecebc88..500621a 100644 --- a/src/nrfcloud_utils/claim_and_provision_device.py +++ b/src/nrfcloud_utils/claim_and_provision_device.py @@ -15,8 +15,8 @@ nrf_cloud_diap, create_device_credentials ) -from nrfcloud_utils.cli_helpers import is_linux, is_windows, is_macos, setup_logging -from nrfcloud_utils.cli_helpers import CMD_TERM_DICT, CMD_TYPE_AUTO, CMD_TYPE_AT, CMD_TYPE_AT_SHELL, CMD_TYPE_TLS_SHELL, parser_add_comms_args +from nrfcloud_utils.cli_helpers import setup_logging +from nrfcloud_utils.cli_helpers import CMD_TERM_DICT, CMD_TYPE_AUTO, CMD_TYPE_AT, CMD_TYPE_AT_SHELL, parser_add_comms_args from cryptography import x509 from cryptography.hazmat.primitives import serialization from nrfcredstore.comms import Comms @@ -129,7 +129,7 @@ def main(in_args): error_exit(f'Device ID must not exceed {DEV_ID_MAX_LEN} characters') if 'CN=' in args.csr_attr: - error_exit(f'Do not include CN in --csr_attr. The device ID will be used as the CN') + error_exit('Do not include CN in --csr_attr. The device ID will be used as the CN') # load local CA cert and key if needed; assume not needed if using provisioning tags if args.provisioning_tags is None: @@ -192,7 +192,7 @@ def main(in_args): logger.info(f'Unclaiming device {dev_uuid}...') api_res = nrf_cloud_diap.unclaim_device(args.api_key, dev_uuid) if api_res.status_code == 204: - logger.info(f'...success') + logger.info('...success') else: nrf_cloud_diap.print_api_result("Unclaim device response", api_res) logger.info("Device may not have been claimed before, continuing...") diff --git a/src/nrfcloud_utils/claim_devices.py b/src/nrfcloud_utils/claim_devices.py index ba9f97c..45408d8 100644 --- a/src/nrfcloud_utils/claim_devices.py +++ b/src/nrfcloud_utils/claim_devices.py @@ -9,7 +9,7 @@ import argparse import logging from nrfcloud_utils import nrf_cloud_diap -from nrfcloud_utils.cli_helpers import is_linux, is_windows, is_macos, setup_logging +from nrfcloud_utils.cli_helpers import setup_logging logger = logging.getLogger(__name__) diff --git a/src/nrfcloud_utils/cli_helpers.py b/src/nrfcloud_utils/cli_helpers.py index 93018c7..9ea5dbe 100644 --- a/src/nrfcloud_utils/cli_helpers.py +++ b/src/nrfcloud_utils/cli_helpers.py @@ -62,7 +62,7 @@ def write_file(pathname, filename, bytes): if not path.isdir(pathname): try: makedirs(pathname, exist_ok=True) - except OSError as e: + except OSError: raise RuntimeError(f"Error creating file path [{pathname}]") full_path = path.join(pathname, filename) diff --git a/src/nrfcloud_utils/create_device_credentials.py b/src/nrfcloud_utils/create_device_credentials.py index 4c3a883..0c3d7d9 100644 --- a/src/nrfcloud_utils/create_device_credentials.py +++ b/src/nrfcloud_utils/create_device_credentials.py @@ -15,12 +15,7 @@ from cryptography import x509 import uuid from cryptography.x509 import ( - Name, - NameAttribute, - BasicConstraints, KeyUsage, - AuthorityKeyIdentifier, - SubjectKeyIdentifier, ) from nrfcloud_utils.cli_helpers import write_file, save_onboarding_csv, setup_logging diff --git a/src/nrfcloud_utils/device_credentials_installer.py b/src/nrfcloud_utils/device_credentials_installer.py index 2379b0f..17ee4a2 100644 --- a/src/nrfcloud_utils/device_credentials_installer.py +++ b/src/nrfcloud_utils/device_credentials_installer.py @@ -12,7 +12,7 @@ import semver import logging from nrfcloud_utils import create_device_credentials, ca_certs, modem_credentials_parser -from nrfcloud_utils.cli_helpers import write_file, save_devinfo_csv, save_onboarding_csv, is_linux, is_windows, is_macos, full_encoding, setup_logging +from nrfcloud_utils.cli_helpers import write_file, save_devinfo_csv, save_onboarding_csv, full_encoding, setup_logging from nrfcloud_utils.cli_helpers import CMD_TERM_DICT, CMD_TYPE_AUTO, CMD_TYPE_AT, CMD_TYPE_AT_SHELL, CMD_TYPE_TLS_SHELL, parser_add_comms_args from nrfcredstore.command_interface import ATCommandInterface, TLSCredShellInterface from nrfcredstore.comms import Comms @@ -377,30 +377,30 @@ def main(in_args): # write CA cert(s) to device nrf_ca_cert_text = format_cred(ca_certs.get_ca_certs(args.coap, stage=args.stage)) - logger.info(f'Writing CA cert(s) to device...') + logger.info('Writing CA cert(s) to device...') try: cred_if.write_credential(args.sectag, 0, nrf_ca_cert_text) except Exception as e: - logger.error(f'Failed to write CA certificate to device') + logger.error('Failed to write CA certificate to device') logger.debug(f'Error details: {e}') raise # write dev cert to device - logger.info(f'Writing dev cert to device...') + logger.info('Writing dev cert to device...') try: cred_if.write_credential(args.sectag, 1, dev_text) except Exception as e: - logger.error(f'Failed to write device certificate to device') + logger.error('Failed to write device certificate to device') logger.debug(f'Error details: {e}') raise # If the private key was locally generated, write it to the device if prv_text is not None: - logger.info(f'Writing private key to device...') + logger.info('Writing private key to device...') try: cred_if.write_credential(args.sectag, 2, prv_text) except Exception as e: - logger.error(f'Failed to write private key to device') + logger.error('Failed to write private key to device') logger.debug(f'Error details: {e}') raise diff --git a/src/nrfcloud_utils/gather_attestation_tokens.py b/src/nrfcloud_utils/gather_attestation_tokens.py index 3c96221..f40e52c 100644 --- a/src/nrfcloud_utils/gather_attestation_tokens.py +++ b/src/nrfcloud_utils/gather_attestation_tokens.py @@ -8,8 +8,8 @@ import csv import argparse from nrfcloud_utils import modem_credentials_parser -from nrfcloud_utils.cli_helpers import is_linux, is_windows, is_macos, setup_logging -from nrfcloud_utils.cli_helpers import CMD_TERM_DICT, CMD_TYPE_AUTO, CMD_TYPE_AT, CMD_TYPE_AT_SHELL, CMD_TYPE_TLS_SHELL, parser_add_comms_args +from nrfcloud_utils.cli_helpers import setup_logging +from nrfcloud_utils.cli_helpers import CMD_TERM_DICT, CMD_TYPE_AUTO, CMD_TYPE_AT, CMD_TYPE_AT_SHELL, parser_add_comms_args from nrfcredstore.comms import Comms from nrfcredstore.command_interface import ATCommandInterface from datetime import datetime, timezone diff --git a/src/nrfcloud_utils/modem_credentials_parser.py b/src/nrfcloud_utils/modem_credentials_parser.py index 1ef52d8..7ee7870 100644 --- a/src/nrfcloud_utils/modem_credentials_parser.py +++ b/src/nrfcloud_utils/modem_credentials_parser.py @@ -6,8 +6,6 @@ import argparse import sys -from os import path -from os import makedirs from cbor2 import loads import base64 import hashlib diff --git a/src/nrfcloud_utils/nrf_cloud_diap.py b/src/nrfcloud_utils/nrf_cloud_diap.py index 98333af..fd9a77f 100644 --- a/src/nrfcloud_utils/nrf_cloud_diap.py +++ b/src/nrfcloud_utils/nrf_cloud_diap.py @@ -5,7 +5,7 @@ # SPDX-License-Identifier: BSD-3-Clause import requests -import coloredlogs, logging +import logging from nrfcloud_utils import ca_certs DEV_STAGE_DICT = {'dev': '.dev.', diff --git a/src/nrfcloud_utils/nrf_cloud_onboard.py b/src/nrfcloud_utils/nrf_cloud_onboard.py index fb18ad8..5572685 100644 --- a/src/nrfcloud_utils/nrf_cloud_onboard.py +++ b/src/nrfcloud_utils/nrf_cloud_onboard.py @@ -13,9 +13,7 @@ import os import io import logging -from os import path from os import makedirs -from ast import literal_eval from enum import Enum from nrfcloud_utils.cli_helpers import write_file, setup_logging @@ -349,7 +347,7 @@ def check_file_path(file): if not os.path.exists(path): try: makedirs(path, exist_ok=True) - except OSError as e: + except OSError: logger.error("Error creating file path: " + path) return '' diff --git a/tests/test_claim_and_provision_device.py b/tests/test_claim_and_provision_device.py index b945ce2..32a77cc 100644 --- a/tests/test_claim_and_provision_device.py +++ b/tests/test_claim_and_provision_device.py @@ -3,10 +3,7 @@ """ from unittest.mock import patch, Mock -from serial import Serial -import pytest from nrfcloud_utils import claim_and_provision_device -from tempfile import TemporaryDirectory from requests import Response from collections import namedtuple @@ -46,7 +43,7 @@ class TestClaimAndProvisionDevice: def test_provisioning_tags(self, ser, select_device, diap): diap.claim_device = Mock(return_value=TEST_RESPONSE) diap.can_device_be_claimed = Mock(return_value=(True, "")) - args = f"--port /not/a/real/device --cmd-type at --api-key NOTAKEY --provisioning-tags nrf-cloud-onboarding".split() + args = "--port /not/a/real/device --cmd-type at --api-key NOTAKEY --provisioning-tags nrf-cloud-onboarding".split() # call DUT claim_and_provision_device.main(args) diap.claim_device.assert_called_once() diff --git a/tests/test_create_ca_cert.py b/tests/test_create_ca_cert.py index 335a127..15ece41 100644 --- a/tests/test_create_ca_cert.py +++ b/tests/test_create_ca_cert.py @@ -2,9 +2,7 @@ Test for create_ca_cert.py """ -import pytest -from unittest.mock import Mock from nrfcloud_utils import create_ca_cert from tempfile import TemporaryDirectory from cryptography.hazmat.primitives import serialization diff --git a/tests/test_create_device_credentials.py b/tests/test_create_device_credentials.py index bbe05b9..6479c2d 100644 --- a/tests/test_create_device_credentials.py +++ b/tests/test_create_device_credentials.py @@ -2,9 +2,7 @@ Test for create_device_credentials.py """ -import pytest -from unittest.mock import Mock from nrfcloud_utils import create_device_credentials from tempfile import TemporaryDirectory from cryptography.hazmat.primitives import serialization diff --git a/tests/test_device_credentials_installer.py b/tests/test_device_credentials_installer.py index 3e44b2f..91a4c59 100644 --- a/tests/test_device_credentials_installer.py +++ b/tests/test_device_credentials_installer.py @@ -3,8 +3,6 @@ """ from unittest.mock import patch, Mock -from serial import Serial -import pytest from nrfcloud_utils import device_credentials_installer from tempfile import TemporaryDirectory import os diff --git a/tests/test_gather_attestation_tokens.py b/tests/test_gather_attestation_tokens.py index dc85517..6e8b9f6 100644 --- a/tests/test_gather_attestation_tokens.py +++ b/tests/test_gather_attestation_tokens.py @@ -3,8 +3,6 @@ """ from unittest.mock import patch, Mock -from serial import Serial -import pytest from nrfcloud_utils import gather_attestation_tokens from tempfile import TemporaryDirectory import os diff --git a/tests/test_modem_credentials_parser.py b/tests/test_modem_credentials_parser.py index 7c23fee..956bf8e 100644 --- a/tests/test_modem_credentials_parser.py +++ b/tests/test_modem_credentials_parser.py @@ -3,9 +3,7 @@ """ -import pytest -from unittest.mock import Mock from nrfcloud_utils import modem_credentials_parser KEYGEN_CSR = "MIIBCjCBrwIBADAvMS0wKwYDVQQDDCQ1MDM2MzE1NC0zOTMxLTQ0ZjAtODAyMi0xMjFiNjQwMTYyN2QwWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAAQqD6pNfa29o_EXnw62bnQWr8-JqsNh_HZxS3k3bMD4KZ8-qxnvgeoiqQ5zAycEP_Wcmzqypvwyf3qWMrZ2VB5aoB4wHAYJKoZIhvcNAQkOMQ8wDTALBgNVHQ8EBAMCA-gwDAYIKoZIzj0EAwIFAANIADBFAiEAv7OLZ_dXbszfhhjcLMUT72wTmw-z6GlgWxVhyWgR27ACIAvY_lPu3yfYZY5AL6uYTkUFp4GQkbSOUC_lsHyCxOuG.0oRDoQEmoQRBIVhL2dn3hQlQUDYxVDkxRPCAIhIbZAFifUERWCBwKj1W8FsvclMdZQgl4gBB4unZMYw0toU6uQZuXHLoDFAbhyLuHetYFWbiyxNZsnzSWEDUiTl7wwFt0hEsCiEQsxj-hCtpBk8Za8UXfdAycpx2faCOPJIrkfmiSS8-Y6_2tTAoAMN1BiWiTOimY1wZE3Ud"