-
Notifications
You must be signed in to change notification settings - Fork 106
/
signature.go
109 lines (93 loc) · 3.16 KB
/
signature.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
//
// SPDX-License-Identifier: BSD-3-Clause
//
package redfish
import (
"encoding/json"
"github.com/stmcginnis/gofish/common"
)
type SignatureTypeRegistry string
const (
// UEFISignatureTypeRegistry denotes a signature defined in the UEFI Specification.
UEFISignatureTypeRegistry SignatureTypeRegistry = "UEFI"
)
// Signature This resource contains a signature for a Redfish implementation.
type Signature struct {
common.Entity
// ODataContext is the odata context.
ODataContext string `json:"@odata.context"`
// ODataEtag is the odata etag.
ODataEtag string `json:"@odata.etag"`
// ODataType is the odata type.
ODataType string `json:"@odata.type"`
// Description provides a description of this resource.
Description string
// Oem shall contain the OEM extensions. All values for properties that this object contains shall conform to the
// Redfish Specification-described requirements.
OEM json.RawMessage `json:"Oem"`
// SignatureString shall contain the string of the signature, and the format shall follow the requirements
// specified by the value of the SignatureType property. If the signature contains any private keys, they shall be
// removed from the string in responses. If the private key for the signature is not known by the service and is
// needed to use the signature, the client shall provide the private key as part of the string in the POST request.
SignatureString string
// SignatureType shall contain the format type for the signature. The format is qualified by the value of the
// SignatureTypeRegistry property.
SignatureType string
// SignatureTypeRegistry shall contain the type for the signature.
SignatureTypeRegistry SignatureTypeRegistry
// UefiSignatureOwner shall contain the GUID of the UEFI signature owner for this signature as defined by the UEFI
// Specification. This property shall only be present if the SignatureTypeRegistry property is 'UEFI'.
UefiSignatureOwner string
}
// GetSignature will get a Signature instance from the service.
func GetSignature(c common.Client, uri string) (*Signature, error) {
resp, err := c.Get(uri)
if err != nil {
return nil, err
}
defer resp.Body.Close()
var signature Signature
err = json.NewDecoder(resp.Body).Decode(&signature)
if err != nil {
return nil, err
}
signature.SetClient(c)
return &signature, nil
}
// ListReferencedSignatures gets the collection of Signature from
// a provided reference.
func ListReferencedSignatures(c common.Client, link string) ([]*Signature, error) {
var result []*Signature
if link == "" {
return result, nil
}
type GetResult struct {
Item *Signature
Link string
Error error
}
ch := make(chan GetResult)
collectionError := common.NewCollectionError()
get := func(link string) {
signature, err := GetSignature(c, link)
ch <- GetResult{Item: signature, Link: link, Error: err}
}
go func() {
err := common.CollectList(get, c, link)
if err != nil {
collectionError.Failures[link] = err
}
close(ch)
}()
for r := range ch {
if r.Error != nil {
collectionError.Failures[r.Link] = r.Error
} else {
result = append(result, r.Item)
}
}
if collectionError.Empty() {
return result, nil
}
return result, collectionError
}