event

package
v0.60.1 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2023 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DateFormatMessage = "Must be an integer specifying a unix timestamp in microseconds"
	SinceErrorMessage = "Must be a date occurring before the until date"
)
View Source
const (
	DefaultEpochMicroseconds  = 1136160000000
	QueryParamType            = "type"
	QueryParamSource          = "source"
	QueryParamResourceType    = "resourceType"
	QueryParamResourceId      = "resourceId"
	QueryParamLastId          = "lastId"
	QueryParamSince           = "since"
	QueryParamUntil           = "until"
	QueryParamObjectType      = "objectType"
	QueryParamObjectId        = "objectId"
	QueryParamRelation        = "relation"
	QueryParamSubjectType     = "subjectType"
	QueryParamSubjectId       = "subjectId"
	QueryParamSubjectRelation = "subjectRelation"
)
View Source
const (
	EventSourceApi         = "api"
	EventTypeAccessAllowed = "access_allowed"
	EventTypeAccessDenied  = "access_denied"
	EventTypeAccessGranted = "access_granted"
	EventTypeAccessRevoked = "access_revoked"
	EventTypeCreated       = "created"
	EventTypeDeleted       = "deleted"
	EventTypeUpdated       = "updated"
)
View Source
const DateFormatRFC3339Micro = "2006-01-02T15:04:05.999999Z07:00"

Variables

This section is empty.

Functions

This section is empty.

Types

type AccessEvent

type AccessEvent struct {
	ID              string    `mysql:"id" postgres:"id" sqlite:"id"`
	Type            string    `mysql:"type" postgres:"type" sqlite:"type"`
	Source          string    `mysql:"source" postgres:"source" sqlite:"source"`
	ObjectType      string    `mysql:"objectType" postgres:"object_type" sqlite:"objectType"`
	ObjectId        string    `mysql:"objectId" postgres:"object_id" sqlite:"objectId"`
	Relation        string    `mysql:"relation" postgres:"relation" sqlite:"relation"`
	SubjectType     string    `mysql:"subjectType" postgres:"subject_type" sqlite:"subjectType"`
	SubjectId       string    `mysql:"subjectId" postgres:"subject_id" sqlite:"subjectId"`
	SubjectRelation string    `mysql:"subjectRelation" postgres:"subject_relation" sqlite:"subjectRelation"`
	Meta            *string   `mysql:"meta" postgres:"meta" sqlite:"meta"`
	CreatedAt       time.Time `mysql:"createdAt" postgres:"created_at" sqlite:"createdAt"`
}

func NewAccessEventFromModel added in v0.8.0

func NewAccessEventFromModel(model AccessEventModel) *AccessEvent

func (AccessEvent) GetCreatedAt added in v0.8.0

func (accessEvent AccessEvent) GetCreatedAt() time.Time

func (AccessEvent) GetID added in v0.8.0

func (accessEvent AccessEvent) GetID() string

func (AccessEvent) GetMeta added in v0.8.0

func (accessEvent AccessEvent) GetMeta() *string

func (AccessEvent) GetObjectId added in v0.8.0

func (accessEvent AccessEvent) GetObjectId() string

func (AccessEvent) GetObjectType added in v0.8.0

func (accessEvent AccessEvent) GetObjectType() string

func (AccessEvent) GetRelation added in v0.8.0

func (accessEvent AccessEvent) GetRelation() string

func (AccessEvent) GetSource added in v0.8.0

func (accessEvent AccessEvent) GetSource() string

func (AccessEvent) GetSubjectId added in v0.8.0

func (accessEvent AccessEvent) GetSubjectId() string

func (AccessEvent) GetSubjectRelation added in v0.8.0

func (accessEvent AccessEvent) GetSubjectRelation() string

func (AccessEvent) GetSubjectType added in v0.8.0

func (accessEvent AccessEvent) GetSubjectType() string

func (AccessEvent) GetType added in v0.8.0

func (accessEvent AccessEvent) GetType() string

func (AccessEvent) ToAccessEventSpec

func (accessEvent AccessEvent) ToAccessEventSpec() (*AccessEventSpec, error)

type AccessEventFilterParams added in v0.58.0

