-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
api.go
109 lines (92 loc) · 3.36 KB
/
api.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*
Copyright 2021 Gravitational, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Package events contains event related types and logic required by the Teleport API.
package events
import (
"context"
"time"
)
// ProtoMarshaler implements marshaler interface
type ProtoMarshaler interface {
// Size returns size of the object when marshaled
Size() (n int)
// MarshalTo marshals the object to sized buffer
MarshalTo(dAtA []byte) (int, error)
}
// AuditEvent represents an audit event.
type AuditEvent interface {
// ProtoMarshaler implements efficient
// protobuf marshaling methods
ProtoMarshaler
// GetID returns unique event ID
GetID() string
// SetID sets unique event ID
SetID(id string)
// GetCode returns event short diagnostic code
GetCode() string
// SetCode sets unique event diagnostic code
SetCode(string)
// GetType returns event type
GetType() string
// SetType sets unique type
SetType(string)
// GetTime returns event time
GetTime() time.Time
// SetTime sets event time
SetTime(time.Time)
// GetIndex gets event index - a non-unique
// monotonically incremented number
// in the event sequence
GetIndex() int64
// SetIndex sets event index
SetIndex(idx int64)
// GetClusterName returns the name of the teleport cluster
// as set on the event.
GetClusterName() string
// SetClusterName sets the name of the teleport cluster on the event.
SetClusterName(string)
}
// Emitter emits audit events.
type Emitter interface {
// EmitAuditEvent emits a single audit event.
//
// NOTE: when implementing this interface, the context should have
// its cancel stripped via `context.WithoutCancel`
EmitAuditEvent(context.Context, AuditEvent) error
}
// PreparedSessionEvent is an event that has been prepared by
// a [github.com/gravitational/teleport/lib/events.SessionEventPreparer].
// More specifically, it is a wrapper around an AuditEvent that signifies
// the event has been prepared and is ready to be recorded or emitted.
type PreparedSessionEvent interface {
GetAuditEvent() AuditEvent
}
// Stream is used to create continuous ordered sequence of events
// associated with a session.
type Stream interface {
// RecordEvent records a single session event if session recording is enabled.
RecordEvent(ctx context.Context, event PreparedSessionEvent) error
// Status returns channel broadcasting updates about the stream state:
// last event index that was uploaded and the upload ID
Status() <-chan StreamStatus
// Done returns channel closed when streamer is closed
// should be used to detect sending errors
Done() <-chan struct{}
// Complete closes the stream and marks it finalized,
// releases associated resources, in case of failure,
// closes this stream on the client side
Complete(ctx context.Context) error
// Close flushes non-uploaded flight stream data without marking
// the stream completed and closes the stream instance
Close(ctx context.Context) error
}