mirror of
https://github.com/h44z/wg-portal.git
synced 2025-08-10 07:22:24 +00:00
GetPeer, DeletePeer impl.
This commit is contained in:
parent
f30805accd
commit
c1735a27ce
@ -38,6 +38,8 @@ type WireGuardManager interface {
|
|||||||
UpdateInterface(ctx context.Context, in *domain.Interface) (*domain.Interface, error)
|
UpdateInterface(ctx context.Context, in *domain.Interface) (*domain.Interface, error)
|
||||||
DeleteInterface(ctx context.Context, id domain.InterfaceIdentifier) error
|
DeleteInterface(ctx context.Context, id domain.InterfaceIdentifier) error
|
||||||
PreparePeer(ctx context.Context, id domain.InterfaceIdentifier) (*domain.Peer, error)
|
PreparePeer(ctx context.Context, id domain.InterfaceIdentifier) (*domain.Peer, error)
|
||||||
|
DeletePeer(ctx context.Context, id domain.PeerIdentifier) error
|
||||||
|
GetPeer(ctx context.Context, id domain.PeerIdentifier) (*domain.Peer, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type StatisticsCollector interface {
|
type StatisticsCollector interface {
|
||||||
|
@ -19,6 +19,7 @@ type InterfaceAndPeerDatabaseRepo interface {
|
|||||||
FindUserPeers(ctx context.Context, id domain.UserIdentifier, search string) ([]domain.Peer, error)
|
FindUserPeers(ctx context.Context, id domain.UserIdentifier, search string) ([]domain.Peer, error)
|
||||||
SavePeer(ctx context.Context, id domain.PeerIdentifier, updateFunc func(in *domain.Peer) (*domain.Peer, error)) error
|
SavePeer(ctx context.Context, id domain.PeerIdentifier, updateFunc func(in *domain.Peer) (*domain.Peer, error)) error
|
||||||
DeletePeer(ctx context.Context, id domain.PeerIdentifier) error
|
DeletePeer(ctx context.Context, id domain.PeerIdentifier) error
|
||||||
|
GetPeer(ctx context.Context, id domain.PeerIdentifier) (*domain.Peer, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type StatisticsDatabaseRepo interface {
|
type StatisticsDatabaseRepo interface {
|
||||||
|
@ -670,3 +670,31 @@ func (m Manager) PreparePeer(ctx context.Context, id domain.InterfaceIdentifier)
|
|||||||
|
|
||||||
return freshPeer, nil
|
return freshPeer, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m Manager) DeletePeer(ctx context.Context, id domain.PeerIdentifier) error {
|
||||||
|
peer, err := m.db.GetPeer(ctx, id)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("unable to find peer %s: %w", id, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = m.wg.DeletePeer(ctx, peer.InterfaceIdentifier, id)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("wireguard failed to delete peer %s: %w", id, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = m.db.DeletePeer(ctx, id)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to delete peer %s: %w", id, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m Manager) GetPeer(ctx context.Context, id domain.PeerIdentifier) (*domain.Peer, error) {
|
||||||
|
peer, err := m.db.GetPeer(ctx, id)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("unable to find peer %s: %w", id, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return peer, nil
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user