pyhubblenetwork 0.15.0__tar.gz → 0.16.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. {pyhubblenetwork-0.15.0 → pyhubblenetwork-0.16.0}/PKG-INFO +95 -6
  2. {pyhubblenetwork-0.15.0 → pyhubblenetwork-0.16.0}/README.md +94 -5
  3. {pyhubblenetwork-0.15.0 → pyhubblenetwork-0.16.0}/pyproject.toml +1 -1
  4. {pyhubblenetwork-0.15.0 → pyhubblenetwork-0.16.0}/src/hubblenetwork/__init__.py +4 -1
  5. pyhubblenetwork-0.16.0/src/hubblenetwork/claim.py +68 -0
  6. {pyhubblenetwork-0.15.0 → pyhubblenetwork-0.16.0}/src/hubblenetwork/cli.py +894 -112
  7. {pyhubblenetwork-0.15.0 → pyhubblenetwork-0.16.0}/src/hubblenetwork/cloud.py +193 -6
  8. {pyhubblenetwork-0.15.0 → pyhubblenetwork-0.16.0}/src/hubblenetwork/device.py +3 -0
  9. {pyhubblenetwork-0.15.0 → pyhubblenetwork-0.16.0}/src/hubblenetwork/errors.py +32 -0
  10. pyhubblenetwork-0.16.0/src/hubblenetwork/org.py +736 -0
  11. pyhubblenetwork-0.16.0/tests/test_claims.py +1025 -0
  12. {pyhubblenetwork-0.15.0 → pyhubblenetwork-0.16.0}/tests/test_cli_help_and_errors.py +3 -3
  13. {pyhubblenetwork-0.15.0 → pyhubblenetwork-0.16.0}/tests/test_terminal_compat.py +1 -1
  14. pyhubblenetwork-0.15.0/src/hubblenetwork/org.py +0 -360
  15. {pyhubblenetwork-0.15.0 → pyhubblenetwork-0.16.0}/.gitignore +0 -0
  16. {pyhubblenetwork-0.15.0 → pyhubblenetwork-0.16.0}/LICENSE +0 -0
  17. {pyhubblenetwork-0.15.0 → pyhubblenetwork-0.16.0}/plugins/pyhubblenetwork/skills/hubble-ready-test/README.md +0 -0
  18. {pyhubblenetwork-0.15.0 → pyhubblenetwork-0.16.0}/src/hubblenetwork/ble.py +0 -0
  19. {pyhubblenetwork-0.15.0 → pyhubblenetwork-0.16.0}/src/hubblenetwork/crypto.py +0 -0
  20. {pyhubblenetwork-0.15.0 → pyhubblenetwork-0.16.0}/src/hubblenetwork/detect.py +0 -0
  21. {pyhubblenetwork-0.15.0 → pyhubblenetwork-0.16.0}/src/hubblenetwork/packets.py +0 -0
  22. {pyhubblenetwork-0.15.0 → pyhubblenetwork-0.16.0}/src/hubblenetwork/ready.py +0 -0
  23. {pyhubblenetwork-0.15.0 → pyhubblenetwork-0.16.0}/src/hubblenetwork/sat.py +0 -0
  24. {pyhubblenetwork-0.15.0 → pyhubblenetwork-0.16.0}/src/hubblenetwork/termcaps.py +0 -0
  25. {pyhubblenetwork-0.15.0 → pyhubblenetwork-0.16.0}/src/hubblenetwork/validate.py +0 -0
  26. {pyhubblenetwork-0.15.0 → pyhubblenetwork-0.16.0}/tests/__init__.py +0 -0
  27. {pyhubblenetwork-0.15.0 → pyhubblenetwork-0.16.0}/tests/conftest.py +0 -0
  28. {pyhubblenetwork-0.15.0 → pyhubblenetwork-0.16.0}/tests/fake_packets.py +0 -0
  29. {pyhubblenetwork-0.15.0 → pyhubblenetwork-0.16.0}/tests/test_aes_eax.py +0 -0
  30. {pyhubblenetwork-0.15.0 → pyhubblenetwork-0.16.0}/tests/test_ble_validate.py +0 -0
  31. {pyhubblenetwork-0.15.0 → pyhubblenetwork-0.16.0}/tests/test_cli_ble_decode.py +0 -0
  32. {pyhubblenetwork-0.15.0 → pyhubblenetwork-0.16.0}/tests/test_cli_ctr_autodetect.py +0 -0
  33. {pyhubblenetwork-0.15.0 → pyhubblenetwork-0.16.0}/tests/test_cli_doctor.py +0 -0
  34. {pyhubblenetwork-0.15.0 → pyhubblenetwork-0.16.0}/tests/test_cli_org_display.py +0 -0
  35. {pyhubblenetwork-0.15.0 → pyhubblenetwork-0.16.0}/tests/test_cli_payload.py +0 -0
  36. {pyhubblenetwork-0.15.0 → pyhubblenetwork-0.16.0}/tests/test_cli_scan_display.py +0 -0
  37. {pyhubblenetwork-0.15.0 → pyhubblenetwork-0.16.0}/tests/test_cloud_decode.py +0 -0
  38. {pyhubblenetwork-0.15.0 → pyhubblenetwork-0.16.0}/tests/test_cloud_integration.py +0 -0
  39. {pyhubblenetwork-0.15.0 → pyhubblenetwork-0.16.0}/tests/test_counter_eid.py +0 -0
  40. {pyhubblenetwork-0.15.0 → pyhubblenetwork-0.16.0}/tests/test_detect.py +0 -0
  41. {pyhubblenetwork-0.15.0 → pyhubblenetwork-0.16.0}/tests/test_metrics.py +0 -0
  42. {pyhubblenetwork-0.15.0 → pyhubblenetwork-0.16.0}/tests/test_org_delete_device.py +0 -0
  43. {pyhubblenetwork-0.15.0 → pyhubblenetwork-0.16.0}/tests/test_register_device_cloud.py +0 -0
  44. {pyhubblenetwork-0.15.0 → pyhubblenetwork-0.16.0}/tests/test_register_device_validation.py +0 -0
  45. {pyhubblenetwork-0.15.0 → pyhubblenetwork-0.16.0}/tests/test_sat.py +0 -0
  46. {pyhubblenetwork-0.15.0 → pyhubblenetwork-0.16.0}/tests/test_sat_decrypt.py +0 -0
  47. {pyhubblenetwork-0.15.0 → pyhubblenetwork-0.16.0}/tests/test_sat_integration.py +0 -0
  48. {pyhubblenetwork-0.15.0 → pyhubblenetwork-0.16.0}/tests/test_unencrypted.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: pyhubblenetwork
