mirror of
https://github.com/h44z/wg-portal.git
synced 2025-08-12 00:12:21 +00:00
ensure that deleted peers are restored once the interface is re-enabled
This commit is contained in:
parent
5dee6d051d
commit
f5e29e2cd3
@ -560,6 +560,27 @@ func (m Manager) saveInterface(ctx context.Context, iface *domain.Interface) (
|
||||
return nil, fmt.Errorf("post-save hooks failed: %w", err)
|
||||
}
|
||||
|
||||
// If the interface has just been enabled, restore its peers on the physical controller
|
||||
if !oldEnabled && newEnabled && iface.Backend == config.LocalBackendName {
|
||||
peers, err := m.db.GetInterfacePeers(ctx, iface.Identifier)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to load peers for interface %s: %w", iface.Identifier, err)
|
||||
}
|
||||
for _, peer := range peers {
|
||||
saveErr := m.wg.GetController(*iface).SavePeer(ctx, iface.Identifier, peer.Identifier,
|
||||
func(pp *domain.PhysicalPeer) (*domain.PhysicalPeer, error) {
|
||||
domain.MergeToPhysicalPeer(pp, &peer)
|
||||
return pp, nil
|
||||
})
|
||||
if saveErr != nil {
|
||||
return nil, fmt.Errorf("failed to restore peer %s for interface %s: %w", peer.Identifier,
|
||||
iface.Identifier, saveErr)
|
||||
}
|
||||
}
|
||||
// notify that peers for this interface have changed so config/routes can be updated
|
||||
m.bus.Publish(app.TopicPeerInterfaceUpdated, iface.Identifier)
|
||||
}
|
||||
|
||||
m.bus.Publish(app.TopicAuditInterfaceChanged, domain.AuditEventWrapper[audit.InterfaceEvent]{
|
||||
Ctx: ctx,
|
||||
Event: audit.InterfaceEvent{
|
||||
|
Loading…
x
Reference in New Issue
Block a user