-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathvpnconfigupdate.go
54 lines (45 loc) · 1.08 KB
/
vpnconfigupdate.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
package daemon
import (
"encoding/json"
"github.com/telekom-mms/oc-daemon/pkg/vpnconfig"
)
// VPNConfigUpdate is a VPN configuration update.
type VPNConfigUpdate struct {
Reason string
Config *vpnconfig.Config
}
// Valid returns whether the config update is valid.
func (c *VPNConfigUpdate) Valid() bool {
switch c.Reason {
case "pre-init", "disconnect", "attempt-reconnect", "reconnect":
// config must be nil
if c.Config != nil {
return false
}
case "connect":
// config must be valid
if c.Config == nil || !c.Config.Valid() {
return false
}
default:
return false
}
return true
}
// JSON returns the Config as JSON.
func (c *VPNConfigUpdate) JSON() ([]byte, error) {
return json.Marshal(c)
}
// VPNConfigUpdateFromJSON parses and returns the VPNConfigUpdate in b.
func VPNConfigUpdateFromJSON(b []byte) (*VPNConfigUpdate, error) {
c := NewVPNConfigUpdate()
err := json.Unmarshal(b, c)
if err != nil {
return nil, err
}
return c, nil
}
// NewVPNConfigUpdate returns a new VPNConfigUpdate.
func NewVPNConfigUpdate() *VPNConfigUpdate {
return &VPNConfigUpdate{}
}