forked from stmcginnis/gofish
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcertificatelocations.go
73 lines (61 loc) · 2.37 KB
/
certificatelocations.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
//
// SPDX-License-Identifier: BSD-3-Clause
//
package redfish
import (
"encoding/json"
"github.com/stmcginnis/gofish/common"
)
// CertificateLocations shall represent the certificate location properties for a Redfish implementation.
type CertificateLocations 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
// certificates is the link to the certificates installed on this service.
certificates []string
// CertificatesCount is the number of certificates installed on this service.
CertificatesCount int
}
// UnmarshalJSON unmarshals a CertificateLocations object from the raw JSON.
func (certificatelocations *CertificateLocations) UnmarshalJSON(b []byte) error {
type temp CertificateLocations
type Links struct {
// Certificates shall contain an array of links to resources of type Certificate that are installed on this
// service.
Certificates common.Links
CertificatesCount int `json:"[email protected]"`
}
var t struct {
temp
Links Links
}
err := json.Unmarshal(b, &t)
if err != nil {
return err
}
*certificatelocations = CertificateLocations(t.temp)
// Extract the links to other entities for later
certificatelocations.certificates = t.Links.Certificates.ToStrings()
certificatelocations.CertificatesCount = t.Links.CertificatesCount
return nil
}
// GetCertificateLocations will get a CertificateLocations instance from the service.
func GetCertificateLocations(c common.Client, uri string) (*CertificateLocations, error) {
return common.GetObject[CertificateLocations](c, uri)
}
// ListReferencedCertificateLocationss gets the collection of CertificateLocations from
// a provided reference.
func ListReferencedCertificateLocations(c common.Client, link string) ([]*CertificateLocations, error) {
return common.GetCollectionObjects[CertificateLocations](c, link)
}
// Certificates retrieves a collection of the Certificates installed on the system.
func (certificatelocations *CertificateLocations) Certificates() ([]*Certificate, error) {
return common.GetObjects[Certificate](certificatelocations.GetClient(), certificatelocations.certificates)
}