Skip to content

feat: extend device filtering and sorting - #1435

Draft
sinchubhat wants to merge 1 commit into
mainfrom
issue1077-console
Draft

sinchubhat wants to merge 1 commit into
mainfrom
issue1077-console

Conversation

@sinchubhat

@sinchubhat sinchubhat commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Addresses #1077

TOKEN=$(curl -sk https://localhost:8181/api/v1/authorize -H "Content-Type: application/json" -d '{"username":"standalone","password":"G@ppm0ym"}' | jq -r '.token') && curl -sk https://localhost:8181/api/v1/devices -H "Authorization: Bearer $TOKEN" | jq '[.[] | {hostname, guid, deviceInfo}]'
curl -fskS -G 'https://localhost:8181/api/v1/devices' \
  -H "Authorization: Bearer $TOKEN" \
  --data-urlencode "\$filter=contains(os,'Ubuntu')" \
  --data-urlencode '$orderby=amtVersion desc' \
  --data-urlencode '$count=true' |
  jq '{totalCount, data: [.data[] | {
    hostname,
    osDistro: .deviceInfo.osDistro,
    amtVersion: .deviceInfo.fwVersion
  }]}'

With $TOKEN already set, this helper keeps the commands short and prints only the fields you’re testing:

devices() {
  curl -fskS -G 'https://localhost:8181/api/v1/devices' \
    -H "Authorization: Bearer $TOKEN" \
    --data-urlencode '$count=true' "$@" |
    jq '{totalCount, data: [.data[] | {
      hostname, tags,
      osDistro: .deviceInfo.osDistro,
      sku: .deviceInfo.fwSku,
      amtVersion: .deviceInfo.fwVersion,
      mode: .deviceInfo.currentMode,
      lmsInstalled: .deviceInfo.lmsInstalled
    }]}'
}

Individual filters

devices --data-urlencode "\$filter=skuType eq 'vPro'"
devices --data-urlencode "\$filter=startswith(amtVersion,'16.1')"
devices --data-urlencode "\$filter=currentMode eq 'ACM'"
devices --data-urlencode '$filter=lmsInstalled eq true'
devices \
  --data-urlencode "\$filter=contains(os,'Ubuntu')" \
  --data-urlencode '$orderby=amtVersion desc'
devices \
  --data-urlencode "\$filter=contains(os,'windows')" \
  --data-urlencode '$orderby=amtVersion desc'

Combined filters, ascending sort, and pagination

devices \
  --data-urlencode "\$filter=contains(os,'Ubuntu') and skuType eq 'vPro'" \
  --data-urlencode '$orderby=amtVersion asc' \
  --data-urlencode '$top=1' \
  --data-urlencode '$skip=1'

Multiple predicates and a legacy tag filter

devices \
  --data-urlencode "\$filter=contains(os,'Ubuntu') and currentMode eq 'CCM' and startswith(amtVersion,'18')" \
  --data-urlencode 'tags=Client Control Mode'

Parentheses, OR, and multi-field sorting

devices \
  --data-urlencode "\$filter=(contains(os,'Ubuntu') or contains(os,'Windows')) and lmsInstalled eq true" \
  --data-urlencode '$orderby=currentMode asc, amtVersion desc, hostname asc'

Validation
Each request should print 400.

for option in \
  '$orderby=invalid' \
  '$orderby=hostname sideways' \
  "\$filter=skuType ne 'vPro'"
do
  curl -skS -G 'https://localhost:8181/api/v1/devices' \
    -H "Authorization: Bearer $TOKEN" \
    --data-urlencode "$option" \
    -o /dev/null -w '%{http_code}\n'
done

@codecov

codecov Bot commented Nov 26, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.93939% with 16 lines in your changes missing coverage. Please review.
✅ Project coverage is 64.60%. Comparing base (5748beb) to head (9588e7a).

Files with missing lines Patch % Lines
...nternal/controller/httpapi/v1/device_list_query.go 94.66% 8 Missing ⚠️
...ternal/controller/httpapi/v1/device_list_filter.go 91.95% 7 Missing ⚠️
internal/usecase/sqldb/device.go 83.33% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1435      +/-   ##
==========================================
+ Coverage   64.07%   64.60%   +0.52%     
==========================================
  Files         163      165       +2     
  Lines       13737    13975     +238     
==========================================
+ Hits         8802     9028     +226     
- Misses       4935     4947      +12     

☔ View full report in Codecov by Harness.
📢 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.

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