auditlog

package
v0.1.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 31, 2020 License: MIT Imports: 10 Imported by: 0

README

auditlog

godoc

A Go package to send audit logs events to WorkOS.

Install

go get -u github.com/workos-inc/workos-go/pkg/auditlog

How it works

package main

import "github.com/workos-inc/workos-go/pkg/auditlog"

func main() {
    auditlog.SetAPIKey("my_api_key")

    // Wherever you need to publish an audit log event:
    err := auditlog.Publish(ctx.Background(), auditlog.Event{
        Action:     "document.viewed",
        ActionType: auditlog.Create,
        ActorName:  "Jairo Kunde",
        ActorID:    "user_01DGZ0FAXN978HCET66Q98QMTQ",
        Group:      "abstract.com",
        Location:   "55.27.223.26",
        OccurredAt: time.Now(),
        TargetName: "central.class",
        TargetID:   "doc_01DGZ0FAXP4HA4X0BVFKS0ZH4Y",
    })
    if err != nil {
        // Handle error.
    }
}

Documentation

Overview

Package auditlog is a package to send audit logs events to WorkOS.

Example:

func main() {
    auditlog.SetAPIKey("my_api_key")

    // Wherever you need to publish an audit log event:
    err := auditlog.Publish(context.Background(), auditlog.Event{
        Action:     "document.viewed",
        ActionType: auditlog.Create,
        ActorName:  "Jairo Kunde",
        ActorID:    "user_01DGZ0FAXN978HCET66Q98QMTQ",
        Group:      "abstract.com",
        Location:   "55.27.223.26",
        OccurredAt: time.Now(),
        TargetName: "central.class",
        TargetID:   "doc_01DGZ0FAXP4HA4X0BVFKS0ZH4Y",
    })
    if err != nil {
        // Handle error.
    }
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Publish

func Publish(ctx context.Context, e Event) error

Publish publishes the given event.

func SetAPIKey

func SetAPIKey(k string)

SetAPIKey sets the WorkOS API key to use when using Publish.

Types

type ActionType

type ActionType string

ActionType is the type that holds the CRUD action used for the WorkOS Audit Log.

const (
	Create ActionType = "C"
	Read   ActionType = "R"
	Update ActionType = "U"
	Delete ActionType = "D"
)

Constants that enumerate the different action types.

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. Defaults to
	// https://api.workos.com/events.
	Endpoint 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 auditlog request to WorkOS API.

func (*Client) Publish

func (c *Client) Publish(ctx context.Context, e Event) error

Publish publishes the given event.

type Event

type Event struct {
	Action     string     `json:"action"`
	ActionType ActionType `json:"action_type"`
	ActorName  string     `json:"actor_name"`
	ActorID    string     `json:"actor_id"`
	Group      string     `json:"group"`

	// If no key is provided or the key is empty, the key will not be attached
	// to the request.
	IdempotencyKey string `json:"-"`

	// An ip address that locates where the audit log occurred.
	Location string `json:"location"`

	// The event metadata. It can't contain more than 50 keys. A key can't
	// exeed 40 characters.
	Metadata Metadata `json:"metadata,omitempty"`

	// The time when the audit log occurred.
	//
	// Defaults to time.Now().
	OccurredAt time.Time `json:"occurred_at"`

	TargetName string `json:"target_name"`
	TargetID   string `json:"target_id"`
}

Event represents an Audit Log event.

type Metadata

type Metadata map[string]interface{}

Metadata represents metadata to be attached to an audit log event.

var (
	// DefaultClient is the client used by SetAPIKey and Publish functions.
	DefaultClient = &Client{
		APIKey:   os.Getenv("WORKOS_API_KEY"),
		Endpoint: "https://api.workos.com/events",
	}

	// GlobalMetadata are metadata that are injected in every audit log events.
	GlobalMetadata Metadata
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL