forked from lf-edge/eve
-
Notifications
You must be signed in to change notification settings - Fork 0
/
certinfotypes.go
65 lines (54 loc) · 1.67 KB
/
certinfotypes.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
// Copyright (c) 2017 Zededa, Inc.
// SPDX-License-Identifier: Apache-2.0
package types
import (
"encoding/hex"
"github.com/google/go-cmp/cmp"
zcert "github.com/lf-edge/eve/api/go/certs"
zcommon "github.com/lf-edge/eve/api/go/evecommon"
"github.com/lf-edge/eve/pkg/pillar/base"
)
// ControllerCert : controller certicate
// config received from controller
type ControllerCert struct {
HashAlgo zcommon.HashAlgorithm
Type zcert.ZCertType
Cert []byte
CertHash []byte
}
// Key :
func (cert *ControllerCert) Key() string {
return hex.EncodeToString(cert.CertHash)
}
// LogCreate :
func (cert ControllerCert) LogCreate(logBase *base.LogObject) {
logObject := base.NewLogObject(logBase, base.ControllerCertLogType, "",
nilUUID, cert.LogKey())
if logObject == nil {
return
}
logObject.Noticef("Controller cert create")
}
// LogModify :
func (cert ControllerCert) LogModify(logBase *base.LogObject, old interface{}) {
logObject := base.EnsureLogObject(logBase, base.ControllerCertLogType, "",
nilUUID, cert.LogKey())
oldCert, ok := old.(ControllerCert)
if !ok {
logObject.Clone().Fatalf("LogModify: Old object interface passed is not of ControllerCert type")
}
// XXX remove?
logObject.CloneAndAddField("diff", cmp.Diff(oldCert, cert)).
Noticef("Controller cert modify")
}
// LogDelete :
func (cert ControllerCert) LogDelete(logBase *base.LogObject) {
logObject := base.EnsureLogObject(logBase, base.ControllerCertLogType, "",
nilUUID, cert.LogKey())
logObject.Noticef("Controller cert delete")
base.DeleteLogObject(logBase, cert.LogKey())
}
// LogKey :
func (cert ControllerCert) LogKey() string {
return string(base.ControllerCertLogType) + "-" + cert.Key()
}