mirror of
https://github.com/bakito/adguardhome-sync.git
synced 2025-01-01 04:41:51 +08:00
do not sync DHCP if disabled #137
This commit is contained in:
parent
9edec9cf04
commit
97ae38c3fa
3 changed files with 59 additions and 8 deletions
|
@ -29,7 +29,6 @@ linters:
|
|||
- unconvert
|
||||
- unparam
|
||||
- unused
|
||||
- wastedassign
|
||||
linters-settings:
|
||||
gosec:
|
||||
# Exclude generated files
|
||||
|
|
|
@ -173,10 +173,12 @@ func (w *worker) sync() {
|
|||
return
|
||||
}
|
||||
|
||||
o.dhcpServerConfig, err = oc.DHCPServerConfig()
|
||||
if err != nil {
|
||||
sl.With("error", err).Error("Error getting dhcp server config")
|
||||
return
|
||||
if w.cfg.Features.DHCP.ServerConfig || w.cfg.Features.DHCP.StaticLeases {
|
||||
o.dhcpServerConfig, err = oc.DHCPServerConfig()
|
||||
if err != nil {
|
||||
sl.With("error", err).Error("Error getting dhcp server config")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
replicas := w.cfg.UniqueReplicas()
|
||||
|
@ -256,9 +258,11 @@ func (w *worker) syncTo(l *zap.SugaredLogger, o *origin, replica types.AdGuardIn
|
|||
return
|
||||
}
|
||||
|
||||
if err = w.syncDHCPServer(o.dhcpServerConfig, rc, replica); err != nil {
|
||||
rl.With("error", err).Error("Error syncing dns")
|
||||
return
|
||||
if w.cfg.Features.DHCP.ServerConfig || w.cfg.Features.DHCP.StaticLeases {
|
||||
if err = w.syncDHCPServer(o.dhcpServerConfig, rc, replica); err != nil {
|
||||
rl.With("error", err).Error("Error syncing dns")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
rl.Info("Sync done")
|
||||
|
@ -475,6 +479,9 @@ func (w *worker) syncDNS(oal *types.AccessList, odc *types.DNSConfig, rc client.
|
|||
}
|
||||
|
||||
func (w *worker) syncDHCPServer(osc *types.DHCPServerConfig, rc client.Client, replica types.AdGuardInstance) error {
|
||||
if !w.cfg.Features.DHCP.ServerConfig && !w.cfg.Features.DHCP.StaticLeases {
|
||||
return nil
|
||||
}
|
||||
sc, err := rc.DHCPServerConfig()
|
||||
if w.cfg.Features.DHCP.ServerConfig {
|
||||
if err != nil {
|
||||
|
|
|
@ -528,6 +528,51 @@ var _ = Describe("Sync", func() {
|
|||
cl.EXPECT().DeleteDHCPStaticLeases().Return(nil)
|
||||
w.sync()
|
||||
})
|
||||
It("should not sync DHCP", func() {
|
||||
w.cfg.Features.DHCP.ServerConfig = false
|
||||
w.cfg.Features.DHCP.StaticLeases = false
|
||||
// origin
|
||||
cl.EXPECT().Host()
|
||||
cl.EXPECT().Status().Return(&types.Status{Version: versions.MinAgh}, nil)
|
||||
cl.EXPECT().Parental()
|
||||
cl.EXPECT().SafeSearch()
|
||||
cl.EXPECT().SafeBrowsing()
|
||||
cl.EXPECT().RewriteList().Return(&types.RewriteEntries{}, nil)
|
||||
cl.EXPECT().Services()
|
||||
cl.EXPECT().Filtering().Return(&types.FilteringStatus{}, nil)
|
||||
cl.EXPECT().Clients().Return(&types.Clients{}, nil)
|
||||
cl.EXPECT().QueryLogConfig().Return(&types.QueryLogConfig{}, nil)
|
||||
cl.EXPECT().StatsConfig().Return(&types.IntervalConfig{}, nil)
|
||||
cl.EXPECT().AccessList().Return(&types.AccessList{}, nil)
|
||||
cl.EXPECT().DNSConfig().Return(&types.DNSConfig{}, nil)
|
||||
|
||||
// replica
|
||||
cl.EXPECT().Host()
|
||||
cl.EXPECT().Status().Return(&types.Status{Version: versions.MinAgh}, nil)
|
||||
cl.EXPECT().Parental()
|
||||
cl.EXPECT().SafeSearch()
|
||||
cl.EXPECT().SafeBrowsing()
|
||||
cl.EXPECT().QueryLogConfig().Return(&types.QueryLogConfig{}, nil)
|
||||
cl.EXPECT().StatsConfig().Return(&types.IntervalConfig{}, nil)
|
||||
cl.EXPECT().RewriteList().Return(&types.RewriteEntries{}, nil)
|
||||
cl.EXPECT().AddRewriteEntries()
|
||||
cl.EXPECT().DeleteRewriteEntries()
|
||||
cl.EXPECT().Filtering().Return(&types.FilteringStatus{}, nil)
|
||||
cl.EXPECT().AddFilters(false)
|
||||
cl.EXPECT().UpdateFilters(false)
|
||||
cl.EXPECT().DeleteFilters(false)
|
||||
cl.EXPECT().AddFilters(true)
|
||||
cl.EXPECT().UpdateFilters(true)
|
||||
cl.EXPECT().DeleteFilters(true)
|
||||
cl.EXPECT().Services()
|
||||
cl.EXPECT().Clients().Return(&types.Clients{}, nil)
|
||||
cl.EXPECT().AddClients()
|
||||
cl.EXPECT().UpdateClients()
|
||||
cl.EXPECT().DeleteClients()
|
||||
cl.EXPECT().AccessList().Return(&types.AccessList{}, nil)
|
||||
cl.EXPECT().DNSConfig().Return(&types.DNSConfig{}, nil)
|
||||
w.sync()
|
||||
})
|
||||
It("origin version is too small", func() {
|
||||
// origin
|
||||
cl.EXPECT().Host()
|
||||
|
|
Loading…
Reference in a new issue