Skip to content

feat: add show-linking-usage support CLI command#3122

Open
Sneagan wants to merge 4 commits into
masterfrom
feat/support-show-linking-usage
Open

feat: add show-linking-usage support CLI command#3122
Sneagan wants to merge 4 commits into
masterfrom
feat/support-show-linking-usage

Conversation

@Sneagan

@Sneagan Sneagan commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds bat-go skus show-linking-usage, a read-only support CLI command that shows
how many device linking slots are in use for a premium order.

Support asked for a way to see a subscriber's slot usage without touching anything.
The deletion flow (reset-linking-limit) already reveals this during its
confirmation step; this command exposes the same listing — active credential
batches via the signed GET /v1/orders/{orderID}/credentials/batches endpoint,
where each batch is one linked device — without any mutation or confirmation
prompt. The order is identified by --order-id or --email (subscriptions
support API lookup, with interactive selection when several match), optionally
scoped with --item-id.

The shared logic between the two commands is extracted into helpers used by both
(requireOrderRef, resolveOrderID, batchesURL, formatBatchTable) rather than
duplicated; reset-linking-limit's behavior and output are unchanged.

Note: the report shows slots in use only, not used-of-total — the batches
endpoint does not return the item's max_active_batches_tlv2_creds, so a
used/total display would need a small SKUs server change. Possible follow-up.

The new command's flags are deliberately not bound to viper: reset-linking-limit
already binds the shared global keys, and viper.BindPFlag is global, so rebinding
would clobber that command. Flags are read directly from cobra with env fallback.

Type of Change

  • Product feature
  • Bug fix
  • Performance improvement
  • Refactor
  • Other

Tested Environments

  • Development
  • Staging
  • Production

Before Requesting Review

  • Does your code build cleanly without any errors or warnings?
  • Have you used auto closing keywords?
  • Have you added tests for new functionality?
  • Have validated query efficiency for new database queries? (n/a — no DB queries; reuses the existing signed SKUs
    endpoint)
  • Have documented new functionality in README or in comments?
  • Have you squashed all intermediate commits?
  • Is there a clear title that explains what the PR does?
  • Have you used intuitive function, variable and other naming?
  • Have you requested security and/or privacy review if needed
  • Have you performed a self review of this PR?

Manual Test Plan

bat-go skus show-linking-usage
--skus-base-url https://
--private-key
--email subscriber@example.com
--subscriptions-base-url https://
--subscriptions-token <SUPPORT_TOKEN>

  • Resolves the order by email (prompts when several match) and prints the slot
    count plus a per-device table (request_id, oldest_valid_from), making no changes.
  • --order-id <uuid> targets an order directly without the email lookup.
  • --item-id <uuid> scopes the listing to one order item.
  • reset-linking-limit is unaffected: same prompts, output, and behavior as before.

@Sneagan Sneagan requested a review from clD11 as a code owner June 9, 2026 21:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant