OpenCHAMI / smd

MIT License
0 stars 4 forks source link

[BUG] Router `go-chi` not handling URLs with parameters correctly #10

Closed davidallendj closed 9 months ago

davidallendj commented 9 months ago

Describe the bug When trying to make a request to SMD, URLs that contain a parameter such as /hsm/v2/Inventory/RedfishEndpoints/{xname} or /hsm/v2/Inventory/ComponentEndpoints/{xname} will return a 400 response code.

curl http://127.0.0.1:27779/hsm/v2/Inventory/ComponentEndpoints/x0c0s1b0
{"type":"about:blank","title":"Bad Request","detail":"HMSDS method arg is nil","status":400}

More relevant information from SMD:

smd              | 2024/02/02 20:33:17.227162 smd-api.go:2640: doComponentEndpointGet(): trying...
smd              | 2024/02/02 20:33:17.227491 hmsds-tx-postgres.go:3272: Error: GetCompEndpointByIDTx(): xname was empty
smd              | 2024/02/02 20:33:17.227863 smd-api.go:2645: doComponentEndpointGet(): Lookup failure: () HMSDS method arg is nil
smd              | 192.168.65.1 - - [02/Feb/2024:20:33:17 +0000] "GET /hsm/v2/Inventory/ComponentEndpoints/x0c0s1b0 HTTP/1.1" 400 93 "" "curl/8.4.0"

To Reproduce Steps to reproduce the behavior:

  1. Start the OChami services
  2. Make a curl request: curl http://127.0.0.1:27779/hsm/v2/Inventory/ComponentEndpoints/x0c0s1b0
  3. See error

Expected behavior Making a request to these endpoints should not return a 400. The request should return a response as described in the swagger_v2.yml file.

Desktop (please complete the following information):

alexlovelltroy commented 9 months ago

This looks to me like we're trying to use mux.Vars when we should be using chi.URLParam(r,"xname")

https://github.com/OpenCHAMI/smd/blob/2697169fc26322c4fe81d345df7e451b959f18dc/cmd/smd/smd-api.go#L2641-L2643

Since we dropped mux in favor of chi, anything that relies on mux is likely to fail.

davidallendj commented 9 months ago

That was the issue and changing the top to lines to xname := chi.URLParam(r, "xname") fixed it.