Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 24 additions & 35 deletions redfish/securebootdatabase.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ type SecureBootDatabase struct {
ODataContext string `json:"@odata.context"`
// ODataType is the odata type.
ODataType string `json:"@odata.type"`
// certificates shall be a link to a resource collection of type CertificateCollection.
certificates string
// CertificatesLink shall be a link to a resource collection of type CertificateCollection.
CertificatesLink common.Link `json:"Certificates"`
// DatabaseID shall contain the name of the UEFI Secure Boot database. This property shall contain the same value
// as the Id property. The value shall be one of the UEFI-defined Secure Boot databases: 'PK', 'KEK' 'db', 'dbx',
// 'dbr', 'dbt', 'PKDefault', 'KEKDefault', 'dbDefault', 'dbxDefault', 'dbrDefault', or 'dbtDefault'.
Expand All @@ -39,60 +39,49 @@ type SecureBootDatabase struct {
// 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"`
// Signatures shall be a link to a resource collection of type SignatureCollection.
signatures string

resetKeysTarget string
// SignaturesLink shall be a link to a resource collection of type SignatureCollection.
SignaturesLink common.Link `json:"Signatures"`
// Actions shall contain the available actions for this resource.
Actions SecureBootDatabaseActions `json:"Actions"`
}

// UnmarshalJSON unmarshals a SecureBootDatabase object from the raw JSON.
func (securebootdatabase *SecureBootDatabase) UnmarshalJSON(b []byte) error {
type temp SecureBootDatabase
var t struct {
temp
Actions struct {
ResetKeys common.ActionTarget `json:"#SecureBootDatabase.ResetKeys"`
}
Certificates common.Link
Signatures common.Link
}

err := json.Unmarshal(b, &t)
if err != nil {
return err
}

*securebootdatabase = SecureBootDatabase(t.temp)

// Extract the links to other entities for later
securebootdatabase.certificates = t.Certificates.String()
securebootdatabase.signatures = t.Signatures.String()

securebootdatabase.resetKeysTarget = t.Actions.ResetKeys.Target

return nil
// SecureBootDatabaseActions shall contain the available actions for a SecureBootDatabase resource.
type SecureBootDatabaseActions struct {
// ResetKeys shall reset the UEFI Secure Boot key database.
ResetKeys common.ActionTarget `json:"#SecureBootDatabase.ResetKeys"`
// Oem shall contain the available OEM-specific actions for this resource.
Oem json.RawMessage `json:"Oem"`
}

// Certificates get the certificates contained in this UEFI Secure Boot database.
func (securebootdatabase *SecureBootDatabase) Certificates() ([]*Certificate, error) {
return ListReferencedCertificates(securebootdatabase.GetClient(), securebootdatabase.certificates)
if securebootdatabase.CertificatesLink.IsZero() {
return nil, nil
}
return ListReferencedCertificates(securebootdatabase.GetClient(), securebootdatabase.CertificatesLink.String())
}

// Signatures get the certificates contained in this UEFI Secure Boot database.
func (securebootdatabase *SecureBootDatabase) Signatures() ([]*Signature, error) {
return ListReferencedSignatures(securebootdatabase.GetClient(), securebootdatabase.signatures)
if securebootdatabase.SignaturesLink.IsZero() {
return nil, nil
}
return ListReferencedSignatures(securebootdatabase.GetClient(), securebootdatabase.SignaturesLink.String())
}

// ResetKeys will perform a reset of this UEFI Secure Boot key database. The `ResetAllKeysToDefault`
// value shall reset this UEFI Secure Boot key database to the default values. The `DeleteAllKeys`
// value shall delete the contents of this UEFI Secure Boot key database.
func (securebootdatabase *SecureBootDatabase) ResetKeys(resetType ResetKeysType) error {
if securebootdatabase.Actions.ResetKeys.Target == "" {
return ErrActionNotSupported
}
params := struct {
ResetKeysType ResetKeysType
}{
ResetKeysType: resetType,
}
return securebootdatabase.Post(securebootdatabase.resetKeysTarget, params)
return securebootdatabase.Post(securebootdatabase.Actions.ResetKeys.Target, params)
}

// GetSecureBootDatabase will get a SecureBootDatabase instance from the service.
Expand Down
4 changes: 2 additions & 2 deletions redfish/securebootdatabase_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ func TestSecureBootDatabase(t *testing.T) {
assertEquals(t, "PK", result.ID)
assertEquals(t, "PK - Platform Key", result.Name)
assertEquals(t, "PK", result.DatabaseID)
assertEquals(t, "/redfish/v1/Systems/1/SecureBoot/SecureBootDatabases/PK/Certificates/", result.certificates)
assertEquals(t, "/redfish/v1/Systems/1/SecureBoot/SecureBootDatabases/PK/Certificates/", result.CertificatesLink.String())
}

// TestSecureBootDatabaseResetKeys tests the SecureBootDatabase ResetKeys call.
func TestSecureBootDatabaseResetKeys(t *testing.T) {
var result SecureBootDatabase
err := json.NewDecoder(strings.NewReader(applicationBody)).Decode(&result)
err := json.NewDecoder(strings.NewReader(secureBootDatabaseBody)).Decode(&result)

if err != nil {
t.Errorf("Error decoding JSON: %s", err)
Expand Down