Template
feat: Let's Encrypt SSL on site creation
This commit is contained in:
@@ -22,14 +22,20 @@ var (
|
||||
domainRegex = regexp.MustCompile(`^(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z]{2,}$`)
|
||||
)
|
||||
|
||||
type Service struct {
|
||||
sites *repository.SiteRepository
|
||||
servers *repository.ServerRepository
|
||||
phpVers *repository.PHPVersionRepository
|
||||
type SSLIssuer interface {
|
||||
IssueAsync(sslID, domainID int64, domain, webroot string)
|
||||
IssueForSite(ctx context.Context, siteID int64) error
|
||||
}
|
||||
|
||||
func NewService(sites *repository.SiteRepository, servers *repository.ServerRepository, php *repository.PHPVersionRepository) *Service {
|
||||
return &Service{sites: sites, servers: servers, phpVers: php}
|
||||
type Service struct {
|
||||
sites *repository.SiteRepository
|
||||
servers *repository.ServerRepository
|
||||
phpVers *repository.PHPVersionRepository
|
||||
ssl SSLIssuer
|
||||
}
|
||||
|
||||
func NewService(sites *repository.SiteRepository, servers *repository.ServerRepository, php *repository.PHPVersionRepository, ssl SSLIssuer) *Service {
|
||||
return &Service{sites: sites, servers: servers, phpVers: php, ssl: ssl}
|
||||
}
|
||||
|
||||
type CreateInput struct {
|
||||
@@ -39,6 +45,7 @@ type CreateInput struct {
|
||||
ServerID int64
|
||||
OwnerID int64
|
||||
IsAdmin bool
|
||||
IssueSSL bool
|
||||
}
|
||||
|
||||
func (s *Service) List(ctx context.Context, user *models.User, isAdmin bool) ([]repository.SiteWithDomain, error) {
|
||||
@@ -86,5 +93,23 @@ func (s *Service) Create(ctx context.Context, in CreateInput) (*repository.SiteW
|
||||
}
|
||||
|
||||
documentRoot := fmt.Sprintf("/var/www/%s/public", name)
|
||||
return s.sites.Create(ctx, serverID, in.OwnerID, name, documentRoot, phpVersion, domain)
|
||||
site, err := s.sites.Create(ctx, serverID, in.OwnerID, name, documentRoot, phpVersion, domain, in.IssueSSL)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if in.IssueSSL && s.ssl != nil && site.SSLID > 0 {
|
||||
s.ssl.IssueAsync(site.SSLID, site.DomainID, domain, documentRoot)
|
||||
}
|
||||
|
||||
return site, nil
|
||||
}
|
||||
|
||||
func (s *Service) ReissueSSLAsync(siteID int64) {
|
||||
if s.ssl == nil {
|
||||
return
|
||||
}
|
||||
go func() {
|
||||
_ = s.ssl.IssueForSite(context.Background(), siteID)
|
||||
}()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user