FOGProject / fogproject

An open source computer cloning & management system
https://fogproject.org
GNU General Public License v3.0
1.08k stars 216 forks source link

Can't do a 'put' api call on a host object if the current 'name' is included in json body #564

Closed darksidemilk closed 4 hours ago

darksidemilk commented 1 year ago

Describe the bug When you do a PUT api call on a host object (http://fog-server/fog/host/{hostID}/edit) and you inlcude the 'name' in the json body, where that is the current name and is not changing, it fails with an { "error": "Already created" } If you update with a changed name or omit the name it works fine. If you include other fields with their current values, no errors occur and the values stay the same.

To Reproduce Steps to reproduce the behavior:

There are other ways to use the api, but I found this using the fogApi powershell module. So in a powershell session

#if you don't already have the fogpai module configured
install-module FogApi;
Set-fogserversettings -interactive; #follow the prompts to connect your server
$myHost = get-foghost;
# just an example of a change on the description field
$myHost.description = "some new description"
# create json of the whole host object
Update-FogObject -type object -coreObject host -jsonData ($myhost | convertto-json -compress) -idofobject $myhost.id -verbose

you'll get an error such as this

 $result = Invoke-WebRequest @apiCall;
     |                        ~~~~~~~~~~~~~~~~~~~~~~~~~~
     | { "error": "Already created" }

If you do this, to omit the name and macs in the json, it will update the description correctly, you could also select only the description/changed fields

Update-FogObject -type object -coreObject host -jsonData ($myhost | Select-Object -excludeproperty name,macs | convertto-json -compress) -idofobject $myhost.id -verbose

The resulting fog host object would then be displayed:

id             : 1847
name           : myComputerName
description    : some new description
...
#full results of host object omitted

Expected behavior

Including the current name shouldn't affect the api call when the name isn't changing. I'm fairly sure (like 80% sure) it didn't previously do this. I believe it used to ignore the macs field too, but I'm less sure about that, setting macs to a host is a separate table/api path. But this bug is about the name field.

Software (please complete the following information):

darksidemilk commented 3 weeks ago

in working-1.6 this is fixed as of this commit https://github.com/FOGProject/fogproject/commit/a65bb37537ab5115a340f6987550d5dddb100b98