equinixmetal-archive / packngo

[Deprecated] A Golang client for the Equinix Metal API. (Packet is now Equinix Metal)
https://deploy.equinix.com/labs/equinix-sdk-go/
Other
79 stars 53 forks source link

Require non-empty IDs as parameters to service actions #307

Closed displague closed 2 years ago

displague commented 3 years ago

It is possible to send ID="" to various service methods, such as Devices.Delete.

The client will send DELETE /metal/v1/devices/. This should not be permitted as such an API call could have unexpected consequences (deleting all devices, for example - although that is not the case).

When an ID is required but an empty ID is provided, the client call should fail with a consistent error message. This should not be left to a 404 response from the API server.

t0mk commented 3 years ago

@displague we could check if the ID is a valid UUID. And wrap the check in a function so that it can be easily changed.

displague commented 3 years ago

Some users of this client may have tests with http.Client mocks and invalid IDs like foo. Those tests will need to be modified to use either change the validator or change the mock ID.