Skip to content

Commit

Permalink
feat: courier template configs
Browse files Browse the repository at this point in the history
  • Loading branch information
Benehiko committed Jan 24, 2022
1 parent d9c8217 commit f3d2175
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 2 deletions.
36 changes: 34 additions & 2 deletions driver/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ const (
ViperKeyDSN = "dsn"
ViperKeyCourierSMTPURL = "courier.smtp.connection_uri"
ViperKeyCourierTemplatesPath = "courier.template_override_path"
ViperKeyCourierTemplatesRecovery = "courier.templates.recovery"
ViperKeyCourierTemplatesVerification = "courier.templates.verification"
ViperKeyCourierSMTPFrom = "courier.smtp.from_address"
ViperKeyCourierSMTPFromName = "courier.smtp.from_name"
ViperKeyCourierSMTPHeaders = "courier.smtp.headers"
Expand Down Expand Up @@ -205,8 +207,22 @@ type (
MinPasswordLength uint `json:"min_password_length"`
IdentifierSimilarityCheckEnabled bool `json:"identifier_similarity_check_enabled"`
}
Schemas []Schema
Config struct {
Schemas []Schema
CourierEmailBodyTemplate struct {
PlainText string `json:"plaintext"`
HTML string `json:"html"`
}
CourierEmailTemplate struct {
Body *CourierEmailBodyTemplate `json:"body"`
Subject string `json:"subject"`
}
CourierFlowTemplate struct {
Invalid *CourierEmailTemplate `json:"invalid"`
Valid *CourierEmailTemplate `json:"valid"`
}
CourierVerificationTemplate CourierFlowTemplate
CourierRecoveryTemplate CourierFlowTemplate
Config struct {
l *logrusx.Logger
p *configx.Provider
identitySchema *jsonschema.Schema
Expand Down Expand Up @@ -822,6 +838,22 @@ func (p *Config) CourierTemplatesRoot() string {
return p.p.StringF(ViperKeyCourierTemplatesPath, "courier/builtin/templates")
}

func (p *Config) CourierTemplatesVerification() (*CourierVerificationTemplate, error) {
var templates *CourierVerificationTemplate
if err := p.p.Unmarshal(ViperKeyCourierTemplatesVerification, &templates); err != nil {
return nil, err
}
return templates, nil
}

func (p *Config) CourierTemplatesRecovery() (*CourierRecoveryTemplate, error) {
var templates *CourierRecoveryTemplate
if err := p.p.Unmarshal(ViperKeyCourierTemplatesRecovery, &templates); err != nil {
return nil, err
}
return templates, nil
}

func (p *Config) CourierSMTPHeaders() map[string]string {
return p.p.StringMap(ViperKeyCourierSMTPHeaders)
}
Expand Down
49 changes: 49 additions & 0 deletions embedx/config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1305,6 +1305,19 @@
"title": "Courier configuration",
"description": "The courier is responsible for sending and delivering messages over email, sms, and other means.",
"properties": {
"templates": {
"type": "object",
"properties": {
"recovery": {
"type": "object",
"$ref": "#/$defs/courier"
},
"verification": {
"type": "object",
"$ref": "#/$defs/courier"
}
}
},
"template_override_path": {
"type": "string",
"title": "Override message templates",
Expand Down Expand Up @@ -2248,6 +2261,42 @@
}
}
],
"$defs": {
"courier": {
"invalid": {
"type": "object",
"$ref": "#/$defs/email-courier"
},
"valid": {
"type": "object",
"$ref": "#/$defs/email-courier"
},
"required": ["invalid", "valid"]
},
"email-courier": {
"email": {
"type": "object",
"properties": {
"body": {
"type": "object",
"properties": {
"plaintext": {
"type": "string"
},
"html": {
"type": "string"
}
},
"require": ["plaintext", "html"]
},
"subject": {
"type": "string"
}
},
"required": ["body", "subject"]
}
}
},
"required": [
"identity",
"dsn",
Expand Down

0 comments on commit f3d2175

Please sign in to comment.