forked from stmcginnis/gofish
-
Notifications
You must be signed in to change notification settings - Fork 0
/
updateservice.go
82 lines (73 loc) · 2.42 KB
/
updateservice.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
//
// SPDX-License-Identifier: BSD-3-Clause
//
package redfish
import (
"encoding/json"
"github.com/stmcginnis/gofish/common"
)
// UpdateService is used to represent the update service offered by the redfish API
type UpdateService struct {
common.Entity
// ODataContext is the odata context.
ODataContext string `json:"@odata.context"`
// ODataType is the odata type.
ODataType string `json:"@odata.type"`
// Description provides a description of this resource.
Description string
// FirmwareInventory points towards the firmware store endpoint
FirmwareInventory string
// HTTPPushURI endpoint is used to push (POST) firmware updates
HTTPPushURI string `json:"HttpPushUri"`
// ServiceEnabled indicates whether this service isenabled.
ServiceEnabled bool
// Status describes the status and health of a resource and its children.
Status common.Status
// TransferProtocol is the list of network protocols used by the UpdateService to retrieve the software image file
TransferProtocol []string
// UpdateServiceTarget indicates where theupdate image is to be applied.
UpdateServiceTarget string
// rawData holds the original serialized JSON so we can compare updates.
rawData []byte
}
// UnmarshalJSON unmarshals a UpdateService object from the raw JSON.
func (updateService *UpdateService) UnmarshalJSON(b []byte) error {
type temp UpdateService
type actions struct {
SimpleUpdate struct {
AllowableValues []string `json:"TransferProtocol@Redfish.AllowableValues"`
Target string
} `json:"#UpdateService.SimpleUpdate"`
}
var t struct {
temp
Actions actions
FirmwareInventory common.Link
}
err := json.Unmarshal(b, &t)
if err != nil {
return err
}
// Extract the links to other entities for later
*updateService = UpdateService(t.temp)
updateService.FirmwareInventory = string(t.FirmwareInventory)
updateService.TransferProtocol = t.Actions.SimpleUpdate.AllowableValues
updateService.UpdateServiceTarget = t.Actions.SimpleUpdate.Target
updateService.rawData = b
return nil
}
// GetUpdateService will get a UpdateService instance from the service.
func GetUpdateService(c common.Client, uri string) (*UpdateService, error) {
resp, err := c.Get(uri)
if err != nil {
return nil, err
}
defer resp.Body.Close()
var updateService UpdateService
err = json.NewDecoder(resp.Body).Decode(&updateService)
if err != nil {
return nil, err
}
updateService.SetClient(c)
return &updateService, nil
}