audit

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: May 13, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidDetail = fmt.Errorf("invalid audit details")
	ErrInvalidID     = fmt.Errorf("group id is invalid")
)

Functions

func SetContextWithActor

func SetContextWithActor(ctx context.Context, actor Actor) context.Context

func SetContextWithMetadata

func SetContextWithMetadata(ctx context.Context, md map[string]string) context.Context

func SetContextWithService

func SetContextWithService(ctx context.Context, p *Service) context.Context

func TransformToEventData added in v0.11.0

func TransformToEventData(l *Log) map[string]interface{}

Types

type Actor

type Actor struct {
	ID   string
	Type string
	Name string
}

type EventName

type EventName string
const (
	UserCreatedEvent        EventName = "app.user.created"
	UserUpdatedEvent        EventName = "app.user.updated"
	UserDeletedEvent        EventName = "app.user.deleted"
	UserListedEvent         EventName = "app.user.listed"
	ServiceUserCreatedEvent EventName = "app.serviceuser.created"
	ServiceUserDeletedEvent EventName = "app.serviceuser.deleted"

	GroupCreatedEvent EventName = "app.group.created"
	GroupUpdatedEvent EventName = "app.group.updated"
	GroupDeletedEvent EventName = "app.group.deleted"

	RoleCreatedEvent EventName = "app.role.created"
	RoleUpdatedEvent EventName = "app.role.updated"
	RoleDeletedEvent EventName = "app.role.deleted"

	PermissionCreatedEvent EventName = "app.permission.created"
	PermissionUpdatedEvent EventName = "app.permission.updated"
	PermissionDeletedEvent EventName = "app.permission.deleted"
	PermissionCheckedEvent EventName = "app.permission.checked"

	BillingEntitlementCheckedEvent EventName = "app.billing.entitlement.checked"

	PolicyCreatedEvent EventName = "app.policy.created"
	PolicyDeletedEvent EventName = "app.policy.deleted"

	OrgCreatedEvent       EventName = "app.organization.created"
	OrgUpdatedEvent       EventName = "app.organization.updated"
	OrgDeletedEvent       EventName = "app.organization.deleted"
	OrgMemberCreatedEvent EventName = "app.organization.member.created"
	OrgMemberDeletedEvent EventName = "app.organization.member.deleted"

	ProjectCreatedEvent EventName = "app.project.created"
	ProjectUpdatedEvent EventName = "app.project.updated"
	ProjectDeletedEvent EventName = "app.project.deleted"

	ResourceCreatedEvent EventName = "app.resource.created"
	ResourceUpdatedEvent EventName = "app.resource.updated"
	ResourceDeletedEvent EventName = "app.resource.deleted"
)

func (EventName) String

func (e EventName) String() string

type Filter

type Filter struct {
	OrgID  string
	Source string
	Action string

	StartTime time.Time
	EndTime   time.Time
}

type Log

type Log struct {
	ID     string
	OrgID  string
	Source string
	Action string

	Actor    Actor
	Target   Target
	Metadata map[string]string

	CreatedAt time.Time
}

Log is a struct that represents an audit log

type Logger

type Logger struct {
	Now func() time.Time
	// contains filtered or unexported fields
}

func GetAuditor

func GetAuditor(ctx context.Context, orgID string) *Logger

func NewLogger

func NewLogger(ctx context.Context, orgID string) *Logger

func (*Logger) Log

func (s *Logger) Log(action EventName, target Target) error

func (*Logger) LogWithAttrs

func (s *Logger) LogWithAttrs(action EventName, target Target, attrs map[string]string) error

type NoopRepository added in v0.8.35

type NoopRepository struct{}

func NewNoopRepository added in v0.8.35

func NewNoopRepository() *NoopRepository

func (NoopRepository) Create added in v0.8.35

func (r NoopRepository) Create(ctx context.Context, log *Log) error

func (NoopRepository) GetByID added in v0.8.35

func (r NoopRepository) GetByID(ctx context.Context, s string) (Log, error)

func (NoopRepository) List added in v0.8.35

func (r NoopRepository) List(ctx context.Context, filter Filter) ([]Log, error)

type NoopWebhookService added in v0.11.0

type NoopWebhookService struct{}

func NewNoopWebhookService added in v0.11.0

func NewNoopWebhookService() *NoopWebhookService

func (NoopWebhookService) Publish added in v0.11.0

type Option

type Option func(*Service)

func WithActorExtractor

func WithActorExtractor(fn func(context.Context) (Actor, bool)) Option

func WithLogPublisher added in v0.8.35

func WithLogPublisher(p Publisher) Option

func WithMetadataExtractor

func WithMetadataExtractor(fn func(context.Context) (map[string]string, bool)) Option

type Publisher added in v0.8.35

type Publisher interface {
	Publish(context.Context, Log)
}

type Repository

type Repository interface {
	Create(context.Context, *Log) error
	List(context.Context, Filter) ([]Log, error)
	GetByID(context.Context, string) (Log, error)
}

type Service

type Service struct {
	// contains filtered or unexported fields
}

func GetService

func GetService(ctx context.Context) *Service

GetService returns the audit service from the context if set otherwise it returns a new service with a write only repository

func NewService

func NewService(source string, repository Repository, webhookService WebhookService, opts ...Option) *Service

func (*Service) Create

func (s *Service) Create(ctx context.Context, l *Log) error

func (*Service) GetByID

func (s *Service) GetByID(ctx context.Context, id string) (Log, error)

func (*Service) List

func (s *Service) List(ctx context.Context, flt Filter) ([]Log, error)

type Target

type Target struct {
	ID   string
	Type string
	Name string
}

func GroupTarget

func GroupTarget(id string) Target

func OrgTarget

func OrgTarget(id string) Target

func ProjectTarget

func ProjectTarget(id string) Target

func ServiceUserTarget

func ServiceUserTarget(id string) Target

func UserTarget

func UserTarget(id string) Target

type WebhookService added in v0.11.0

type WebhookService interface {
	Publish(ctx context.Context, e webhook.Event) error
}

type WriteOnlyRepository

type WriteOnlyRepository struct {
	// contains filtered or unexported fields
}

func NewWriteOnlyRepository

func NewWriteOnlyRepository(writer io.Writer) *WriteOnlyRepository

func (WriteOnlyRepository) Create

func (r WriteOnlyRepository) Create(ctx context.Context, log *Log) error

func (WriteOnlyRepository) GetByID

func (r WriteOnlyRepository) GetByID(ctx context.Context, s string) (Log, error)

func (WriteOnlyRepository) List

func (r WriteOnlyRepository) List(ctx context.Context, filter Filter) ([]Log, error)

Jump to

Keyboard shortcuts

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