Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/nrfcloud_utils/claim_and_provision_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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...")
Expand Down
2 changes: 1 addition & 1 deletion src/nrfcloud_utils/claim_devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down
2 changes: 1 addition & 1 deletion src/nrfcloud_utils/cli_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}]")
Comment on lines +65 to 66
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

write_file catches OSError and raises a new RuntimeError without explicitly chaining the original exception. While Python will still attach context, using except OSError as e: ... raise RuntimeError(...) from e makes the causal relationship explicit and keeps the original errno/message easy to find in tracebacks.

Copilot uses AI. Check for mistakes.

full_path = path.join(pathname, filename)
Expand Down
5 changes: 0 additions & 5 deletions src/nrfcloud_utils/create_device_credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions src/nrfcloud_utils/device_credentials_installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions src/nrfcloud_utils/gather_attestation_tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions src/nrfcloud_utils/modem_credentials_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

import argparse
import sys
from os import path
from os import makedirs
from cbor2 import loads
import base64
import hashlib
Expand Down
2 changes: 1 addition & 1 deletion src/nrfcloud_utils/nrf_cloud_diap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
Expand Down
4 changes: 1 addition & 3 deletions src/nrfcloud_utils/nrf_cloud_onboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In check_file_path, the except OSError: branch logs a generic message and drops the underlying exception details. Consider using logger.exception(...) or logger.error(..., exc_info=True) so permission/path issues include the original OSError/traceback in logs.

Suggested change
logger.error("Error creating file path: " + path)
logger.exception("Error creating file path: %s", path)

Copilot uses AI. Check for mistakes.
return ''

Expand Down
5 changes: 1 addition & 4 deletions tests/test_claim_and_provision_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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()
Expand Down
2 changes: 0 additions & 2 deletions tests/test_create_ca_cert.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions tests/test_create_device_credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions tests/test_device_credentials_installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions tests/test_gather_attestation_tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions tests/test_modem_credentials_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading