event

package
v0.45.0 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2023 License: Apache-2.0 Imports: 16 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"
	LimitErrorMessage = "Must be an integer between 1 and 1000"
)
View Source
const (
	DefaultEpochMicroseconds  = 1136160000000
	DefaultLimit              = 100
	QueryParamType            = "type"
	QueryParamSource          = "source"
	QueryParamResourceType    = "resourceType"
	QueryParamResourceId      = "resourceId"
	QueryParamLastId          = "lastId"
	QueryParamSince           = "since"
	QueryParamUntil           = "until"
	QueryParamLimit           = "limit"
	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

func LastIdSpecToString added in v0.13.0

func LastIdSpecToString(lastIdSpec LastIdSpec) (string, error)

func ListAccessEvents added in v0.13.0

func ListAccessEvents(svc EventService, w http.ResponseWriter, r *http.Request) error

func ListResourceEvents added in v0.13.0

func ListResourceEvents(svc EventService, w http.ResponseWriter, r *http.Request) error

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 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(context.Context, ResourceEventModel) error
	TrackResourceEvents(context.Context, []ResourceEventModel) error
	ListResourceEvents(context.Context, ListResourceEventParams) ([]ResourceEventModel, string, error)
	TrackAccessEvent(context.Context, AccessEventModel) error
	TrackAccessEvents(context.Context, []AccessEventModel) error
	ListAccessEvents(context.Context, ListAccessEventParams) ([]AccessEventModel, string, 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, listParams ListAccessEventParams) ([]AccessEventSpec, string, error)

func (EventService) ListResourceEvents

func (svc EventService) ListResourceEvents(ctx context.Context, listParams ListResourceEventParams) ([]ResourceEventSpec, string, 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 LastIdSpec

type LastIdSpec struct {
	ID        string    `json:"id"`
	CreatedAt time.Time `json:"createdAt"`
}

func StringToLastIdSpec added in v0.13.0

func StringToLastIdSpec(base64Str string) (*LastIdSpec, error)

type ListAccessEventParams

type ListAccessEventParams struct {
	Type            string
	Source          string
	ObjectType      string
	ObjectId        string
	Relation        string
	SubjectType     string
	SubjectId       string
	SubjectRelation string
	LastId          string
	Since           time.Time
	Until           time.Time
	Limit           int64
}

type ListEventsSpec

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

type ListResourceEventParams

type ListResourceEventParams struct {
	Type         string
	Source       string
	ResourceType string
	ResourceId   string
	LastId       string
	Since        time.Time
	Until        time.Time
	Limit        int64
}

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, listParams ListAccessEventParams) ([]AccessEventModel, string, error)

func (MySQLRepository) ListResourceEvents

func (repo MySQLRepository) ListResourceEvents(ctx context.Context, listParams ListResourceEventParams) ([]ResourceEventModel, string, 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, listParams ListAccessEventParams) ([]AccessEventModel, string, error)

func (PostgresRepository) ListResourceEvents

func (repo PostgresRepository) ListResourceEvents(ctx context.Context, listParams ListResourceEventParams) ([]ResourceEventModel, string, 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 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, listParams ListAccessEventParams) ([]AccessEventModel, string, error)

func (SQLiteRepository) ListResourceEvents added in v0.11.0

func (repo SQLiteRepository) ListResourceEvents(ctx context.Context, listParams ListResourceEventParams) ([]ResourceEventModel, string, 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, listParams ListResourceEventParams) ([]ResourceEventSpec, string, 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, listParams ListAccessEventParams) ([]AccessEventSpec, string, error)
}

Jump to

Keyboard shortcuts

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