type AccessEventFilterParams struct {
	Type            string
	Source          string
	ObjectType      string
	ObjectId        string
	Relation        string
	SubjectType     string
	SubjectId       string
	SubjectRelation string
	Since           time.Time
	Until           time.Time
}

type AccessEventListParamParser added in v0.58.0

type AccessEventListParamParser struct{}

func (AccessEventListParamParser) GetDefaultSortBy added in v0.58.0

func (parser AccessEventListParamParser) GetDefaultSortBy() string

func (AccessEventListParamParser) GetSupportedSortBys added in v0.58.0

func (parser AccessEventListParamParser) GetSupportedSortBys() []string

func (AccessEventListParamParser) ParseValue added in v0.58.0

func (parser AccessEventListParamParser) ParseValue(val string, sortBy string) (interface{}, error)

type AccessEventModel added in v0.8.0

type AccessEventModel interface {
	GetID() string
	GetType() string
	GetSource() string
	GetObjectType() string
	GetObjectId() string
	GetRelation() string
	GetSubjectType() string
	GetSubjectId() string
	GetSubjectRelation() string
	GetMeta() *string
	GetCreatedAt() time.Time
	ToAccessEventSpec() (*AccessEventSpec, error)
}

type AccessEventSpec

type AccessEventSpec struct {
	ID              string      `json:"id"`
	Type            string      `json:"type"`
	Source          string      `json:"source"`
	ObjectType      string      `json:"objectType"`
	ObjectId        string      `json:"objectId"`
	Relation        string      `json:"relation"`
	SubjectType     string      `json:"subjectType"`
	SubjectId       string      `json:"subjectId"`
	SubjectRelation string      `json:"subjectRelation,omitempty"`
	Meta            interface{} `json:"meta,omitempty"`
	CreatedAt       time.Time   `json:"createdAt"`
}

type CreateAccessEventSpec

type CreateAccessEventSpec struct {
	Type            string      `json:"type"`
	Source          string      `json:"source"`
	ObjectType      string      `json:"objectType"`
	ObjectId        string      `json:"objectId"`
	Relation        string      `json:"relation"`
	SubjectType     string      `json:"subjectType"`
	SubjectId       string      `json:"subjectId"`
	SubjectRelation string      `json:"subjectRelation"`
	Meta            interface{} `json:"meta"`
}

func (CreateAccessEventSpec) ToAccessEvent

func (spec CreateAccessEventSpec) ToAccessEvent() (*AccessEvent, error)

type CreateResourceEventSpec

type CreateResourceEventSpec struct {
	Type         string      `json:"type"`
	Source       string      `json:"source"`
	ResourceType string      `json:"resourceType"`
	ResourceId   string      `json:"resourceId"`
	Meta         interface{} `json:"meta"`
}

func (CreateResourceEventSpec) ToResourceEvent

func (spec CreateResourceEventSpec) ToResourceEvent() (*ResourceEvent, error)

type EventContextFunc added in v0.13.0

type EventContextFunc func(ctx context.Context, synchronizeEvents bool) (context.Context, error)

type EventRepository

type EventRepository interface {
	TrackResourceEvent(ctx context.Context, resourceEvent ResourceEventModel) error
	TrackResourceEvents(ctx context.Context, resourceEvents []ResourceEventModel) error
	ListResourceEvents(ctx context.Context, filterParams ResourceEventFilterParams, listParams service.ListParams) ([]ResourceEventModel, *service.Cursor, *service.Cursor, error)
	TrackAccessEvent(ctx context.Context, accessEvent AccessEventModel) error
	TrackAccessEvents(ctx context.Context, accessEvents []AccessEventModel) error
	ListAccessEvents(ctx context.Context, filterParams AccessEventFilterParams, listParams service.ListParams) ([]AccessEventModel, *service.Cursor, *service.Cursor, error)
}

func NewRepository

func NewRepository(db database.Database) (EventRepository, error)

type EventService

type EventService struct {
	service.BaseService
	Repository         EventRepository
	SynchronizeEvents  bool
	CreateEventContext EventContextFunc
}

func NewService

func NewService(env service.Env, repository EventRepository, synchronizeEvents bool, createEventContext EventContextFunc) *EventService

func (EventService) ListAccessEvents

