Skip to content

refactor: accept expanded deviceInfo fields in v1 devices#1021

Open
ShradhaGupta31 wants to merge 5 commits into
mainfrom
device-discovery-apis
Open

refactor: accept expanded deviceInfo fields in v1 devices#1021
ShradhaGupta31 wants to merge 5 commits into
mainfrom
device-discovery-apis

Conversation

@ShradhaGupta31
Copy link
Copy Markdown
Contributor

@ShradhaGupta31 ShradhaGupta31 commented May 21, 2026

  • Update the v1 devices POST/GET flow to accomodate the full deviceInfo payload

Adresses - #1020

Step 1: Fetch auth token

export TOKEN=$(curl -ks --noproxy "*" \
  -X POST "https://localhost:8181/api/v1/authorize" \
  -H "Content-Type: application/json" \
  -d '{"username":"standalone","password":"G@ppm0ym"}' \
  | jq -r '.token')

Step 2: Use POST api to add device information

curl --insecure -X POST "https://localhost:8181/api/v1/devices" \
  --noproxy "*" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $TOKEN" \
  -d '{
    "guid": "143e4567-e89b-12d3-a456-426614174000",
    "hostname": "hostname",
    "friendlyName": "friendlyName",
    "tags": [],
    "mpsusername": "admin",
    "deviceInfo": {
      "fwVersion": "16.1.30",
      "fwBuild": "3400",
      "fwSku": "11",
      "currentMode": "Admin",
      "features": "SOL,IDER,KVM",
      "ipAddress": "10.0.0.12",
      "lastUpdated": "2026-05-21T00:00:00Z",
      "tlsMode": "TLS 1.2",
      "upid": {
        "oemPlatformIdType": "Not Set (0)",
        "oemId": "",
        "csmeId": "4A45A39C5ED9462082510000"
      },
      "amtEnabledInBIOS": true,
      "meInterfaceVersion": "16.1.25.2124",
      "dhcpEnabled": true,
      "certHashes": ["a1b2c3", "d4e5f6"],
      "lmsInstalled": true,
      "lmsVersion": "2410.5.0.0",
      "osName": "linux",
      "osVersion": "6.8.0-51-generic",
      "osDistro": "Ubuntu 24.04 LTS",
      "cpuModel": "Intel(R) Core(TM) Ultra 7 165H",
      "osIpAddress": "10.49.76.163",
      "ethernetAdapterCount": 2,
      "monitorConnected": true,
      "ieee8021xEnabled": false
    }
  }'

Step 3: Fetch list of all known devices along with there respective discovery data

curl --insecure -s -X GET "https://localhost:8181/api/v1/devices" \
  --noproxy "*" \
  -H "Authorization: Bearer $TOKEN" | jq

Step 4: Fetch discovery data of a particular GUID

curl --insecure -s -X GET "https://localhost:8181/api/v1/devices/<GUID>" \
  --noproxy "*" \
  -H "Authorization: Bearer $TOKEN" | jq

@ShradhaGupta31 ShradhaGupta31 requested a review from a team as a code owner May 21, 2026 14:43
@codecov
Copy link
Copy Markdown

codecov Bot commented May 21, 2026

Codecov Report

❌ Patch coverage is 57.37705% with 26 lines in your changes missing coverage. Please review.
✅ Project coverage is 41.71%. Comparing base (f01cb2b) to head (2c554b6).

Files with missing lines Patch % Lines
internal/usecase/devices/usecase.go 45.45% 23 Missing and 1 partial ⚠️
internal/controller/httpapi/v1/devices.go 85.71% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1021      +/-   ##
==========================================
+ Coverage   41.66%   41.71%   +0.04%     
==========================================
  Files         135      135              
  Lines       12433    12488      +55     
==========================================
+ Hits         5180     5209      +29     
- Misses       6698     6722      +24     
- Partials      555      557       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates the v1 /api/v1/devices DTO/usecase flow to accept and persist an expanded deviceInfo payload (including unknown/extra fields), supporting the Device Discovery requirements in #1020.

Changes:

  • Persist deviceInfo by JSON-marshalling dto.DeviceInfo into entity.Device.DeviceInfo (string) and unmarshalling it back on reads.
  • Expand dto.DeviceInfo with additional fields and custom JSON (un)marshal logic to round-trip unknown fields via ExtraFields.
  • Add/adjust unit tests and update the v1 devices Postman request example to include the expanded deviceInfo.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
