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.AuditLogEventOpts{
Organization: "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 ¶
View Source
const ResponseLimit = 10
ResponseLimit is the default number of records to limit a response to.
Variables ¶
View Source
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 AuditLogEventOpts) 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 AuditLogEventOpts ¶
type AuditLogEventOpts struct {
// Organization identifier
Organization 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:"-"`
}
AuditLogEventOpts represents arguments to create an Audit Logs event.
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 AuditLogEventOpts) error
CreateEvent creates an Audit Log event.
func (*Client) CreateExport ¶
func (c *Client) CreateExport(ctx context.Context, e CreateExportOpts) (CreateExportResponse, 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) (GetExportResponse, 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 CreateExportOpts ¶
type CreateExportOpts struct {
// Organization identifier
Organization 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 CreateExportResponse ¶
type CreateExportResponse struct {
Object string `json:"object"`
Id string `json:"id"`
State string `json:"state"`
Url string `json:"url"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
}
func CreateExport ¶
func CreateExport(ctx context.Context, e CreateExportOpts) (CreateExportResponse, error)
CreateEvent creates the given event.
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"`
}
type GetExportResponse ¶
type GetExportResponse struct {
Object string `json:"object"`
Id string `json:"id"`
State string `json:"state"`
Url string `json:"url"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
}
func GetExport ¶
func GetExport(ctx context.Context, e GetExportOpts) (GetExportResponse, error)
CreateEvent creates the given event.
Click to show internal directories.
Click to hide internal directories.