add a webapi and webhooks for a simple http/json-based api

for applications to compose/send messages, receive delivery feedback, and
maintain suppression lists.

this is an alternative to applications using a library to compose messages,
submitting those messages using smtp, and monitoring a mailbox with imap for
DSNs, which can be processed into the equivalent of suppression lists. but you
need to know about all these standards/protocols and find libraries. by using
the webapi & webhooks, you just need a http & json library.

unfortunately, there is no standard for these kinds of api, so mox has made up
yet another one...

matching incoming DSNs about deliveries to original outgoing messages requires
keeping history of "retired" messages (delivered from the queue, either
successfully or failed). this can be enabled per account. history is also
useful for debugging deliveries. we now also keep history of each delivery
attempt, accessible while still in the queue, and kept when a message is
retired. the queue webadmin pages now also have pagination, to show potentially
large history.

a queue of webhook calls is now managed too. failures are retried similar to
message deliveries. webhooks can also be saved to the retired list after
completing. also configurable per account.

messages can be sent with a "unique smtp mail from" address. this can only be
used if the domain is configured with a localpart catchall separator such as
"+". when enabled, a queued message gets assigned a random "fromid", which is
added after the separator when sending. when DSNs are returned, they can be
related to previously sent messages based on this fromid. in the future, we can
implement matching on the "envid" used in the smtp dsn extension, or on the
"message-id" of the message. using a fromid can be triggered by authenticating
with a login email address that is configured as enabling fromid.

suppression lists are automatically managed per account. if a delivery attempt
results in certain smtp errors, the destination address is added to the
suppression list. future messages queued for that recipient will immediately
fail without a delivery attempt. suppression lists protect your mail server
reputation.

submitted messages can carry "extra" data through the queue and webhooks for
outgoing deliveries. through webapi as a json object, through smtp submission
as message headers of the form "x-mox-extra-<key>: value".

to make it easy to test webapi/webhooks locally, the "localserve" mode actually
puts messages in the queue. when it's time to deliver, it still won't do a full
delivery attempt, but just delivers to the sender account. unless the recipient
address has a special form, simulating a failure to deliver.

admins now have more control over the queue. "hold rules" can be added to mark
newly queued messages as "on hold", pausing delivery. rules can be about
certain sender or recipient domains/addresses, or apply to all messages pausing
the entire queue. also useful for (local) testing.

new config options have been introduced. they are editable through the admin
and/or account web interfaces.

the webapi http endpoints are enabled for newly generated configs with the
quickstart, and in localserve. existing configurations must explicitly enable
the webapi in mox.conf.

gopherwatch.org was created to dogfood this code. it initially used just the
compose/smtpclient/imapclient mox packages to send messages and process
delivery feedback. it will get a config option to use the mox webapi/webhooks
instead. the gopherwatch code to use webapi/webhook is smaller and simpler, and
developing that shaped development of the mox webapi/webhooks.

for issue #31 by cuu508
This commit is contained in:
Mechiel Lukkien
2024-04-15 21:49:02 +02:00
parent 8bec5ef7d4
commit 09fcc49223
87 changed files with 15556 additions and 1306 deletions

512
queue.go
View File

