Skip to content

Commit 4745e79

Browse files
committed
tools: provision: detect conflict in cloud and CLI ID
Detect conflicts between the ID a board is already provisioned with on the cloud and the ID the user provides on the command line. Signed-off-by: Jordan Yates <jordan@embeint.com>
1 parent 30edfc8 commit 4745e79

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

src/infuse_iot/tools/provision.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ def add_parser(cls, parser):
6565
)
6666

6767
def __init__(self, args):
68-
self._vendor = args.vendor
69-
self._snr = args.snr
68+
self._vendor: str = args.vendor
69+
self._snr: int | None = args.snr
7070
try:
7171
self._board = UUID(args.board) if args.board else None
7272
except ValueError:
@@ -75,8 +75,8 @@ def __init__(self, args):
7575
self._org = UUID(args.organisation) if args.organisation else None
7676
except ValueError:
7777
sys.exit(f"Organisation ID: '{args.organisation}' is not a valid UUID")
78-
self._id = args.id
79-
self._dry_run = args.dry_run
78+
self._id: int | None = args.id
79+
self._dry_run: bool | None = args.dry_run
8080
self._metadata = {}
8181
if args.metadata:
8282
for meta in args.metadata:
@@ -146,8 +146,15 @@ def run(self):
146146
if response.status_code == HTTPStatus.OK:
147147
# Device found, fall through
148148
assert isinstance(response.parsed, Device)
149+
assert isinstance(response.parsed.device_id, str)
149150
self._org = response.parsed.organisation_id
150151
self._board = response.parsed.board_id
152+
cloud_id = int(response.parsed.device_id, 16)
153+
if self._id and (self._id != cloud_id):
154+
# ID provided on the command line but device already provisioned as another ID
155+
err = f"HW ID 0x{hardware_id:016x} provisioned as 0x{cloud_id:016x} on the cloud"
156+
err += f" but CLI requested 0x{self._id:016x}"
157+
sys.exit(err)
151158
pass
152159
elif response.status_code == HTTPStatus.NOT_FOUND:
153160
# Create new device here

0 commit comments

Comments
 (0)