Initial commit: Open sourcing all of the Maple Open Technologies code.
This commit is contained in:
commit
755d54a99d
2010 changed files with 448675 additions and 0 deletions
62
cloud/maplefile-backend/pkg/emailer/mailgun/config.go
Normal file
62
cloud/maplefile-backend/pkg/emailer/mailgun/config.go
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
// File Path: monorepo/cloud/maplefile-backend/pkg/emailer/mailgun/config.go
|
||||
package mailgun
|
||||
|
||||
type MailgunConfigurationProvider interface {
|
||||
GetSenderEmail() string
|
||||
GetDomainName() string // Deprecated
|
||||
GetBackendDomainName() string
|
||||
GetFrontendDomainName() string
|
||||
GetMaintenanceEmail() string
|
||||
GetAPIKey() string
|
||||
GetAPIBase() string
|
||||
}
|
||||
|
||||
type mailgunConfigurationProviderImpl struct {
|
||||
senderEmail string
|
||||
domain string
|
||||
apiBase string
|
||||
maintenanceEmail string
|
||||
frontendDomain string
|
||||
backendDomain string
|
||||
apiKey string
|
||||
}
|
||||
|
||||
func NewMailgunConfigurationProvider(senderEmail, domain, apiBase, maintenanceEmail, frontendDomain, backendDomain, apiKey string) MailgunConfigurationProvider {
|
||||
return &mailgunConfigurationProviderImpl{
|
||||
senderEmail: senderEmail,
|
||||
domain: domain,
|
||||
apiBase: apiBase,
|
||||
maintenanceEmail: maintenanceEmail,
|
||||
frontendDomain: frontendDomain,
|
||||
backendDomain: backendDomain,
|
||||
apiKey: apiKey,
|
||||
}
|
||||
}
|
||||
|
||||
func (me *mailgunConfigurationProviderImpl) GetDomainName() string {
|
||||
return me.domain
|
||||
}
|
||||
|
||||
func (me *mailgunConfigurationProviderImpl) GetSenderEmail() string {
|
||||
return me.senderEmail
|
||||
}
|
||||
|
||||
func (me *mailgunConfigurationProviderImpl) GetBackendDomainName() string {
|
||||
return me.backendDomain
|
||||
}
|
||||
|
||||
func (me *mailgunConfigurationProviderImpl) GetFrontendDomainName() string {
|
||||
return me.frontendDomain
|
||||
}
|
||||
|
||||
func (me *mailgunConfigurationProviderImpl) GetMaintenanceEmail() string {
|
||||
return me.maintenanceEmail
|
||||
}
|
||||
|
||||
func (me *mailgunConfigurationProviderImpl) GetAPIKey() string {
|
||||
return me.apiKey
|
||||
}
|
||||
|
||||
func (me *mailgunConfigurationProviderImpl) GetAPIBase() string {
|
||||
return me.apiBase
|
||||
}
|
||||
13
cloud/maplefile-backend/pkg/emailer/mailgun/interface.go
Normal file
13
cloud/maplefile-backend/pkg/emailer/mailgun/interface.go
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
// File Path: monorepo/cloud/maplefile-backend/pkg/emailer/mailgun/interface.go
|
||||
package mailgun
|
||||
|
||||
import "context"
|
||||
|
||||
type Emailer interface {
|
||||
Send(ctx context.Context, sender, subject, recipient, htmlContent string) error
|
||||
GetSenderEmail() string
|
||||
GetDomainName() string // Deprecated
|
||||
GetBackendDomainName() string
|
||||
GetFrontendDomainName() string
|
||||
GetMaintenanceEmail() string
|
||||
}
|
||||
64
cloud/maplefile-backend/pkg/emailer/mailgun/mailgun.go
Normal file
64
cloud/maplefile-backend/pkg/emailer/mailgun/mailgun.go
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
// File Path: monorepo/cloud/maplefile-backend/pkg/emailer/mailgun/mailgun.go
|
||||
package mailgun
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/mailgun/mailgun-go/v4"
|
||||
)
|
||||
|
||||
type mailgunEmailer struct {
|
||||
config MailgunConfigurationProvider
|
||||
Mailgun *mailgun.MailgunImpl
|
||||
}
|
||||
|
||||
func NewEmailer(config MailgunConfigurationProvider) Emailer {
|
||||
// Defensive code: Make sure we have access to the file before proceeding any further with the code.
|
||||
mg := mailgun.NewMailgun(config.GetDomainName(), config.GetAPIKey())
|
||||
|
||||
mg.SetAPIBase(config.GetAPIBase()) // Override to support our custom email requirements.
|
||||
|
||||
return &mailgunEmailer{
|
||||
config: config,
|
||||
Mailgun: mg,
|
||||
}
|
||||
}
|
||||
|
||||
func (me *mailgunEmailer) Send(ctx context.Context, sender, subject, recipient, body string) error {
|
||||
|
||||
message := me.Mailgun.NewMessage(sender, subject, "", recipient)
|
||||
message.SetHtml(body)
|
||||
|
||||
ctx, cancel := context.WithTimeout(ctx, time.Second*10)
|
||||
defer cancel()
|
||||
|
||||
// Send the message with a 10 second timeout
|
||||
_, _, err := me.Mailgun.Send(ctx, message)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (me *mailgunEmailer) GetDomainName() string {
|
||||
return me.config.GetDomainName()
|
||||
}
|
||||
|
||||
func (me *mailgunEmailer) GetSenderEmail() string {
|
||||
return me.config.GetSenderEmail()
|
||||
}
|
||||
|
||||
func (me *mailgunEmailer) GetBackendDomainName() string {
|
||||
return me.config.GetBackendDomainName()
|
||||
}
|
||||
|
||||
func (me *mailgunEmailer) GetFrontendDomainName() string {
|
||||
return me.config.GetFrontendDomainName()
|
||||
}
|
||||
|
||||
func (me *mailgunEmailer) GetMaintenanceEmail() string {
|
||||
return me.config.GetMaintenanceEmail()
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
// File Path: monorepo/cloud/maplefile-backend/pkg/emailer/mailgun/maplefilemailgun.go
|
||||
package mailgun
|
||||
|
||||
import (
|
||||
"codeberg.org/mapleopentech/monorepo/cloud/maplefile-backend/config"
|
||||
)
|
||||
|
||||
// NewMapleFileModuleEmailer creates a new emailer for the MapleFile standalone module.
|
||||
func NewMapleFileModuleEmailer(cfg *config.Configuration) Emailer {
|
||||
emailerConfigProvider := NewMailgunConfigurationProvider(
|
||||
cfg.Mailgun.SenderEmail,
|
||||
cfg.Mailgun.Domain,
|
||||
cfg.Mailgun.APIBase,
|
||||
cfg.Mailgun.SenderEmail, // Use sender email as maintenance email
|
||||
cfg.Mailgun.FrontendURL,
|
||||
"", // Backend domain not needed for standalone
|
||||
cfg.Mailgun.APIKey,
|
||||
)
|
||||
|
||||
return NewEmailer(emailerConfigProvider)
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
// File Path: monorepo/cloud/maplefile-backend/pkg/emailer/mailgun/papercloudmailgun.go
|
||||
package mailgun
|
||||
|
||||
import (
|
||||
"codeberg.org/mapleopentech/monorepo/cloud/maplefile-backend/config"
|
||||
)
|
||||
|
||||
// NewPaperCloudModuleEmailer creates a new emailer for the PaperCloud Property Evaluator module.
|
||||
func NewPaperCloudModuleEmailer(cfg *config.Configuration) Emailer {
|
||||
emailerConfigProvider := NewMailgunConfigurationProvider(
|
||||
cfg.PaperCloudMailgun.SenderEmail,
|
||||
cfg.PaperCloudMailgun.Domain,
|
||||
cfg.PaperCloudMailgun.APIBase,
|
||||
cfg.PaperCloudMailgun.MaintenanceEmail,
|
||||
cfg.PaperCloudMailgun.FrontendDomain,
|
||||
cfg.PaperCloudMailgun.BackendDomain,
|
||||
cfg.PaperCloudMailgun.APIKey,
|
||||
)
|
||||
|
||||
return NewEmailer(emailerConfigProvider)
|
||||
}
|
||||
10
cloud/maplefile-backend/pkg/emailer/mailgun/provider.go
Normal file
10
cloud/maplefile-backend/pkg/emailer/mailgun/provider.go
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
package mailgun
|
||||
|
||||
import (
|
||||
"codeberg.org/mapleopentech/monorepo/cloud/maplefile-backend/config"
|
||||
)
|
||||
|
||||
// ProvideMapleFileModuleEmailer provides a Mailgun emailer for Wire DI
|
||||
func ProvideMapleFileModuleEmailer(cfg *config.Config) Emailer {
|
||||
return NewMapleFileModuleEmailer(cfg)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue