mirror of
https://github.com/kemko/nomad.git
synced 2026-01-06 10:25:42 +03:00
Add event sink API and CLI commands (#9226)
Co-authored-by: Drew Bailey <2614075+drewbailey@users.noreply.github.com>
This commit is contained in:
57
vendor/github.com/hashicorp/nomad/api/event_sink.go
generated
vendored
Normal file
57
vendor/github.com/hashicorp/nomad/api/event_sink.go
generated
vendored
Normal file
@@ -0,0 +1,57 @@
|
||||
package api
|
||||
|
||||
import "sort"
|
||||
|
||||
type SinkType string
|
||||
|
||||
const (
|
||||
SinkWebhook SinkType = "webhook"
|
||||
)
|
||||
|
||||
type EventSink struct {
|
||||
ID string
|
||||
Type SinkType
|
||||
|
||||
Topics map[Topic][]string
|
||||
|
||||
Address string
|
||||
|
||||
// LatestIndex is the latest reported index that was successfully sent.
|
||||
// MangedSinks periodically check in to update the LatestIndex so that a
|
||||
// minimal amount of events are resent when reestablishing an event sink
|
||||
LatestIndex uint64
|
||||
|
||||
CreateIndex uint64
|
||||
ModifyIndex uint64
|
||||
}
|
||||
|
||||
type EventSinks struct {
|
||||
client *Client
|
||||
}
|
||||
|
||||
func (c *Client) EventSinks() *EventSinks {
|
||||
return &EventSinks{client: c}
|
||||
}
|
||||
|
||||
func (e *EventSinks) List(q *QueryOptions) ([]*EventSink, *QueryMeta, error) {
|
||||
var resp []*EventSink
|
||||
qm, err := e.client.query("/v1/event/sinks", &resp, q)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
sort.Slice(resp, func(i, j int) bool { return resp[i].ID < resp[j].ID })
|
||||
return resp, qm, nil
|
||||
}
|
||||
|
||||
func (e *EventSinks) Register(eventSink *EventSink, w *WriteOptions) (*WriteMeta, error) {
|
||||
wm, err := e.client.write("/v1/event/sink/"+eventSink.ID, eventSink, nil, w)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return wm, nil
|
||||
}
|
||||
|
||||
func (e *EventSinks) Deregister(name string, w *WriteOptions) (*WriteMeta, error) {
|
||||
return e.client.delete("/v1/event/sink/"+name, nil, w)
|
||||
}
|
||||
Reference in New Issue
Block a user