Skip to content

Commit bd1ce4d

Browse files
committed
allow webhook only mode
1 parent 07347ad commit bd1ce4d

File tree

5 files changed

+37
-26
lines changed

5 files changed

+37
-26
lines changed

config/config.go

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -179,34 +179,36 @@ func (c *Config) Validate() []error {
179179
c.Server.MessageSize = DefaultMessageSize
180180
}
181181

182-
// validate mailer options
183-
if c.Mailer.From == "" {
184-
errorList = append(errorList, errors.New("mailer from is required"))
182+
// validate mailer options if configured or required
183+
if c.Mailer.DSN == "" && c.Webhook.Url == "" {
184+
errorList = append(errorList, errors.New("either mailer dsn or webhook url is required"))
185185
}
186186

187-
if _, err := mail.ParseAddress(c.Mailer.From); err != nil {
188-
errorList = append(errorList, errors.New("invalid sender address"))
189-
}
187+
if c.Mailer.DSN != "" {
188+
if c.Mailer.From == "" {
189+
errorList = append(errorList, errors.New("mailer from is required"))
190+
}
190191

191-
if c.Mailer.To == "" {
192-
errorList = append(errorList, errors.New("recipient email is required"))
193-
}
192+
if _, err := mail.ParseAddress(c.Mailer.From); err != nil {
193+
errorList = append(errorList, errors.New("invalid sender address"))
194+
}
194195

195-
if _, err := mail.ParseAddress(c.Mailer.To); err != nil {
196-
errorList = append(errorList, errors.New("invalid recipient address"))
197-
}
196+
if c.Mailer.To == "" {
197+
errorList = append(errorList, errors.New("recipient email is required"))
198+
}
198199

199-
if c.Mailer.DSN == "" {
200-
errorList = append(errorList, errors.New("mailer dsn is required"))
201-
}
200+
if _, err := mail.ParseAddress(c.Mailer.To); err != nil {
201+
errorList = append(errorList, errors.New("invalid recipient address"))
202+
}
202203

203-
parts, err := url.Parse(c.Mailer.DSN)
204-
if err != nil {
205-
errorList = append(errorList, errors.New("invalid mailer dsn"))
206-
}
204+
parts, err := url.Parse(c.Mailer.DSN)
205+
if err != nil {
206+
errorList = append(errorList, errors.New("invalid mailer dsn"))
207+
}
207208

208-
if parts.Scheme != "smtp" {
209-
errorList = append(errorList, errors.New("only smtp servers supported"))
209+
if parts.Scheme != "smtp" {
210+
errorList = append(errorList, errors.New("only smtp servers supported"))
211+
}
210212
}
211213

212214
// validate webhook url

config/config_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,5 @@ func TestConfigValidate(t *testing.T) {
6161

6262
assert.Contains(t, combined, "public key file does not exist")
6363
assert.Contains(t, combined, "unable to read pubkey")
64-
assert.Contains(t, combined, "mailer dsn is required")
65-
assert.Contains(t, combined, "only smtp servers supported")
64+
assert.Contains(t, combined, "either mailer dsn or webhook url is required")
6665
}

docs/qy/developer-guide.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,15 @@ openssl rsa -pubout -in rsa_private.pem -out rsa_public.pem
8585
flowchart TD
8686
A[Cañy qabar ciberüü] --> B{Daroo ciberüü işke aştyby?}
8787
B -- Ooba --> C[Qabar ciberildi]
88-
B -- Cok --> D[Inbox folderge saktoo]
88+
B -- Cok --> D[Inbox folderine saktoo]
8989
D --> E[Cron cügürüü]
9090
E --> F[Qabarlardy oquu]
9191
F --> G{Qajra ciberüügö macburbu?}
9292
G -- Ooba --> H[Qabar ciberildi]
9393
G -- Ooba --> E
9494
```
9595

96-
## Testterdi Jügürtüü
96+
## Testterdi Cügürtüü
9797

9898
```sh
9999
go test ./...

docs/qy/readme.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
[![Test](https://github.com/sultaniman/kpow/actions/workflows/test.yml/badge.svg)](https://github.com/sultaniman/kpow/actions/workflows/test.yml)
2+
---
3+
<a href="https://coff.ee/sultaniman" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Kofe alyp beriñiz" height="36"></a>
4+
15
# KPow 💥
26

37
KPow bul öz aldynça tejlengen, kupujaluuluk türdö bagyttalgan bajlanyş formasy,
@@ -93,6 +97,9 @@ $ kpow verify --config=path-to-config.toml
9397
| `KPOW_INBOX_PATH` | Inbox folderin coly | string | "" |
9498
| `KPOW_INBOX_CRON` | Inboxtu iştetüü cron tartibi | string | `*/5 * * * *` |
9599

100+
> [!note]
101+
> KPowğo Messec cetkirüü üçün `KPOW_MAILER_DSN` ce `KPOW_WEBHOOK_URL` boluşu kerek.
102+
96103
## Şifrlöö
97104

98105
KPow Age, PGP, cana RSA açyk açkyç menen qatty şifrlöö üçün koldonulat.
@@ -110,7 +117,7 @@ age-keygen -o age.key
110117
grep "^# public key:" age.key | cut -d' ' -f3 > age.pub
111118
```
112119

113-
`age.pub` fajlyn `--pubkey` boluup qoldonuñuz.
120+
`age.pub` fajlyn `--pubkey` arqyluu qoldonuñuz.
114121

115122
#### PGP
116123

readme.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ $ kpow verify --config=path-to-config.toml
101101
| `KPOW_INBOX_PATH` | Path to inbox | string | "" |
102102
| `KPOW_INBOX_CRON` | Cron schedule for inbox processing | string | `*/5 * * * *` |
103103

104+
> [!note]
105+
> Either `KPOW_MAILER_DSN` or `KPOW_WEBHOOK_URL` must be provided so KPow can deliver messages.
106+
104107
## Encryption
105108

106109
KPow supports Age, PGP, and RSA public keys for encrypting messages.

0 commit comments

Comments
 (0)