-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add system event types from event-worker
These types are for auditing and billing metrics Signed-off-by: Alex Ellis (OpenFaaS Ltd) <[email protected]>
- Loading branch information
Showing
1 changed file
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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"` | ||
} |