func (svc EventService) ListAccessEvents(ctx context.Context, filterParams AccessEventFilterParams, listParams service.ListParams) ([]AccessEventSpec, *service.Cursor, *service.Cursor, error)

func (EventService) ListResourceEvents

func (svc EventService) ListResourceEvents(ctx context.Context, filterParams ResourceEventFilterParams, listParams service.ListParams) ([]ResourceEventSpec, *service.Cursor, *service.Cursor, error)

func (EventService) Routes added in v0.8.0

func (svc EventService) Routes() ([]service.Route, error)

func (EventService) TrackAccessAllowedEvent

func (svc EventService) TrackAccessAllowedEvent(ctx context.Context, objectType string, objectId string, relation string, subjectType string, subjectId string, subjectRelation string, meta interface{}) error

func (EventService) TrackAccessDeniedEvent

func (svc EventService) TrackAccessDeniedEvent(ctx context.Context, objectType string, objectId string, relation string, subjectType string, subjectId string, subjectRelation string, meta interface{}) error

func (EventService) TrackAccessEvent

func (svc EventService) TrackAccessEvent(ctx context.Context, accessEventSpec CreateAccessEventSpec) error

func (EventService) TrackAccessEvents

func (svc EventService) TrackAccessEvents(ctx context.Context, accessEventSpecs []CreateAccessEventSpec) error

func (EventService) TrackAccessGrantedEvent

func (svc EventService) TrackAccessGrantedEvent(ctx context.Context, objectType string, objectId string, relation string, subjectType string, subjectId string, subjectRelation string, meta interface{}) error

func (EventService) TrackAccessRevokedEvent

func (svc EventService) TrackAccessRevokedEvent(ctx context.Context, objectType string, objectId string, relation string, subjectType string, subjectId string, subjectRelation string, meta interface{}) error

func (EventService) TrackResourceCreated

func (svc EventService) TrackResourceCreated(ctx context.Context, resourceType string, resourceId string, meta interface{}) error

func (EventService) TrackResourceDeleted

func (svc EventService) TrackResourceDeleted(ctx context.Context, resourceType string, resourceId string, meta interface{}) error

func (EventService) TrackResourceEvent

func (svc EventService) TrackResourceEvent(ctx context.Context, resourceEventSpec CreateResourceEventSpec) error

func (EventService) TrackResourceEvents

func (svc EventService) TrackResourceEvents(ctx context.Context, resourceEventSpecs []CreateResourceEventSpec) error

func (EventService) TrackResourceUpdated

func (svc EventService) TrackResourceUpdated(ctx context.Context, resourceType string, resourceId string, meta interface{}) error

type ListEventsSpecV1 added in v0.58.0

type ListEventsSpecV1[T ResourceEventSpec | AccessEventSpec] struct {
	Events []T    `json:"events"`
	LastId string `json:"lastId,omitempty"`
}

type ListEventsSpecV2 added in v0.58.0

type ListEventsSpecV2[T ResourceEventSpec | AccessEventSpec] struct {
	Results    []T             `json:"results"`
	PrevCursor *service.Cursor `json:"prevCursor,omitempty"`
	NextCursor *service.Cursor `json:"nextCursor,omitempty"`
}

type MySQLRepository

type MySQLRepository struct {
	database.SQLRepository
}

func NewMySQLRepository

func NewMySQLRepository(db *database.MySQL) *MySQLRepository

func (MySQLRepository) ListAccessEvents

func (repo MySQLRepository) ListAccessEvents(ctx context.Context, filterParams AccessEventFilterParams, listParams service.ListParams) ([]AccessEventModel, *service.Cursor, *service.Cursor, error)

func (MySQLRepository) ListResourceEvents

func (repo MySQLRepository) ListResourceEvents(ctx context.Context, filterParams ResourceEventFilterParams, listParams service.ListParams) ([]ResourceEventModel, *service.Cursor, *service.Cursor, error)

func (MySQLRepository) TrackAccessEvent

func (repo MySQLRepository) TrackAccessEvent(ctx context.Context, accessEvent AccessEventModel) error

func (MySQLRepository) TrackAccessEvents

func (repo MySQLRepository) TrackAccessEvents(ctx context.Context, models []AccessEventModel) error

func (MySQLRepository) TrackResourceEvent

