forked from evcc-io/evcc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheebus.go
43 lines (34 loc) · 1.03 KB
/
eebus.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
package configure
import (
"fmt"
"github.com/evcc-io/evcc/charger/eebus"
"github.com/evcc-io/evcc/cmd/shutdown"
)
// configureEEBus setup EEBus
func (c *CmdConfigure) configureEEBus(conf map[string]interface{}) error {
var err error
if eebus.Instance, err = eebus.NewServer(conf); err == nil {
go eebus.Instance.Run()
shutdown.Register(eebus.Instance.Shutdown)
}
return err
}
// eebusCertificate creates EEBUS certificate and returns private/public key
func (c *CmdConfigure) eebusCertificate() (map[string]interface{}, error) {
var eebusConfig map[string]interface{}
cert, err := eebus.CreateCertificate()
if err != nil {
return eebusConfig, fmt.Errorf("%s", c.localizedString("Error_EEBUS_Certificate_Create"))
}
pubKey, privKey, err := eebus.GetX509KeyPair(cert)
if err != nil {
return eebusConfig, fmt.Errorf("%s", c.localizedString("Error_EEBUS_Certificate_Use"))
}
eebusConfig = map[string]interface{}{
"certificate": map[string]string{
"public": pubKey,
"private": privKey,
},
}
return eebusConfig, nil
}