Documentation ¶
Overview ¶
Package `auditlogs` provides a client wrapping the WorkOS Audit Logs API.
Example:
func main() { auditlogs.SetAPIKey("my_api_key") // Wherever you need to publish an audit log event: err := auditlogs.CreateEvent(context.Background(), auditlogs.CreateEventOpts{ OrganizationID: "org_8899300049990088", Event: Event{ Action: "team.created", Actor: Actor{ ID: "o5fdfsdfUMCAuunNN3Iwfs34gMw", Name: "jonatas", Type: "user", Metadata: map[string]interface{}{ "Email": "person@workos.com", }, }, Context: Context{ Location: "79.226.116.209", }, Targets: []Target{ Target{ID: "team_123", Type: "team"}, }, }, IdempotencyKey: uuid.New().String(), }) if err != nil { // Handle error. } }
Index ¶
- Constants
- Variables
- func CreateEvent(ctx context.Context, e CreateEventOpts) error
- func SetAPIKey(k string)
- type Actor
- type AuditLogExport
- type AuditLogExportObject
- type AuditLogExportState
- type Client
- type Context
- type CreateEventOpts
- type CreateExportOpts
- type Event
- type GetExportOpts
- type Order
- type Target
Constants ¶
const ResponseLimit = 10
ResponseLimit is the default number of records to limit a response to.
Variables ¶
var ( // DefaultClient is the client used by SetAPIKey and Publish functions. DefaultClient = &Client{ EventsEndpoint: "https://api.workos.com/audit_logs/events", ExportsEndpoint: "https://api.workos.com/audit_logs/exports", } )
Functions ¶
func CreateEvent ¶
func CreateEvent(ctx context.Context, e CreateEventOpts) error
CreateEvent creates the given event.
Types ¶
type Actor ¶
type Actor struct { ID string `json:"id"` Name string `json:"name"` Type string `json:"type"` Metadata map[string]interface{} `json:"metadata,omitempty"` }
Actor describes the entity that generated the event
type AuditLogExport ¶
type AuditLogExport struct { // Object will always be set to 'audit_log_export' Object AuditLogExportObject `json:"object"` // AuditLogExport identifier ID string `json:"id"` // State is the active state of AuditLogExport State AuditLogExportState `json:"state"` // URL for downloading the exported logs URL string `json:"url"` // AuditLogExport's created at date CreatedAt string `json:"created_at"` // AuditLogExport's updated at date UpdatedAt string `json:"updated_at"` }
func CreateExport ¶
func CreateExport(ctx context.Context, e CreateExportOpts) (AuditLogExport, error)
CreateEvent creates the given event.
func GetExport ¶
func GetExport(ctx context.Context, e GetExportOpts) (AuditLogExport, error)
CreateEvent creates the given event.
type AuditLogExportObject ¶
type AuditLogExportObject string
const AuditLogExportObjectName AuditLogExportObject = "audit_log_export"
type AuditLogExportState ¶
type AuditLogExportState string
AuditLogExportState represents the active state of an AuditLogExport.
const ( Ready AuditLogExportState = "Ready" Pending AuditLogExportState = "Pending" Error AuditLogExportState = "Error" )
Constants that enumerate the state of a AuditLogExport.
type Client ¶
type Client struct { // The WorkOS API key. It can be found in // https://dashboard.workos.com/api-keys. APIKey string // The http.Client that is used to post Audit Log events to WorkOS. Defaults // to http.Client. HTTPClient *http.Client // The endpoint used to request WorkOS AuditLog events creation endpoint. // Defaults to https://api.workos.com/audit_logs/events. EventsEndpoint string // The endpoint used to request WorkOS AuditLog events creation endpoint. // Defaults to https://api.workos.com/audit_logs/exports. ExportsEndpoint string // The function used to encode in JSON. Defaults to json.Marshal. JSONEncode func(v interface{}) ([]byte, error) // contains filtered or unexported fields }
Client represents a client that performs auditlogs requests to WorkOS API.
func (*Client) CreateEvent ¶
func (c *Client) CreateEvent(ctx context.Context, e CreateEventOpts) error
CreateEvent creates an Audit Log event.
func (*Client) CreateExport ¶
func (c *Client) CreateExport(ctx context.Context, e CreateExportOpts) (AuditLogExport, error)
CreateExport creates an export of Audit Log events. You can specify some filters.
func (*Client) GetExport ¶
func (c *Client) GetExport(ctx context.Context, e GetExportOpts) (AuditLogExport, error)
GetExport retrieves an export of Audit Log events
type Context ¶
type Context struct { // Place from where the event is fired Location string `json:"location"` // User Agent identity information of the event actor UserAgent string `json:"user_agent"` }
Context describes the event location and user agent
type CreateEventOpts ¶
type CreateEventOpts struct { // Organization identifier OrganizationID string `json:"organization_id" binding:"required"` // Event payload Event Event `json:"event" binding:"required"` // If no key is provided or the key is empty, the key will not be attached // to the request. IdempotencyKey string `json:"-"` }
CreateEventOpts represents arguments to create an Audit Logs event.
type CreateExportOpts ¶
type CreateExportOpts struct { // Organization identifier OrganizationID string `json:"organization_id"` // ISO-8601 start datetime the date range filter RangeStart string `json:"range_start"` // ISO-8601 start datetime the date range filter RangeEnd string `json:"range_end"` // Optional list of actions to filter Actions []string `json:"actions,omitempty"` // Optional list of actors to filter Actors []string `json:"actors,omitempty"` // Optional list of targets to filter Targets []string `json:"targets,omitempty"` }
type Event ¶
type Event struct { // Represents the activity performed by the actor. Action string `json:"action"` // The schema version of the event Version int `json:"version,omitempty"` // The time when the audit trail occurred. // Defaults to time.Now(). OccurredAt time.Time `json:"occurred_at"` // Describes the entity that generated the event Actor Actor `json:"actor"` // List of event target Targets []Target `json:"targets"` // Attributes of event context Context Context `json:"context"` // Event metadata. Metadata map[string]interface{} `json:"metadata,omitempty"` }
type GetExportOpts ¶
type GetExportOpts struct {
ExportID string `json:"export_id" binding:"required"`
}