func (repo MySQLRepository) TrackResourceEvent(ctx context.Context, resourceEvent ResourceEventModel) error

func (MySQLRepository) TrackResourceEvents

func (repo MySQLRepository) TrackResourceEvents(ctx context.Context, models []ResourceEventModel) error

type PostgresRepository

type PostgresRepository struct {
	database.SQLRepository
}

func NewPostgresRepository

func NewPostgresRepository(db *database.Postgres) *PostgresRepository

func (PostgresRepository) ListAccessEvents

func (repo PostgresRepository) ListAccessEvents(ctx context.Context, filterParams AccessEventFilterParams, listParams service.ListParams) ([]AccessEventModel, *service.Cursor, *service.Cursor, error)

func (PostgresRepository) ListResourceEvents

func (repo PostgresRepository) ListResourceEvents(ctx context.Context, filterParams ResourceEventFilterParams, listParams service.ListParams) ([]ResourceEventModel, *service.Cursor, *service.Cursor, error)

func (PostgresRepository) TrackAccessEvent

func (repo PostgresRepository) TrackAccessEvent(ctx context.Context, accessEvent AccessEventModel) error

func (PostgresRepository) TrackAccessEvents

func (repo PostgresRepository) TrackAccessEvents(ctx context.Context, models []AccessEventModel) error

func (PostgresRepository) TrackResourceEvent

func (repo PostgresRepository) TrackResourceEvent(ctx context.Context, resourceEvent ResourceEventModel) error

func (PostgresRepository) TrackResourceEvents

func (repo PostgresRepository) TrackResourceEvents(ctx context.Context, models []ResourceEventModel) error

type ResourceEvent

type ResourceEvent struct {
	ID           string    `mysql:"id" postgres:"id" sqlite:"id"`
	Type         string    `mysql:"type" postgres:"type" sqlite:"type"`
	Source       string    `mysql:"source" postgres:"source" sqlite:"source"`
	ResourceType string    `mysql:"resourceType" postgres:"resource_type" sqlite:"resourceType"`
	ResourceId   string    `mysql:"resourceId" postgres:"resource_id" sqlite:"resourceId"`
	Meta         *string   `mysql:"meta" postgres:"meta" sqlite:"meta"`
	CreatedAt    time.Time `mysql:"createdAt" postgres:"created_at" sqlite:"createdAt"`
}

func NewResourceEventFromModel added in v0.8.0

func NewResourceEventFromModel(model ResourceEventModel) *ResourceEvent

func (ResourceEvent) GetCreatedAt added in v0.8.0

func (resourceEvent ResourceEvent) GetCreatedAt() time.Time

func (ResourceEvent) GetID added in v0.8.0

func (resourceEvent ResourceEvent) GetID() string

func (ResourceEvent) GetMeta added in v0.8.0

func (resourceEvent ResourceEvent) GetMeta() *string

func (ResourceEvent) GetResourceId added in v0.8.0

func (resourceEvent ResourceEvent) GetResourceId() string

func (ResourceEvent) GetResourceType added in v0.8.0

func (resourceEvent ResourceEvent) GetResourceType() string

func (ResourceEvent) GetSource added in v0.8.0

func (resourceEvent ResourceEvent) GetSource() string

func (ResourceEvent) GetType added in v0.8.0

func (resourceEvent ResourceEvent) GetType() string

func (ResourceEvent) ToResourceEventSpec

func (resourceEvent ResourceEvent) ToResourceEventSpec() (*ResourceEventSpec, error)

type ResourceEventFilterParams added in v0.58.0

type ResourceEventFilterParams struct {
	Type         string
	Source       string
	ResourceType string
	ResourceId   string
	Since        time.Time
	Until        time.Time
}

type ResourceEventListParamParser added in v0.58.0

type ResourceEventListParamParser struct{}

func (ResourceEventListParamParser) GetDefaultSortBy added in v0.58.0

func (parser ResourceEventListParamParser) GetDefaultSortBy() string

func (ResourceEventListParamParser) GetSupportedSortBys added in v0.58.0

func (parser ResourceEventListParamParser) GetSupportedSortBys() []string

func (ResourceEventListParamParser) ParseValue added in v0.58.0

