Skip to content

Commit

Permalink
do not sync DHCP if disabled #137
Browse files Browse the repository at this point in the history
  • Loading branch information
bakito committed Dec 27, 2022
1 parent 9edec9c commit 97ae38c
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 8 deletions.
1 change: 0 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ linters:
- unconvert
- unparam
- unused
- wastedassign
linters-settings:
gosec:
# Exclude generated files
Expand Down
21 changes: 14 additions & 7 deletions pkg/sync/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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 {
Expand Down
45 changes: 45 additions & 0 deletions pkg/sync/sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 97ae38c

Please sign in to comment.