Skip to content

feat: auto-register device on 404 for unactivated devices#1369

Draft
sinchubhat wants to merge 1 commit into
mainfrom
issue1368-rpc-go
Draft

feat: auto-register device on 404 for unactivated devices#1369
sinchubhat wants to merge 1 commit into
mainfrom
issue1368-rpc-go

Conversation

@sinchubhat

@sinchubhat sinchubhat commented Jun 8, 2026

Copy link
Copy Markdown
Contributor
  • When rpc amtinfo --sync sends a PATCH to console for a device that is not yet registered, sync currently fails with: "device not found; activate the device before syncing device info".
  • Handle 404 by creating a minimal device record (guid + hostname) via POST, then retry PATCH with the full deviceInfo payload.

Addresses #1368

Output:

Query from host

TOKEN=$(curl -s http://localhost:8181/api/v1/authorize -H "Content-Type: application/json" -d '{"username":"<username>","password":"<password>"}' | jq -r '.token') && curl -s http://localhost:8181/api/v1/devices -H "Authorization: Bearer $TOKEN" | jq '[.[] | {hostname, guid, deviceInfo}]'
[]

Using old rpc

  • When rpc amtinfo --sync sends a PATCH to console for a device that is not yet registered, sync currently fails with: "device not found; activate the device before syncing device info".
sudo ./rpc amtinfo --sync --url http://<host_ip_addr>:8181/api/v1/devices \
  --auth-endpoint http://<host_ip_addr>:8181/api/v1/authorize \
  --auth-username <username> --auth-password "<password>"
time="2026-06-08T10:09:02+05:30" level=info msg="Using configuration file: config.yaml (flag values may originate from this file)"
time="2026-06-08T10:09:02+05:30" level=error msg="Failed to get user certificates: WSMAN client not available"
time="2026-06-08T10:09:02+05:30" level=error msg="device not found; activate the device before syncing device info"

Using current rpc

  • Handle 404 by creating a minimal device record (guid + hostname) via POST, then retry PATCH with the full deviceInfo payload.
sudo ./rpc amtinfo --sync --url http://<host_ip_addr>:8181/api/v1/devices \
  --auth-endpoint http://<host_ip_addr>:8181/api/v1/authorize \
  --auth-username <username> --auth-password "<password>"
[sudo] password for hspe:
time="2026-06-08T10:09:28+05:30" level=error msg="Failed to get user certificates: WSMAN client not available"

  AMT Device Information
  ──────────────────────
  Version                        16.1.35
  Build Number                   2557
  SKU                            16392
  Features                       AMT Pro Corporate
  UUID                           <edge-node-guid>
  Control Mode                   not activated
  Provisioning State             pre-provisioning
  DNS Suffix                     vprodemo.com
  DNS Suffix (OS)                <edge-node-hostname>
  Hostname (OS)                  <edge-node-hostname>

  Remote Access
  ─────────────
  Network                        outside enterprise (CIRA)
  Remote Status                  not connected
  Trigger                        user initiated
  MPS Hostname

  Wired Adapter
  ─────────────
  DHCP Enabled                   true
  DHCP Mode                      passive
  Link Status                    up
  AMT IP Address                 0.0.0.0
  OS IP Address                  <edge-node-ip-addr>
  MAC Address                    <edge-node-mac-addr>

  Wireless Adapter
  ────────────────
  DHCP Enabled                   true
  DHCP Mode                      active
  Link Status                    down
  AMT IP Address                 0.0.0.0
  OS IP Address                  0.0.0.0
  MAC Address                    00:00:00:00:00:00

  Intel UPID
  ──────────
  Platform ID Type               Not Set (0)
  OEM ID
  CSME ID                        <edge-node-csmeId>

  Certificate Hashes
  ──────────────────
  <Certificate Hashes>

Query from host

curl -s http://localhost:8181/api/v1/devices -H "Authorization: Bearer $TOKEN" | jq '[.[] | {hostname, guid, deviceInfo}]'
[
  {
    "hostname": "<edge-node-hostname>",
    "guid": "<edge-node-guid>",
    "deviceInfo": {
      "fwVersion": "16.1.35",
      "fwBuild": "2557",
      "fwSku": "16392",
      "currentMode": "not activated",
      "features": "AMT Pro Corporate",
      "ipAddress": "<edge-node-ip-addr>",
      "lastUpdated": "2026-06-08T10:09:28.771045493+05:30",
      "lmsInstalled": true
    }
  }
]

* When rpc amtinfo --sync sends a PATCH to console for a device that is not yet registered, sync currently fails with: "device not found; activate the device before syncing device info".
* Handle 404 by creating a minimal device record (guid + hostname) via POST, then retry PATCH with the full deviceInfo payload.

Addresses #1368

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds a 404 recovery path to rpc amtinfo --sync so unregistered (unactivated) devices can be automatically registered in the Console and then synced successfully, addressing issue #1368.

Changes:

  • On PATCH 404 during amtinfo --sync, POST a minimal device record (guid + hostname) and retry the PATCH.
  • Introduce a helper (createDevice) to perform the minimal POST registration.
  • Add a unit test covering the 404 → POST → retry PATCH flow.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
internal/commands/amtinfo.go Implements 404 fallback behavior by POSTing a minimal device record then retrying the PATCH sync.
internal/commands/amtinfo_test.go Adds a test validating that a 404 triggers POST registration and a retry PATCH.

Comment thread internal/commands/amtinfo.go Outdated
Comment thread internal/commands/amtinfo_test.go
Comment thread internal/commands/amtinfo_test.go
Comment thread internal/commands/amtinfo.go Outdated
@sinchubhat sinchubhat force-pushed the issue1368-rpc-go branch 2 times, most recently from b94886d to b1acee9 Compare June 8, 2026 05:27
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.

sync fails with 404 for unactivated devices - auto-register instead

2 participants