Skip to content

Commit

Permalink
refactor: retention policy config
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsNotGoodName committed Sep 13, 2023
1 parent b6f4268 commit 44aee5c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 30 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,12 @@ python_executable: python3
# Retention policy for envelopes and attachment files
retention:
# # Retention policy for envelopes in database
# envelope_count: # (0, 100, 250, ...)
# envelope_age: # (5m, 5h45m, ...)
# Retention policy for envelopes in database
envelope_count: # (0, 100, 250, ...)
envelope_age: # (5m, 5h45m, ...)
# # Retention policy for attachment files on disk
# attachment_size: # (100 MB, 1 GB, ...)
# Retention policy for attachment files on disk
attachment_size: # (100 MB, 1 GB, ...)
# HTTP server
http:
Expand Down Expand Up @@ -276,6 +276,6 @@ make dev-web
- feat: read [mbox](https://access.redhat.com/articles/6167512) files
- feat: CRUD endpoints
- feat: IMAP for viewing mail
- feat: JSON API
- feat: OpenAPI
- feat: Windows installer
- fix: chrome keeps thinking some HTTP pages are French
57 changes: 33 additions & 24 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,25 +55,25 @@ type Config struct {
}

type Raw struct {
Debug bool `koanf:"debug"`
TimeFormat string `koanf:"time_format"`
MaxPayloadSize string `koanf:"max_payload_size"`
DataDirectory string `koanf:"data_directory"`
PythonExecutable string `koanf:"python_executable"`
RetentionEnvelopeCount *int `koanf:"retention.envelope_count"`
RetentionEnvelopeAge *string `koanf:"retention.envelope_age"`
RetentionAttachmentSize *string `koanf:"retention.attachment_size"`
SMTPDisable bool `koanf:"smtp.disable"`
SMTPHost string `koanf:"smtp.host"`
SMTPPort uint16 `koanf:"smtp.port"`
SMTPUsername string `koanf:"smtp.username"`
SMTPPassword string `koanf:"smtp.password"`
HTTPDisable bool `koanf:"http.disable"`
HTTPHost string `koanf:"http.host"`
HTTPPort uint16 `koanf:"http.port"`
HTTPUsername string `koanf:"http.username"`
HTTPPassword string `koanf:"http.password"`
HTTPURL string `koanf:"http.url"`
Debug bool `koanf:"debug"`
TimeFormat string `koanf:"time_format"`
MaxPayloadSize string `koanf:"max_payload_size"`
DataDirectory string `koanf:"data_directory"`
PythonExecutable string `koanf:"python_executable"`
RetentionEnvelopeCount string `koanf:"retention.envelope_count"`
RetentionEnvelopeAge string `koanf:"retention.envelope_age"`
RetentionAttachmentSize string `koanf:"retention.attachment_size"`
SMTPDisable bool `koanf:"smtp.disable"`
SMTPHost string `koanf:"smtp.host"`
SMTPPort uint16 `koanf:"smtp.port"`
SMTPUsername string `koanf:"smtp.username"`
SMTPPassword string `koanf:"smtp.password"`
HTTPDisable bool `koanf:"http.disable"`
HTTPHost string `koanf:"http.host"`
HTTPPort uint16 `koanf:"http.port"`
HTTPUsername string `koanf:"http.username"`
HTTPPassword string `koanf:"http.password"`
HTTPURL string `koanf:"http.url"`
// IMAPDisable bool `koanf:"imap.disable"`
// IMAPHost string `koanf:"imap.host"`
// IMAPPort uint16 `koanf:"imap.port"`
Expand Down Expand Up @@ -187,17 +187,26 @@ func (p Parser) Parse(raw Raw) (Config, error) {

var config *models.Config
{
var envelopeCount *int
if raw.RetentionEnvelopeCount != "" {
count, err := strconv.Atoi(raw.RetentionEnvelopeCount)
if err != nil {
return Config{}, err
}

envelopeCount = &count
}
var attachmentsSize *int64
if raw.RetentionAttachmentSize != nil {
size, err := bytes.Parse(*raw.RetentionAttachmentSize)
if raw.RetentionAttachmentSize != "" {
size, err := bytes.Parse(raw.RetentionAttachmentSize)
if err != nil {
return Config{}, err
}
attachmentsSize = &size
}
var envelopeAge *time.Duration
if raw.RetentionEnvelopeAge != nil {
age, err := time.ParseDuration(*raw.RetentionEnvelopeAge)
if raw.RetentionEnvelopeAge != "" {
age, err := time.ParseDuration(raw.RetentionEnvelopeAge)
if err != nil {
return Config{}, err
}
Expand All @@ -206,7 +215,7 @@ func (p Parser) Parse(raw Raw) (Config, error) {

config = &models.Config{
RetentionPolicy: models.ConfigRetentionPolicy{
EnvelopeCount: raw.RetentionEnvelopeCount,
EnvelopeCount: envelopeCount,
AttachmentSize: attachmentsSize,
EnvelopeAge: envelopeAge,
MinAge: 5 * time.Minute,
Expand Down

0 comments on commit 44aee5c

Please sign in to comment.