func (parser ResourceEventListParamParser) ParseValue(val string, sortBy string) (interface{}, error)

type ResourceEventModel added in v0.8.0

type ResourceEventModel interface {
	GetID() string
	GetType() string
	GetSource() string
	GetResourceType() string
	GetResourceId() string
	GetMeta() *string
	GetCreatedAt() time.Time
	ToResourceEventSpec() (*ResourceEventSpec, error)
}

type ResourceEventSpec

type ResourceEventSpec struct {
	ID           string      `json:"id"`
	Type         string      `json:"type"`
	Source       string      `json:"source"`
	ResourceType string      `json:"resourceType"`
	ResourceId   string      `json:"resourceId"`
	Meta         interface{} `json:"meta,omitempty"`
	CreatedAt    time.Time   `json:"createdAt"`
}

type SQLiteRepository added in v0.11.0

type SQLiteRepository struct {
	database.SQLRepository
}

func NewSQLiteRepository added in v0.11.0

func NewSQLiteRepository(db *database.SQLite) *SQLiteRepository

func (SQLiteRepository) ListAccessEvents added in v0.11.0

func (repo SQLiteRepository) ListAccessEvents(ctx context.Context, filterParams AccessEventFilterParams, listParams service.ListParams) ([]AccessEventModel, *service.Cursor, *service.Cursor, error)

func (SQLiteRepository) ListResourceEvents added in v0.11.0

func (repo SQLiteRepository) ListResourceEvents(ctx context.Context, filterParams ResourceEventFilterParams, listParams service.ListParams) ([]ResourceEventModel, *service.Cursor, *service.Cursor, error)

func (SQLiteRepository) TrackAccessEvent added in v0.11.0

func (repo SQLiteRepository) TrackAccessEvent(ctx context.Context, accessEvent AccessEventModel) error

func (SQLiteRepository) TrackAccessEvents added in v0.11.0

func (repo SQLiteRepository) TrackAccessEvents(ctx context.Context, models []AccessEventModel) error

func (SQLiteRepository) TrackResourceEvent added in v0.11.0

func (repo SQLiteRepository) TrackResourceEvent(ctx context.Context, resourceEvent ResourceEventModel) error

func (SQLiteRepository) TrackResourceEvents added in v0.11.0

func (repo SQLiteRepository) TrackResourceEvents(ctx context.Context, models []ResourceEventModel) error

type Service added in v0.24.0

type Service interface {
	TrackResourceCreated(ctx context.Context, resourceType string, resourceId string, meta interface{}) error
	TrackResourceUpdated(ctx context.Context, resourceType string, resourceId string, meta interface{}) error
	TrackResourceDeleted(ctx context.Context, resourceType string, resourceId string, meta interface{}) error
	TrackResourceEvent(ctx context.Context, resourceEventSpec CreateResourceEventSpec) error
	TrackResourceEvents(ctx context.Context, resourceEventSpecs []CreateResourceEventSpec) error
	ListResourceEvents(ctx context.Context, filterParams ResourceEventFilterParams, listParams service.ListParams) ([]ResourceEventSpec, *service.Cursor, *service.Cursor, error)
	TrackAccessGrantedEvent(ctx context.Context, objectType string, objectId string, relation string, subjectType string, subjectId string, subjectRelation string, meta interface{}) error
	TrackAccessRevokedEvent(ctx context.Context, objectType string, objectId string, relation string, subjectType string, subjectId string, subjectRelation string, meta interface{}) error
	TrackAccessAllowedEvent(ctx context.Context, objectType string, objectId string, relation string, subjectType string, subjectId string, subjectRelation string, meta interface{}) error
	TrackAccessDeniedEvent(ctx context.Context, objectType string, objectId string, relation string, subjectType string, subjectId string, subjectRelation string, meta interface{}) error
	TrackAccessEvent(ctx context.Context, accessEventSpec CreateAccessEventSpec) error
	TrackAccessEvents(ctx context.Context, accessEventSpecs []CreateAccessEventSpec) error
	ListAccessEvents(ctx context.Context, filterParams AccessEventFilterParams, listParams service.ListParams) ([]AccessEventSpec, *service.Cursor, *service.Cursor, error)
}

Jump to

Keyboard shortcuts

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