mirror of
https://github.com/h44z/wg-portal.git
synced 2025-09-15 07:11:15 +00:00
chore: use interfaces for all other services
This commit is contained in:
@@ -10,16 +10,60 @@ import (
|
||||
"github.com/h44z/wg-portal/internal/domain"
|
||||
)
|
||||
|
||||
type Manager struct {
|
||||
cfg *config.Config
|
||||
tplHandler *TemplateHandler
|
||||
// region dependencies
|
||||
|
||||
type Mailer interface {
|
||||
// Send sends an email with the given subject and body to the given recipients.
|
||||
Send(ctx context.Context, subject, body string, to []string, options *domain.MailOptions) error
|
||||
}
|
||||
|
||||
type ConfigFileManager interface {
|
||||
// GetInterfaceConfig returns the configuration for the given interface.
|
||||
GetInterfaceConfig(ctx context.Context, id domain.InterfaceIdentifier) (io.Reader, error)
|
||||
// GetPeerConfig returns the configuration for the given peer.
|
||||
GetPeerConfig(ctx context.Context, id domain.PeerIdentifier) (io.Reader, error)
|
||||
// GetPeerConfigQrCode returns the QR code for the given peer.
|
||||
GetPeerConfigQrCode(ctx context.Context, id domain.PeerIdentifier) (io.Reader, error)
|
||||
}
|
||||
|
||||
type UserDatabaseRepo interface {
|
||||
// GetUser returns the user with the given identifier.
|
||||
GetUser(ctx context.Context, id domain.UserIdentifier) (*domain.User, error)
|
||||
}
|
||||
|
||||
type WireguardDatabaseRepo interface {
|
||||
// GetInterfaceAndPeers returns the interface and all peers for the given interface identifier.
|
||||
GetInterfaceAndPeers(ctx context.Context, id domain.InterfaceIdentifier) (*domain.Interface, []domain.Peer, error)
|
||||
// GetPeer returns the peer with the given identifier.
|
||||
GetPeer(ctx context.Context, id domain.PeerIdentifier) (*domain.Peer, error)
|
||||
// GetInterface returns the interface with the given identifier.
|
||||
GetInterface(ctx context.Context, id domain.InterfaceIdentifier) (*domain.Interface, error)
|
||||
}
|
||||
|
||||
type TemplateRenderer interface {
|
||||
// GetConfigMail returns the text and html template for the mail with a link.
|
||||
GetConfigMail(user *domain.User, link string) (io.Reader, io.Reader, error)
|
||||
// GetConfigMailWithAttachment returns the text and html template for the mail with an attachment.
|
||||
GetConfigMailWithAttachment(user *domain.User, cfgName, qrName string) (
|
||||
io.Reader,
|
||||
io.Reader,
|
||||
error,
|
||||
)
|
||||
}
|
||||
|
||||
// endregion dependencies
|
||||
|
||||
type Manager struct {
|
||||
cfg *config.Config
|
||||
|
||||
tplHandler TemplateRenderer
|
||||
mailer Mailer
|
||||
configFiles ConfigFileManager
|
||||
users UserDatabaseRepo
|
||||
wg WireguardDatabaseRepo
|
||||
}
|
||||
|
||||
// NewMailManager creates a new mail manager.
|
||||
func NewMailManager(
|
||||
cfg *config.Config,
|
||||
mailer Mailer,
|
||||
@@ -44,6 +88,7 @@ func NewMailManager(
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// SendPeerEmail sends an email to the user linked to the given peers.
|
||||
func (m Manager) SendPeerEmail(ctx context.Context, linkOnly bool, peers ...domain.PeerIdentifier) error {
|
||||
for _, peerId := range peers {
|
||||
peer, err := m.wg.GetPeer(ctx, peerId)
|
||||
|
Reference in New Issue
Block a user