forked from openfaas/faas-provider
/
system_events.go
52 lines (44 loc) · 1.44 KB
/
system_events.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
package types
import "time"
const (
TypeFunctionUsage = "function_usage"
TypeAPIAccess = "api_access"
)
type Event interface {
EventType() string
}
type FunctionUsageEvent struct {
Namespace string `json:"namespace"`
FunctionName string `json:"function_name"`
Started time.Time `json:"started"`
Duration time.Duration `json:"duration"`
MemoryBytes int64 `json:"memory_bytes"`
}
func (e FunctionUsageEvent) EventType() string {
return TypeFunctionUsage
}
type APIAccessEvent struct {
Actor *Actor `json:"actor,omitempty"`
Path string `json:"path"`
Method string `json:"method"`
Actions []string `json:"actions"`
ResponseCode int `json:"response_code"`
CustomMessage string `json:"custom_message,omitempty"`
Namespace string `json:"namespace,omitempty"`
Time time.Time `json:"time"`
}
func (e APIAccessEvent) EventType() string {
return TypeAPIAccess
}
// Actor is the user that triggered an event.
// Get from OIDC claims, we can add any of the default OIDC profile or email claim fields if desired.
type Actor struct {
// OIDC subject, a unique identifier of the user.
Sub string `json:"sub"`
// Full name of the subject, can be the name of a user of OpenFaaS component.
Name string `json:"name,omitempty"`
// OpenFaaS issuer
Issuer string `json:"issuer,omitempty"`
// Federated issuer
FedIssuer string `json:"fed_issuer,omitempty"`
}