mirror of
https://github.com/bakito/adguardhome-sync.git
synced 2025-01-01 04:41:51 +08:00
Only sync dhcp config if it is valid (#184)
* handle new install page redirect location * only sync dhcp config if valid
This commit is contained in:
parent
009715ccea
commit
c93084e623
5 changed files with 53 additions and 2 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -7,3 +7,4 @@ main
|
|||
tmp
|
||||
bin
|
||||
config.yaml
|
||||
*.log
|
||||
|
|
|
@ -490,7 +490,7 @@ func (w *worker) syncDHCPServer(osc *types.DHCPServerConfig, rc client.Client, r
|
|||
return nil
|
||||
}
|
||||
sc, err := rc.DHCPServerConfig()
|
||||
if w.cfg.Features.DHCP.ServerConfig {
|
||||
if w.cfg.Features.DHCP.ServerConfig && osc.HasConfig() {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package sync
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"net"
|
||||
|
||||
"github.com/bakito/adguardhome-sync/pkg/client"
|
||||
clientmock "github.com/bakito/adguardhome-sync/pkg/mocks/client"
|
||||
|
@ -433,11 +434,17 @@ var _ = Describe("Sync", func() {
|
|||
rsc *types.DHCPServerConfig
|
||||
)
|
||||
BeforeEach(func() {
|
||||
osc = &types.DHCPServerConfig{}
|
||||
osc = &types.DHCPServerConfig{V4: &types.V4ServerConfJSON{
|
||||
GatewayIP: net.IPv4(1, 2, 3, 4),
|
||||
RangeStart: net.IPv4(1, 2, 3, 5),
|
||||
RangeEnd: net.IPv4(1, 2, 3, 6),
|
||||
SubnetMask: net.IPv4(255, 255, 255, 0),
|
||||
}}
|
||||
rsc = &types.DHCPServerConfig{}
|
||||
w.cfg.Features.DHCP.StaticLeases = false
|
||||
})
|
||||
It("should have no changes", func() {
|
||||
rsc.V4 = osc.V4
|
||||
cl.EXPECT().DHCPServerConfig().Return(rsc, nil)
|
||||
err := w.syncDHCPServer(osc, cl, types.AdGuardInstance{})
|
||||
Ω(err).ShouldNot(HaveOccurred())
|
||||
|
|
|
@ -33,6 +33,10 @@ func (c *DHCPServerConfig) Equals(o *DHCPServerConfig) bool {
|
|||
return string(a) == string(b)
|
||||
}
|
||||
|
||||
func (c *DHCPServerConfig) HasConfig() bool {
|
||||
return (c.V4 != nil && c.V4.isValid()) || (c.V6 != nil && c.V6.isValid())
|
||||
}
|
||||
|
||||
// V4ServerConfJSON v4 server conf
|
||||
type V4ServerConfJSON struct {
|
||||
GatewayIP net.IP `json:"gateway_ip"`
|
||||
|
@ -42,6 +46,10 @@ type V4ServerConfJSON struct {
|
|||
LeaseDuration uint32 `json:"lease_duration"`
|
||||
}
|
||||
|
||||
func (j V4ServerConfJSON) isValid() bool {
|
||||
return j.GatewayIP != nil && j.SubnetMask != nil && j.RangeStart != nil && j.RangeEnd != nil
|
||||
}
|
||||
|
||||
// V6ServerConfJSON v6 server conf
|
||||
type V6ServerConfJSON struct {
|
||||
RangeStart net.IP `json:"range_start"`
|
||||
|
@ -49,6 +57,10 @@ type V6ServerConfJSON struct {
|
|||
LeaseDuration uint32 `json:"lease_duration"`
|
||||
}
|
||||
|
||||
func (j V6ServerConfJSON) isValid() bool {
|
||||
return j.RangeStart != nil && j.RangeEnd != nil
|
||||
}
|
||||
|
||||
// Leases slice of leases type
|
||||
type Leases []Lease
|
||||
|
||||
|
|
|
@ -420,5 +420,36 @@ var _ = Describe("Types", func() {
|
|||
Ω(dc1.Clone().Equals(dc1)).Should(BeTrue())
|
||||
})
|
||||
})
|
||||
Context("HasConfig", func() {
|
||||
It("should not have a config", func() {
|
||||
dc1 := &types.DHCPServerConfig{
|
||||
V4: &types.V4ServerConfJSON{},
|
||||
V6: &types.V6ServerConfJSON{},
|
||||
}
|
||||
Ω(dc1.HasConfig()).Should(BeFalse())
|
||||
})
|
||||
It("should not have a v4 config", func() {
|
||||
dc1 := &types.DHCPServerConfig{
|
||||
V4: &types.V4ServerConfJSON{
|
||||
GatewayIP: net.IPv4(1, 2, 3, 4),
|
||||
RangeStart: net.IPv4(1, 2, 3, 5),
|
||||
RangeEnd: net.IPv4(1, 2, 3, 6),
|
||||
SubnetMask: net.IPv4(255, 255, 255, 0),
|
||||
},
|
||||
V6: &types.V6ServerConfJSON{},
|
||||
}
|
||||
Ω(dc1.HasConfig()).Should(BeTrue())
|
||||
})
|
||||
It("should not have a v6 config", func() {
|
||||
dc1 := &types.DHCPServerConfig{
|
||||
V4: &types.V4ServerConfJSON{},
|
||||
V6: &types.V6ServerConfJSON{
|
||||
RangeStart: net.IPv4(1, 2, 3, 5),
|
||||
RangeEnd: net.IPv4(1, 2, 3, 6),
|
||||
},
|
||||
}
|
||||
Ω(dc1.HasConfig()).Should(BeTrue())
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue