Skip to content

Commit

Permalink
Initialize wireguard devices on boot
Browse files Browse the repository at this point in the history
  • Loading branch information
UnAfraid committed Oct 22, 2023
1 parent 6393b88 commit aad74f4
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions pkg/manage/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,37 @@ func NewService(
}

s.cleanup(context.Background())
s.init()

return s
}

func (s *service) init() {
ctx := context.Background()
servers, err := s.serverService.FindServers(ctx, &server.FindOptions{
Enabled: adapt.ToPointerNilZero(true),
})
if err != nil {
logrus.WithError(err).Error("failed to find servers")
return
}

for _, srv := range servers {
peers, err := s.peerService.FindPeers(ctx, &peer.FindOptions{
ServerId: adapt.ToPointer(srv.Id),
})
if err != nil {
logrus.WithError(err).WithField("name", srv.Name).Error("failed to find peers for server")
return
}

if _, err = s.configureDevice(ctx, srv, peers); err != nil {
logrus.WithError(err).WithField("name", srv.Name).Error("failed to configure wireguard device")
return
}
}
}

func (s *service) Authenticate(ctx context.Context, username string, password string) (*user.User, error) {
return s.userService.Authenticate(ctx, username, password)
}
Expand Down

0 comments on commit aad74f4

Please sign in to comment.