3
- Version: 0.15.0
3
+ Version: 0.16.0
4
4
  Summary: Hubble SDK host-side tools
5
5
  Author-email: Paul Buckley <paul@hubble.com>
6
6
  License-Expression: Apache-2.0
@@ -86,7 +86,8 @@ not be answered without doing real work (pulling the satellite receiver image, s
86
86
  | See which of my devices are nearby, no key needed | [`ble decode`](#decrypt-nearby-packets-in-the-cloud) |
87
87
  | See what's registered to my org | [`org list-devices`](#work-with-your-fleet-in-the-cloud) |
88
88
  | Read a device's history from the cloud | [`org get-packets <id>`](#work-with-your-fleet-in-the-cloud) |
89
- | Register a new device and get its key | [`org register-device`](#work-with-your-fleet-in-the-cloud) |
89
+ | Register new devices and get their keys | [`org register-device`](#work-with-your-fleet-in-the-cloud) |
90
+ | Make devices claimable by a customer's org | [`claim`](#hand-devices-to-another-org) |
90
91
  | Hear a device's satellite uplink | [`sat scan`](#receive-a-devices-satellite-uplink) |
91
92
  | Capture raw RF for offline analysis | [`sat record`](#one-shot-capture-record--signal-report) |
92
93
 
@@ -96,7 +97,8 @@ Reference: [Reading the output](#reading-the-output) ·
96
97
  [Python library](#using-it-as-a-python-library) ·
97
98
  [Troubleshooting](#troubleshooting)
98
99
 
99
- Commands live in groups — **`org`** (your devices in the Hubble Cloud), **`ble`**
100
+ Commands live in groups — **`org`** (your devices in the Hubble Cloud), **`claim`**
101
+ (hand devices to another org), **`ble`**
100
102
  (nearby devices over Bluetooth), **`sat`** (satellite packets via PlutoSDR) and
101
103
  **`metrics`** (fleet counts) — so it is usually `hubblenetwork <group> <command>`. The
102
104
  two setup commands, `doctor` and `validate-credentials`, sit at the top level.
@@ -236,7 +238,8 @@ hubblenetwork org get-packets <id> # last 7 days by default
236
238
  hubblenetwork org get-packets <id> --days 30 --format csv
237
239
  hubblenetwork org get-packets <id> -n 50 --debug
238
240
 
239
- hubblenetwork org register-device # returns the new device's key
241
+ hubblenetwork org register-device # prints the new device's ID and key
242
+ hubblenetwork org register-device -n 10 -f json
240
243
  hubblenetwork org set-device-name <id> <name>
241
244
  hubblenetwork org delete-device <id>
242
245
  ```
@@ -254,7 +257,64 @@ tabular output when you want the run itself bounded.
254
257
  `register-device` takes `--encryption`, `--counter-source`, and — for AES-128-EAX on
255
258
  `DEVICE_UPTIME` — either `--period-seconds` or `--period-exponent` (period = 2ⁿ
256
259
  seconds; the cloud accepts 10-15, default 15 ≈ 9h). The two period flags are mutually
257
- exclusive.
260
+ exclusive. `-n` registers several devices; more than 1000 go 1000 per request. The
261
+ claim options `--claimable` and `--claim` are under
262
+ [Hand devices to another org](#hand-devices-to-another-org).
263
+
264
+
265
+ ## Hand devices to another org
266
+
267
+ A **claim** moves devices from the org that owns them (typically a manufacturer that
268
+ provisions them at the factory) to another org, with no shared credentials or keys.
269
+ Registering claimable devices is an option on `org register-device`; the `claim`
270
+ group covers the rest of the manufacturer's side, managing the claims. The receiving org redeems a claim on its side, and every linked
271
+ device moves across.
272
+
273
+ ```bash
274
+ # New devices, each in a claim of its own (claim ID = device ID)
275
+ hubblenetwork org register-device -n 10 --claimable
276
+ hubblenetwork org register-device -n 10 --claimable --destination-org <org-id>
277
+
278
+ # Existing devices: one claim for all of them, or one claim each
279
+ hubblenetwork claim create --device <id> --device <id>
280
+ hubblenetwork claim create --device <id> --device <id> --destination-org <org-id>
281
+ hubblenetwork claim create --device <id> --device <id> --per-device
282
+
283
+ # An empty claim to fill later
284
+ hubblenetwork claim create --destination-org <org-id> --name "lot 42"
285
+ hubblenetwork claim link <claim-id> <id> <id>
286
+ hubblenetwork org register-device -n 10 --claim <claim-id>
287
+
288
+ hubblenetwork claim list # claims this org created
289
+ hubblenetwork claim get <claim-id> # status and device count
290
+ hubblenetwork claim get --claim-token "(01)12345678901231(21)ABC123"
291
+ hubblenetwork claim update <claim-id> --directionless
292
+ hubblenetwork claim unlink <id>
293
+ hubblenetwork claim delete <claim-id> # unredeemed claims only
294
+ ```
295
+
296
+ A claim goes `AVAILABLE` → `IN_PROGRESS` → `COMPLETED`, and only an `AVAILABLE` claim
297
+ can be changed, deleted, or have devices linked or unlinked. A completed claim stays as
298
+ a permanent record of the hand-off.
299
+
300
+ * **Directional or directionless.** With `--destination-org`, only that org can redeem
301
+ the claim, so a leaked claim ID is harmless. Without it, whoever presents the claim
302
+ ID first wins it. Use that only when the recipient isn't known yet, and share the ID
303
+ only with them. `claim update` can set or remove the destination later.
304
+ * **Claim tokens.** `--claim-token` adds an alternate ID that you can print on the
305
+ box: a UUID, or a GS1-128 payload using AI `01` (GTIN) and/or `21` (serial). `get`
306
+ accepts it in place of the claim ID.
307
+ * **Entitlement.** Creating claims and linking devices need the
308
+ `can_create_device_claims` entitlement. It is off by default, and Hubble enables it
309
+ per org.
310
+ * **Existing devices.** `claim create --device` links the devices once the claim
311
+ exists. If linking fails, the new claim is deleted again so no empty claim is left
312
+ behind. With `--per-device`, one device failing doesn't stop the rest.
313
+ * **Provisioning.** The cloud registers devices before linking them and doesn't roll
314
+ back. If `org register-device --claim` fails on the link, the devices may exist
315
+ unlinked, and the error says so.
316
+
317
+ `list`, `get`, `create` and `update` take `-f json`, as does `org register-device`.
258
318
 
259
319
 
260
320
  ## Receive a device's satellite uplink
@@ -453,7 +513,7 @@ Import from the package top-level for a stable surface:
453
513
  ```python
454
514
  from hubblenetwork import (
455
515
  ble, cloud, sat,
456
- Organization, Device, Credentials, Environment,
516
+ Organization, Device, DeviceClaim, Credentials, Environment,
457
517
  EncryptedPacket, UnencryptedPacket, AesEaxPacket, UnknownPacket,
458
518
  DecryptedPacket, SatellitePacket, Location,
459
519
  decrypt, decrypt_eax, decrypt_satellite,
@@ -530,6 +590,35 @@ variants — `ble.scan()` / `ble.scan_async()`. The CLI's auto-detection is avai
530
590
  too, in `hubblenetwork.detect`: `CtrCounterModeDetector` / `EaxExponentDetector` are
531
591
  the per-scan objects that own the sweep and its cache.
532
592
 
593
+ Device claims, from the manufacturer's side. Errors are `hubblenetwork.errors`
594
+ types: `NotFoundError` (404, which is also what a claim pinned to another org
595
+ returns), `ConflictError` (409, not `AVAILABLE`), and `PermissionDeniedError` (a
596
+ missing entitlement or scope):
597
+
598
+ ```python
599
+ from hubblenetwork import DeviceClaim
600
+
601
+ # New devices, each claimable on its own (destination_org_id is optional)
602
+ devices = org.register_devices(10, claimable=True, destination_org_id=customer_org_id)
603
+ device = org.register_device(claimable=True) # directionless
604
+
605
+ # Existing devices: one claim for several, or one claim each
606
+ claim: DeviceClaim = org.create_claim(
607
+ destination_org_id=customer_org_id, name="lot 42", device_ids=[d1, d2]
608
+ )
609
+ claims = org.claim_devices([d1, d2]) # {device_id: DeviceClaim}
610
+
611
+ # Manage claims
612
+ org.link_device(existing.id, claim.claim_id) # or unlink_device(id)
613
+ for c in org.iter_claims(status="AVAILABLE"):
614
+ print(c.claim_id, c.status, c.destination_org_id)
615
+ org.update_claim(claim.claim_id, destination_org_id="") # "" clears: directionless
616
+ org.delete_claim(claim.claim_id)
617
+ ```
618
+
619
+ `Device.claim_id` records the claim a newly registered device was put in.
620
+ `update_claim()` takes `None` to leave a field alone and `""` to clear it.
621
+
533
622
  Satellite, which manages the Docker container for you:
534
623
 
535
624
  ```python
@@ -63,7 +63,8 @@ not be answered without doing real work (pulling the satellite receiver image, s
63
63
  | See which of my devices are nearby, no key needed | [`ble decode`](#decrypt-nearby-packets-in-the-cloud) |
64
64
  | See what's registered to my org | [`org list-devices`](#work-with-your-fleet-in-the-cloud) |
65
65
  | Read a device's history from the cloud | [`org get-packets <id>`](#work-with-your-fleet-in-the-cloud) |
66
- | Register a new device and get its key | [`org register-device`](#work-with-your-fleet-in-the-cloud) |
66
+ | Register new devices and get their keys | [`org register-device`](#work-with-your-fleet-in-the-cloud) |
67
+ | Make devices claimable by a customer's org | [`claim`](#hand-devices-to-another-org) |
67
68
  | Hear a device's satellite uplink | [`sat scan`](#receive-a-devices-satellite-uplink) |
68
69
  | Capture raw RF for offline analysis | [`sat record`](#one-shot-capture-record--signal-report) |
69
70
 
@@ -73,7 +74,8 @@ Reference: [Reading the output](#reading-the-output) ·
73
74
  [Python library](#using-it-as-a-python-library) ·
74
75
  [Troubleshooting](#troubleshooting)
75
76
 
76
- Commands live in groups — **`org`** (your devices in the Hubble Cloud), **`ble`**
77
+ Commands live in groups — **`org`** (your devices in the Hubble Cloud), **`claim`**
78
+ (hand devices to another org), **`ble`**
77
79
  (nearby devices over Bluetooth), **`sat`** (satellite packets via PlutoSDR) and
78
80
  **`metrics`** (fleet counts) — so it is usually `hubblenetwork <group> <command>`. The
79
81
  two setup commands, `doctor` and `validate-credentials`, sit at the top level.
@@ -213,7 +215,8 @@ hubblenetwork org get-packets <id> # last 7 days by default
213
215
  hubblenetwork org get-packets <id> --days 30 --format csv
214
216
  hubblenetwork org get-packets <id> -n 50 --debug
215
217
 
216
- hubblenetwork org register-device # returns the new device's key
218
+ hubblenetwork org register-device # prints the new device's ID and key
219
+ hubblenetwork org register-device -n 10 -f json
217
220
  hubblenetwork org set-device-name <id> <name>
218
221
  hubblenetwork org delete-device <id>
219
222
  ```
@@ -231,7 +234,64 @@ tabular output when you want the run itself bounded.
231
234
  `register-device` takes `--encryption`, `--counter-source`, and — for AES-128-EAX on
232
235
  `DEVICE_UPTIME` — either `--period-seconds` or `--period-exponent` (period = 2ⁿ
233
236
  seconds; the cloud accepts 10-15, default 15 ≈ 9h). The two period flags are mutually
234
- exclusive.
237
+ exclusive. `-n` registers several devices; more than 1000 go 1000 per request. The
238
+ claim options `--claimable` and `--claim` are under
239
+ [Hand devices to another org](#hand-devices-to-another-org).
240
+
241
+
242
+ ## Hand devices to another org
243
+
244
+ A **claim** moves devices from the org that owns them (typically a manufacturer that
245
+ provisions them at the factory) to another org, with no shared credentials or keys.
246
+ Registering claimable devices is an option on `org register-device`; the `claim`
247
+ group covers the rest of the manufacturer's side, managing the claims. The receiving org redeems a claim on its side, and every linked
248
+ device moves across.
249
+
250
+ ```bash
251
+ # New devices, each in a claim of its own (claim ID = device ID)
252
+ hubblenetwork org register-device -n 10 --claimable
253
+ hubblenetwork org register-device -n 10 --claimable --destination-org <org-id>
254
+
255
+ # Existing devices: one claim for all of them, or one claim each
256
+ hubblenetwork claim create --device <id> --device <id>
257
+ hubblenetwork claim create --device <id> --device <id> --destination-org <org-id>
258
+ hubblenetwork claim create --device <id> --device <id> --per-device
259
+
260
+ # An empty claim to fill later
261
+ hubblenetwork claim create --destination-org <org-id> --name "lot 42"
262
+ hubblenetwork claim link <claim-id> <id> <id>
263
+ hubblenetwork org register-device -n 10 --claim <claim-id>
264
+
265
+ hubblenetwork claim list # claims this org created
266
+ hubblenetwork claim get <claim-id> # status and device count
267
+ hubblenetwork claim get --claim-token "(01)12345678901231(21)ABC123"
268
+ hubblenetwork claim update <claim-id> --directionless
269
+ hubblenetwork claim unlink <id>
270
+ hubblenetwork claim delete <claim-id> # unredeemed claims only
271
+ ```
272
+
273
+ A claim goes `AVAILABLE` → `IN_PROGRESS` → `COMPLETED`, and only an `AVAILABLE` claim
274
+ can be changed, deleted, or have devices linked or unlinked. A completed claim stays as
275
+ a permanent record of the hand-off.
276
+
277
+ * **Directional or directionless.** With `--destination-org`, only that org can redeem
278
+ the claim, so a leaked claim ID is harmless. Without it, whoever presents the claim
279
+ ID first wins it. Use that only when the recipient isn't known yet, and share the ID
280
+ only with them. `claim update` can set or remove the destination later.
281
+ * **Claim tokens.** `--claim-token` adds an alternate ID that you can print on the
282
+ box: a UUID, or a GS1-128 payload using AI `01` (GTIN) and/or `21` (serial). `get`
283
+ accepts it in place of the claim ID.
284
+ * **Entitlement.** Creating claims and linking devices need the
285
+ `can_create_device_claims` entitlement. It is off by default, and Hubble enables it
286
+ per org.
287
+ * **Existing devices.** `claim create --device` links the devices once the claim
288
+ exists. If linking fails, the new claim is deleted again so no empty claim is left
289
+ behind. With `--per-device`, one device failing doesn't stop the rest.
290
+ * **Provisioning.** The cloud registers devices before linking them and doesn't roll
291
+ back. If `org register-device --claim` fails on the link, the devices may exist
292
+ unlinked, and the error says so.
293
+
294
+ `list`, `get`, `create` and `update` take `-f json`, as does `org register-device`.
235
295
 
236
296
 
237
297
  ## Receive a device's satellite uplink
@@ -430,7 +490,7 @@ Import from the package top-level for a stable surface:
430
490
  ```python
431
491
  from hubblenetwork import (
432
492
  ble, cloud, sat,
433
- Organization, Device, Credentials, Environment,
493
+ Organization, Device, DeviceClaim, Credentials, Environment,
434
494
  EncryptedPacket, UnencryptedPacket, AesEaxPacket, UnknownPacket,
435
495
  DecryptedPacket, SatellitePacket, Location,
436
496
  decrypt, decrypt_eax, decrypt_satellite,
@@ -507,6 +567,35 @@ variants — `ble.scan()` / `ble.scan_async()`. The CLI's auto-detection is avai
507
567
  too, in `hubblenetwork.detect`: `CtrCounterModeDetector` / `EaxExponentDetector` are
508
568
  the per-scan objects that own the sweep and its cache.
509
569
 
570
+ Device claims, from the manufacturer's side. Errors are `hubblenetwork.errors`
571
+ types: `NotFoundError` (404, which is also what a claim pinned to another org
572
+ returns), `ConflictError` (409, not `AVAILABLE`), and `PermissionDeniedError` (a
573
+ missing entitlement or scope):
574
+
575
+ ```python
576
+ from hubblenetwork import DeviceClaim
577
+
578
+ # New devices, each claimable on its own (destination_org_id is optional)
579
+ devices = org.register_devices(10, claimable=True, destination_org_id=customer_org_id)
580
+ device = org.register_device(claimable=True) # directionless
581
+
582
+ # Existing devices: one claim for several, or one claim each
583
+ claim: DeviceClaim = org.create_claim(
584
+ destination_org_id=customer_org_id, name="lot 42", device_ids=[d1, d2]
585
+ )
586
+ claims = org.claim_devices([d1, d2]) # {device_id: DeviceClaim}
587
+
588
+ # Manage claims
589
+ org.link_device(existing.id, claim.claim_id) # or unlink_device(id)
590
+ for c in org.iter_claims(status="AVAILABLE"):
591
+ print(c.claim_id, c.status, c.destination_org_id)
592
+ org.update_claim(claim.claim_id, destination_org_id="") # "" clears: directionless
593
+ org.delete_claim(claim.claim_id)
594
+ ```
595
+
596
+ `Device.claim_id` records the claim a newly registered device was put in.
597
+ `update_claim()` takes `None` to leave a field alone and `""` to clear it.
598
+
510
599
  Satellite, which manages the Docker container for you:
511
600
 
512
601
  ```python
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "pyhubblenetwork"
7
- version = "0.15.0"
7
+ version = "0.16.0"
8
8
  requires-python = ">=3.10"
9
9
  authors = [
10
10
  { name="Paul Buckley", email="paul@hubble.com" },
@@ -5,10 +5,11 @@ Import from here; internal module layout may change without notice.
5
5
  """
6
6
 
7
7
  from . import ble, cloud, ready, sat
8
+ from .claim import DeviceClaim
8
9
  from .cloud import Credentials, Environment
9
10
  from .crypto import DEVICE_UPTIME, UNIX_TIME, decrypt, decrypt_eax, decrypt_satellite
10
11
  from .device import Device
11
- from .errors import InvalidCredentialsError
12
+ from .errors import InvalidCredentialsError, PartialRegistrationError
12
13
  from .org import Organization
13
14
  from .packets import (
14
15
  AesEaxPacket,
@@ -27,11 +28,13 @@ __all__ = [
27
28
  "Credentials",
28
29
  "DecryptedPacket",
29
30
  "Device",
31
+ "DeviceClaim",
30
32
  "EncryptedPacket",
31
33
  "Environment",
32
34
  "InvalidCredentialsError",
33
35
  "Location",
34
36
  "Organization",
37
+ "PartialRegistrationError",
35
38
  "SatellitePacket",
36
39
  "UnencryptedPacket",
37
40
  "UnknownPacket",
@@ -0,0 +1,68 @@
1
+ # hubble/claim.py
2
+ from __future__ import annotations
3
+
4
+ import base64
5
+ from dataclasses import dataclass
6
+
7
+ AVAILABLE = "AVAILABLE"
8
+ IN_PROGRESS = "IN_PROGRESS"
9
+ COMPLETED = "COMPLETED"
10
+ CLAIM_STATUSES = (AVAILABLE, IN_PROGRESS, COMPLETED)
11
+
12
+
13
+ def encode_claim_token(token: str) -> str:
14
+ """The path segment a claim_token is looked up by: unpadded base64url.
15
+
16
+ The cloud rejects a padded segment, so the ``=`` must go.
17
+ """
18
+ return base64.urlsafe_b64encode(token.encode("utf-8")).rstrip(b"=").decode("ascii")
19
+
20
+
21
+ @dataclass
22
+ class DeviceClaim:
23
+ """
24
+ A hand-off of devices from the org that owns them (source) to another
25
+ org (destination). Redeeming it moves every linked device to the
26
+ redeeming org and activates them.
27
+
28
+ Status only moves forward: AVAILABLE -> IN_PROGRESS -> COMPLETED. Only an
29
+ AVAILABLE claim can be edited, deleted, or have devices linked/unlinked.
30
+ """
31
+
32
+ claim_id: str
33
+ source_org_id: str
34
+ status: str
35
+ # Caller-chosen alternate ID (UUID or GS1-128), normalized by the cloud.
36
+ claim_token: str | None = None
37
+ name: str | None = None
38
+ # None means directionless: any org holding the claim_id can redeem it.
39
+ destination_org_id: str | None = None
40
+ created_ts: int | None = None # epoch seconds
41
+ updated_ts: int | None = None
42
+ completed_ts: int | None = None
43
+ # Only the single-claim GET returns these. The cloud names the device
44
+ # only when exactly one is linked.
45
+ device_count: int | None = None
46
+ device_ids: list[str] | None = None
47
+
48
+ @property
49
+ def directional(self) -> bool:
50
+ """True when only ``destination_org_id`` can redeem this claim."""
51
+ return bool(self.destination_org_id)
52
+
53
+ @classmethod
54
+ def from_json(cls, json: dict) -> DeviceClaim:
55
+ devices = json.get("devices")
56
+ return cls(
57
+ claim_id=json["claim_id"],
58
+ source_org_id=json.get("source_org_id", ""),
59
+ status=json.get("status", ""),
60
+ claim_token=json.get("claim_token") or None,
61
+ name=json.get("name") or None,
62
+ destination_org_id=json.get("destination_org_id") or None,
63
+ created_ts=json.get("created_ts"),
64
+ updated_ts=json.get("updated_ts"),
65
+ completed_ts=json.get("completed_ts"),
66
+ device_count=json.get("device_count"),
67
+ device_ids=[d["device_id"] for d in devices] if devices else None,
68
+ )