internal/usecase/devices/usecase.go Marshals/unmarshals deviceInfo between DTO and entity; allows partial-update setter for deviceInfo.
internal/usecase/devices/repo_test.go Updates partial-update tests to include deviceInfo persistence/round-trip expectations.
internal/entity/dto/v1/device.go Expands DeviceInfo and adds custom JSON round-tripping for unknown fields (ExtraFields).
internal/entity/dto/v1/device_test.go Adds a JSON round-trip test for DeviceInfo, including ExtraFields.
internal/controller/httpapi/v1/devices_test.go Adds controller-level test ensuring POST accepts full deviceInfo payload.
integration-test/collections/console_mps_apis.postman_collection.json Updates Postman sample request body to include full deviceInfo.

Comment thread internal/usecase/devices/usecase.go
Comment thread internal/usecase/devices/usecase.go
Comment thread internal/entity/dto/v1/device.go Outdated
Comment thread internal/entity/dto/v1/device.go Outdated
Comment thread internal/entity/dto/v1/device.go Outdated
Comment thread internal/entity/dto/v1/device.go Outdated
Comment thread internal/entity/dto/v1/device.go Outdated
Comment thread internal/usecase/devices/repo_test.go Outdated
@rsdmike
Copy link
Copy Markdown
Member

rsdmike commented May 21, 2026

OpenAPI spec is stale. doc/openapi.json only declares the original 7 deviceInfo fields; the 17 new fields added in this PR (tlsMode, upid, amtEnabledInBIOS, meInterfaceVersion, dhcpEnabled, certHashes, lmsInstalled, lmsVersion, osName, osVersion, osDistro, cpuModel, osIpAddress, ethernetAdapterCount, monitorConnected, ieee8021xEnabled, lastDiscovered) are not documented.

CLAUDE.md requires regenerating the spec in the same PR:

go run ./cmd/openapi-gen

Then commit the regenerated doc/openapi.json.

Copy link
Copy Markdown
Member

@rsdmike rsdmike left a comment

Choose a reason for hiding this comment

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

Great first attack at this, thanks for doing this! Please see my comments. Most important we def need to remove the complexity with the deletes. Thanks!

@sinchubhat
Copy link
Copy Markdown
Contributor

Hi, please take a look at #905 it contains the lmsinstalled part of deviceInfo

* Wire deviceInfo serialization/deserialization in dtoToEntity/entityToDTO
* Merge isLMSAvailable from activation into deviceInfo.lmsInstalled
* Add LMSInstalled field to DeviceInfo DTO struct

Related to device-management-toolkit/rpc-go#1246
Comment thread internal/entity/dto/v1/device.go Outdated
@ShradhaGupta31 ShradhaGupta31 force-pushed the device-discovery-apis branch from f54a1fe to c4d41ab Compare May 27, 2026 05:51
@ShradhaGupta31 ShradhaGupta31 changed the base branch from main to issue1246-rpc-go May 27, 2026 06:29
@ShradhaGupta31 ShradhaGupta31 force-pushed the device-discovery-apis branch from c4d41ab to c0c208d Compare May 27, 2026 06:45
 - Update the v1 devices POST/GET flow to accomodate the full deviceInfo payload

Adresses - #1020

Signed-off-by: ShradhaGupta31 <shradha.gupta@intel.com>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Comment thread internal/controller/httpapi/v1/devices.go
Comment thread internal/entity/dto/v1/device.go
Comment thread internal/entity/dto/v1/device.go
@ShradhaGupta31 ShradhaGupta31 force-pushed the device-discovery-apis branch from 5d2c185 to b0cabfb Compare May 27, 2026 09:27
Comment thread internal/entity/dto/v1/device.go
@ShradhaGupta31 ShradhaGupta31 force-pushed the device-discovery-apis branch from b0cabfb to 54b8bb6 Compare May 27, 2026 16:28
Base automatically changed from issue1246-rpc-go to main June 1, 2026 03:37
@ShradhaGupta31 ShradhaGupta31 force-pushed the device-discovery-apis branch 3 times, most recently from 052a57c to 2ddab90 Compare June 2, 2026 06:05
@ShradhaGupta31 ShradhaGupta31 force-pushed the device-discovery-apis branch from 2ddab90 to 2c554b6 Compare June 2, 2026 06:18
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.

4 participants