@ -14,6 +14,12 @@ import (
"github.com/mjl-/mox/queue"
)
func xctlwriteJSON(ctl *ctl, v any) {
fbuf, err := json.Marshal(v)
xcheckf(err, "marshal as json to ctl")
ctl.xwrite(string(fbuf))
}
func cmdQueueHoldrulesList(c *cmd) {
c.help = `List hold rules for the delivery queue.
@ -84,9 +90,9 @@ func ctlcmdQueueHoldrulesRemove(ctl *ctl, id int64) {
ctl.xreadok()
}
// flagFilter is used by many of the queue commands to accept flags for filtering
// the messages the operation applies to.
func flagFilter(fs *flag.FlagSet, f *queue.Filter) {
// flagFilterSort is used by many of the queue commands to accept flags for
// filtering the messages the operation applies to.
func flagFilterSort(fs *flag.FlagSet, f *queue.Filter, s *queue.Sort) {
fs.Func("ids", "comma-separated list of message IDs", func(v string) error {
for _, s := range strings.Split(v, ",") {
id, err := strconv.ParseInt(s, 10, 64)
@ -97,6 +103,7 @@ func flagFilter(fs *flag.FlagSet, f *queue.Filter) {
}
return nil
})
fs.IntVar(&f.Max, "n", 0, "number of messages to return")
fs.StringVar(&f.Account, "account", "", "account that queued the message")
fs.StringVar(&f.From, "from", "", `from address of message, use "@example.com" to match all messages for a domain`)
fs.StringVar(&f.To, "to", "", `recipient address of message, use "@example.com" to match all messages for a domain`)
@ -118,32 +125,93 @@ func flagFilter(fs *flag.FlagSet, f *queue.Filter) {
f.Hold = &hold
return nil
})
if s != nil {
fs.Func("sort", `field to sort by, "nextattempt" (default) or "queued"`, func(v string) error {
switch v {
case "nextattempt":
s.Field = "NextAttempt"
case "queued":
s.Field = "Queued"
default:
return fmt.Errorf("unknown value %q", v)
}
return nil
})
fs.BoolVar(&s.Asc, "asc", false, "sort ascending instead of descending (default)")
}
}
// flagRetiredFilterSort has filters for retired messages.
func flagRetiredFilterSort(fs *flag.FlagSet, f *queue.RetiredFilter, s *queue.RetiredSort) {
fs.Func("ids", "comma-separated list of retired message IDs", func(v string) error {
for _, s := range strings.Split(v, ",") {
id, err := strconv.ParseInt(s, 10, 64)
if err != nil {
return err
}
f.IDs = append(f.IDs, id)
}
return nil
})
fs.IntVar(&f.Max, "n", 0, "number of messages to return")
fs.StringVar(&f.Account, "account", "", "account that queued the message")
fs.StringVar(&f.From, "from", "", `from address of message, use "@example.com" to match all messages for a domain`)
fs.StringVar(&f.To, "to", "", `recipient address of message, use "@example.com" to match all messages for a domain`)
fs.StringVar(&f.Submitted, "submitted", "", `filter by time of submission relative to now, value must start with "<" (before now) or ">" (after now)`)
fs.StringVar(&f.LastActivity, "lastactivity", "", `filter by time of last activity relative to now, value must start with "<" (before now) or ">" (after now)`)
fs.Func("transport", "transport to use for messages, empty string sets the default behaviour", func(v string) error {
f.Transport = &v
return nil
})
fs.Func("result", `"success" or "failure" as result of delivery`, func(v string) error {
switch v {
case "success":
t := true
f.Success = &t
case "failure":
t := false
f.Success = &t
default:
return fmt.Errorf("bad argument %q, need success or failure", v)
}
return nil
})
if s != nil {
fs.Func("sort", `field to sort by, "lastactivity" (default) or "queued"`, func(v string) error {
switch v {
case "lastactivity":
s.Field = "LastActivity"
case "queued":
s.Field = "Queued"
default:
return fmt.Errorf("unknown value %q", v)
}
return nil
})
fs.BoolVar(&s.Asc, "asc", false, "sort ascending instead of descending (default)")
}
}
func cmdQueueList(c *cmd) {
c.params = "[filterflags]"
c.params = "[filtersortflags]"
c.help = `List matching messages in the delivery queue.
Prints the message with its ID, last and next delivery attempts, last error.
`
var f queue.Filter
flagFilter(c.flag, &f)
var s queue.Sort
flagFilterSort(c.flag, &f, &s)
if len(c.Parse()) != 0 {
c.Usage()
}
mustLoadConfig()
ctlcmdQueueList(xctl(), f)
ctlcmdQueueList(xctl(), f, s)
}
func xctlwritequeuefilter(ctl *ctl, f queue.Filter) {
fbuf, err := json.Marshal(f)
xcheckf(err, "marshal filter")
ctl.xwrite(string(fbuf))
}
func ctlcmdQueueList(ctl *ctl, f queue.Filter) {
func ctlcmdQueueList(ctl *ctl, f queue.Filter, s queue.Sort) {
ctl.xwrite("queuelist")
xctlwritequeuefilter(ctl, f)
xctlwriteJSON(ctl, f)
xctlwriteJSON(ctl, s)
ctl.xreadok()
if _, err := io.Copy(os.Stdout, ctl.reader()); err != nil {
log.Fatalf("%s", err)
@ -158,7 +226,7 @@ Messages that are on hold are not delivered until marked as off hold again, or
otherwise handled by the admin.
`
var f queue.Filter
flagFilter(c.flag, &f)
flagFilterSort(c.flag, &f, nil)
if len(c.Parse()) != 0 {
c.Usage()
}
@ -174,7 +242,7 @@ Once off hold, messages can be delivered according to their current next
delivery attempt. See the "queue schedule" command.
`
var f queue.Filter
flagFilter(c.flag, &f)
flagFilterSort(c.flag, &f, nil)
if len(c.Parse()) != 0 {
c.Usage()
}
@ -184,7 +252,7 @@ delivery attempt. See the "queue schedule" command.
func ctlcmdQueueHoldSet(ctl *ctl, f queue.Filter, hold bool) {
ctl.xwrite("queueholdset")
xctlwritequeuefilter(ctl, f)
xctlwriteJSON(ctl, f)
if hold {
ctl.xwrite("true")
} else {
@ -199,7 +267,7 @@ func ctlcmdQueueHoldSet(ctl *ctl, f queue.Filter, hold bool) {
}
func cmdQueueSchedule(c *cmd) {
c.params = "[filterflags] duration"
c.params = "[filterflags] [-now] duration"
c.help = `Change next delivery attempt for matching messages.
The next delivery attempt is adjusted by the duration parameter. If the -now
@ -211,7 +279,7 @@ Schedule immediate delivery with "mox queue schedule -now 0".
var fromNow bool
c.flag.BoolVar(&fromNow, "now", false, "schedule for duration relative to current time instead of relative to current next delivery attempt for messages")
var f queue.Filter
flagFilter(c.flag, &f)
flagFilterSort(c.flag, &f, nil)
args := c.Parse()
if len(args) != 1 {
c.Usage()
@ -224,7 +292,7 @@ Schedule immediate delivery with "mox queue schedule -now 0".
func ctlcmdQueueSchedule(ctl *ctl, f queue.Filter, fromNow bool, d time.Duration) {
ctl.xwrite("queueschedule")
xctlwritequeuefilter(ctl, f)
xctlwriteJSON(ctl, f)
if fromNow {
ctl.xwrite("yes")
} else {
@ -233,7 +301,7 @@ func ctlcmdQueueSchedule(ctl *ctl, f queue.Filter, fromNow bool, d time.Duration
ctl.xwrite(d.String())
line := ctl.xread()
if line == "ok" {
fmt.Printf("%s messages rescheduled\n", ctl.xread())
fmt.Printf("%s message(s) rescheduled\n", ctl.xread())
} else {
log.Fatalf("%s", line)
}
@ -249,7 +317,7 @@ configured transport assigned to use for delivery, e.g. using submission to
another mail server or with connections over a SOCKS proxy.
`
var f queue.Filter
flagFilter(c.flag, &f)
flagFilterSort(c.flag, &f, nil)
args := c.Parse()
if len(args) != 1 {
c.Usage()
@ -260,11 +328,11 @@ another mail server or with connections over a SOCKS proxy.
func ctlcmdQueueTransport(ctl *ctl, f queue.Filter, transport string) {
ctl.xwrite("queuetransport")
xctlwritequeuefilter(ctl, f)
xctlwriteJSON(ctl, f)
ctl.xwrite(transport)
line := ctl.xread()
if line == "ok" {
fmt.Printf("%s messages changed\n", ctl.xread())
fmt.Printf("%s message(s) changed\n", ctl.xread())
} else {
log.Fatalf("%s", line)
}
@ -285,7 +353,7 @@ Value "default" is the default behaviour, currently for unverified opportunistic
TLS.
`
var f queue.Filter
flagFilter(c.flag, &f)
flagFilterSort(c.flag, &f, nil)
args := c.Parse()
if len(args) != 1 {
c.Usage()
@ -308,7 +376,7 @@ TLS.
func ctlcmdQueueRequireTLS(ctl *ctl, f queue.Filter, tlsreq *bool) {
ctl.xwrite("queuerequiretls")
xctlwritequeuefilter(ctl, f)
xctlwriteJSON(ctl, f)
var req string
if tlsreq == nil {
req = ""
@ -320,7 +388,7 @@ func ctlcmdQueueRequireTLS(ctl *ctl, f queue.Filter, tlsreq *bool) {
ctl.xwrite(req)
line := ctl.xread()
if line == "ok" {
fmt.Printf("%s messages changed\n", ctl.xread())
fmt.Printf("%s message(s) changed\n", ctl.xread())
} else {
log.Fatalf("%s", line)
}
@ -335,7 +403,7 @@ delivery attempts failed. The DSN (delivery status notification) message
contains a line saying the message was canceled by the admin.
`
var f queue.Filter
flagFilter(c.flag, &f)
flagFilterSort(c.flag, &f, nil)
if len(c.Parse()) != 0 {
c.Usage()
}
@ -345,10 +413,10 @@ contains a line saying the message was canceled by the admin.
func ctlcmdQueueFail(ctl *ctl, f queue.Filter) {
ctl.xwrite("queuefail")
xctlwritequeuefilter(ctl, f)
xctlwriteJSON(ctl, f)
line := ctl.xread()
if line == "ok" {
fmt.Printf("%s messages marked as failed\n", ctl.xread())
fmt.Printf("%s message(s) marked as failed\n", ctl.xread())
} else {
log.Fatalf("%s", line)
}
@ -362,7 +430,7 @@ Dangerous operation, this completely removes the message. If you want to store
the message, use "queue dump" before removing.
`
var f queue.Filter
flagFilter(c.flag, &f)
flagFilterSort(c.flag, &f, nil)
if len(c.Parse()) != 0 {
c.Usage()
}
@ -372,10 +440,10 @@ the message, use "queue dump" before removing.
func ctlcmdQueueDrop(ctl *ctl, f queue.Filter) {
ctl.xwrite("queuedrop")
xctlwritequeuefilter(ctl, f)
xctlwriteJSON(ctl, f)
line := ctl.xread()
if line == "ok" {
fmt.Printf("%s messages dropped\n", ctl.xread())
fmt.Printf("%s message(s) dropped\n", ctl.xread())
} else {
log.Fatalf("%s", line)
}
@ -403,3 +471,381 @@ func ctlcmdQueueDump(ctl *ctl, id string) {
log.Fatalf("%s", err)
}
}
func cmdQueueSuppressList(c *cmd) {
c.params = "[-account account]"
c.help = `Print addresses in suppression list.`
var account string
c.flag.StringVar(&account, "account", "", "only show suppression list for this account")
args := c.Parse()
if len(args) != 0 {
c.Usage()
}
mustLoadConfig()
ctlcmdQueueSuppressList(xctl(), account)
}
func ctlcmdQueueSuppressList(ctl *ctl, account string) {
ctl.xwrite("queuesuppresslist")
ctl.xwrite(account)
ctl.xreadok()
if _, err := io.Copy(os.Stdout, ctl.reader()); err != nil {
log.Fatalf("%s", err)
}
}
func cmdQueueSuppressAdd(c *cmd) {
c.params = "account address"
c.help = `Add address to suppression list for account.`
args := c.Parse()
if len(args) != 2 {
c.Usage()
}
mustLoadConfig()
ctlcmdQueueSuppressAdd(xctl(), args[0], args[1])
}
func ctlcmdQueueSuppressAdd(ctl *ctl, account, address string) {
ctl.xwrite("queuesuppressadd")
ctl.xwrite(account)
ctl.xwrite(address)
ctl.xreadok()
}
func cmdQueueSuppressRemove(c *cmd) {
c.params = "account address"
c.help = `Remove address from suppression list for account.`
args := c.Parse()
if len(args) != 2 {
c.Usage()
}
mustLoadConfig()
ctlcmdQueueSuppressRemove(xctl(), args[0], args[1])
}
func ctlcmdQueueSuppressRemove(ctl *ctl, account, address string) {
ctl.xwrite("queuesuppressremove")
ctl.xwrite(account)
ctl.xwrite(address)
ctl.xreadok()
}
func cmdQueueSuppressLookup(c *cmd) {
c.params = "[-account account] address"
c.help = `Check if address is present in suppression list, for any or specific account.`
var account string
c.flag.StringVar(&account, "account", "", "only check address in specified account")
args := c.Parse()
if len(args) != 1 {
c.Usage()
}
mustLoadConfig()
ctlcmdQueueSuppressLookup(xctl(), account, args[0])
}
func ctlcmdQueueSuppressLookup(ctl *ctl, account, address string) {
ctl.xwrite("queuesuppresslookup")
ctl.xwrite(account)
ctl.xwrite(address)
ctl.xreadok()
if _, err := io.Copy(os.Stdout, ctl.reader()); err != nil {
log.Fatalf("%s", err)
}
}
func cmdQueueRetiredList(c *cmd) {
c.params = "[filtersortflags]"
c.help = `List matching messages in the retired queue.
Prints messages with their ID and results.
`
var f queue.RetiredFilter
var s queue.RetiredSort
flagRetiredFilterSort(c.flag, &f, &s)
if len(c.Parse()) != 0 {
c.Usage()
}
mustLoadConfig()
ctlcmdQueueRetiredList(xctl(), f, s)
}
func ctlcmdQueueRetiredList(ctl *ctl, f queue.RetiredFilter, s queue.RetiredSort) {
ctl.xwrite("queueretiredlist")
xctlwriteJSON(ctl, f)
xctlwriteJSON(ctl, s)
ctl.xreadok()
if _, err := io.Copy(os.Stdout, ctl.reader()); err != nil {
log.Fatalf("%s", err)
}
}
func cmdQueueRetiredPrint(c *cmd) {
c.params = "id"
c.help = `Print a message from the retired queue.
Prints a JSON representation of the information from the retired queue.
`
args := c.Parse()
if len(args) != 1 {
c.Usage()
}
mustLoadConfig()
ctlcmdQueueRetiredPrint(xctl(), args[0])
}
func ctlcmdQueueRetiredPrint(ctl *ctl, id string) {
ctl.xwrite("queueretiredprint")
ctl.xwrite(id)
ctl.xreadok()
if _, err := io.Copy(os.Stdout, ctl.reader()); err != nil {
log.Fatalf("%s", err)
}
}
// note: outgoing hook events are in queue/hooks.go, mox-/config.go, queue.go and webapi/gendoc.sh. keep in sync.
// flagHookFilterSort is used by many of the queue commands to accept flags for
// filtering the webhooks the operation applies to.
func flagHookFilterSort(fs *flag.FlagSet, f *queue.HookFilter, s *queue.HookSort) {
fs.Func("ids", "comma-separated list of webhook IDs", func(v string) error {
for _, s := range strings.Split(v, ",") {
id, err := strconv.ParseInt(s, 10, 64)
if err != nil {
return err
}
f.IDs = append(f.IDs, id)
}
return nil
})
fs.IntVar(&f.Max, "n", 0, "number of webhooks to return")
fs.StringVar(&f.Account, "account", "", "account that queued the message/webhook")
fs.StringVar(&f.Submitted, "submitted", "", `filter by time of submission relative to now, value must start with "<" (before now) or ">" (after now)`)
fs.StringVar(&f.NextAttempt, "nextattempt", "", `filter by time of next delivery attempt relative to now, value must start with "<" (before now) or ">" (after now)`)
fs.Func("event", `event this webhook is about: incoming, delivered, suppressed, delayed, failed, relayed, expanded, canceled, unrecognized`, func(v string) error {
switch v {
case "incoming", "delivered", "suppressed", "delayed", "failed", "relayed", "expanded", "canceled", "unrecognized":
f.Event = v
default:
return fmt.Errorf("invalid parameter %q", v)
}
return nil
})
if s != nil {
fs.Func("sort", `field to sort by, "nextattempt" (default) or "queued"`, func(v string) error {
switch v {
case "nextattempt":
s.Field = "NextAttempt"
case "queued":
s.Field = "Queued"
default:
return fmt.Errorf("unknown value %q", v)
}
return nil
})
fs.BoolVar(&s.Asc, "asc", false, "sort ascending instead of descending (default)")
}
}
// flagHookRetiredFilterSort is used by many of the queue commands to accept flags
// for filtering the webhooks the operation applies to.
func flagHookRetiredFilterSort(fs *flag.FlagSet, f *queue.HookRetiredFilter, s *queue.HookRetiredSort) {
fs.Func("ids", "comma-separated list of retired webhook IDs", func(v string) error {
for _, s := range strings.Split(v, ",") {
id, err := strconv.ParseInt(s, 10, 64)
if err != nil {
return err
}
f.IDs = append(f.IDs, id)
}
return nil
})
fs.IntVar(&f.Max, "n", 0, "number of webhooks to return")
fs.StringVar(&f.Account, "account", "", "account that queued the message/webhook")
fs.StringVar(&f.Submitted, "submitted", "", `filter by time of submission relative to now, value must start with "<" (before now) or ">" (after now)`)
fs.StringVar(&f.LastActivity, "lastactivity", "", `filter by time of last activity relative to now, value must start with "<" (before now) or ">" (after now)`)
fs.Func("event", `event this webhook is about: incoming, delivered, suppressed, delayed, failed, relayed, expanded, canceled, unrecognized`, func(v string) error {
switch v {
case "incoming", "delivered", "suppressed", "delayed", "failed", "relayed", "expanded", "canceled", "unrecognized":
f.Event = v
default:
return fmt.Errorf("invalid parameter %q", v)
}
return nil
})
if s != nil {
fs.Func("sort", `field to sort by, "lastactivity" (default) or "queued"`, func(v string) error {
switch v {
case "lastactivity":
s.Field = "LastActivity"
case "queued":
s.Field = "Queued"
default:
return fmt.Errorf("unknown value %q", v)
}
return nil
})
fs.BoolVar(&s.Asc, "asc", false, "sort ascending instead of descending (default)")
}
}
func cmdQueueHookList(c *cmd) {
c.params = "[filtersortflags]"
c.help = `List matching webhooks in the queue.
Prints list of webhooks, their IDs and basic information.
`
var f queue.HookFilter
var s queue.HookSort
flagHookFilterSort(c.flag, &f, &s)
if len(c.Parse()) != 0 {
c.Usage()
}
mustLoadConfig()
ctlcmdQueueHookList(xctl(), f, s)
}
func ctlcmdQueueHookList(ctl *ctl, f queue.HookFilter, s queue.HookSort) {
ctl.xwrite("queuehooklist")
xctlwriteJSON(ctl, f)
xctlwriteJSON(ctl, s)
ctl.xreadok()
if _, err := io.Copy(os.Stdout, ctl.reader()); err != nil {
log.Fatalf("%s", err)
}
}
func cmdQueueHookSchedule(c *cmd) {
c.params = "[filterflags] duration"
c.help = `Change next delivery attempt for matching webhooks.
The next delivery attempt is adjusted by the duration parameter. If the -now
flag is set, the new delivery attempt is set to the duration added to the
current time, instead of added to the current scheduled time.
Schedule immediate delivery with "mox queue schedule -now 0".
`
var fromNow bool
c.flag.BoolVar(&fromNow, "now", false, "schedule for duration relative to current time instead of relative to current next delivery attempt for webhooks")
var f queue.HookFilter
flagHookFilterSort(c.flag, &f, nil)
args := c.Parse()
if len(args) != 1 {
c.Usage()
}
d, err := time.ParseDuration(args[0])
xcheckf(err, "parsing duration %q", args[0])
mustLoadConfig()
ctlcmdQueueHookSchedule(xctl(), f, fromNow, d)
}
func ctlcmdQueueHookSchedule(ctl *ctl, f queue.HookFilter, fromNow bool, d time.Duration) {
ctl.xwrite("queuehookschedule")
xctlwriteJSON(ctl, f)
if fromNow {
ctl.xwrite("yes")
} else {
ctl.xwrite("")
}
ctl.xwrite(d.String())
line := ctl.xread()
if line == "ok" {
fmt.Printf("%s webhook(s) rescheduled\n", ctl.xread())
} else {
log.Fatalf("%s", line)
}
}
func cmdQueueHookCancel(c *cmd) {
c.params = "[filterflags]"
c.help = `Fail delivery of matching webhooks.`
var f queue.HookFilter
flagHookFilterSort(c.flag, &f, nil)
if len(c.Parse()) != 0 {
c.Usage()
}
mustLoadConfig()
ctlcmdQueueHookCancel(xctl(), f)
}
func ctlcmdQueueHookCancel(ctl *ctl, f queue.HookFilter) {
ctl.xwrite("queuehookcancel")
xctlwriteJSON(ctl, f)
line := ctl.xread()
if line == "ok" {
fmt.Printf("%s webhook(s)s marked as canceled\n", ctl.xread())
} else {
log.Fatalf("%s", line)
}
}
func cmdQueueHookPrint(c *cmd) {
c.params = "id"
c.help = `Print details of a webhook from the queue.
The webhook is printed to stdout as JSON.
`
args := c.Parse()
if len(args) != 1 {
c.Usage()
}
mustLoadConfig()
ctlcmdQueueHookPrint(xctl(), args[0])
}
func ctlcmdQueueHookPrint(ctl *ctl, id string) {
ctl.xwrite("queuehookprint")
ctl.xwrite(id)
ctl.xreadok()
if _, err := io.Copy(os.Stdout, ctl.reader()); err != nil {
log.Fatalf("%s", err)
}
}
func cmdQueueHookRetiredList(c *cmd) {
c.params = "[filtersortflags]"
c.help = `List matching webhooks in the retired queue.
Prints list of retired webhooks, their IDs and basic information.
`
var f queue.HookRetiredFilter
var s queue.HookRetiredSort
flagHookRetiredFilterSort(c.flag, &f, &s)
if len(c.Parse()) != 0 {
c.Usage()
}
mustLoadConfig()
ctlcmdQueueHookRetiredList(xctl(), f, s)
}
func ctlcmdQueueHookRetiredList(ctl *ctl, f queue.HookRetiredFilter, s queue.HookRetiredSort) {
ctl.xwrite("queuehookretiredlist")
xctlwriteJSON(ctl, f)
xctlwriteJSON(ctl, s)
ctl.xreadok()
if _, err := io.Copy(os.Stdout, ctl.reader()); err != nil {
log.Fatalf("%s", err)
}
}
func cmdQueueHookRetiredPrint(c *cmd) {
c.params = "id"
c.help = `Print details of a webhook from the retired queue.
The retired webhook is printed to stdout as JSON.
`
args := c.Parse()
if len(args) != 1 {
c.Usage()
}
mustLoadConfig()
ctlcmdQueueHookRetiredPrint(xctl(), args[0])
}
func ctlcmdQueueHookRetiredPrint(ctl *ctl, id string) {
ctl.xwrite("queuehookretiredprint")
ctl.xwrite(id)
ctl.xreadok()
if _, err := io.Copy(os.Stdout, ctl.reader()); err != nil {
log.Fatalf("%s", err)
}
}