audit

package
v1.0.4-gitspaces-beta Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RepoName = "repoName"
)

Variables

View Source
var (
	ErrActionUndefined              = errors.New("undefined action")
	ErrResourceTypeUndefined        = errors.New("undefined resource type")
	ErrResourceIdentifierIsRequired = errors.New("resource identifier is required")
	ErrUserIsRequired               = errors.New("user is required")
	ErrSpacePathIsRequired          = errors.New("space path is required")
)

Functions

func GetRealIP

func GetRealIP(ctx context.Context) string

GetRealIP returns IP address from context.

func GetRequestID

func GetRequestID(ctx context.Context) string

GetRequestID returns requestID from context.

func GetRequestMethod

func GetRequestMethod(ctx context.Context) string

GetRequestMethod returns http method from context.

func Middleware

func Middleware() func(next http.Handler) http.Handler

Middleware process request headers to fill internal info data.

Types

type Action

type Action string
const (
	ActionCreated Action = "created"
	ActionUpdated Action = "updated" // update default branch, switching default branch, updating description
	ActionDeleted Action = "deleted"
)

func (Action) Validate

func (a Action) Validate() error

type DiffObject

type DiffObject struct {
	OldObject any
	NewObject any
}

type Event

type Event struct {
	ID            string
	Timestamp     int64
	Action        Action          // example: ActionCreated
	User          types.Principal // example: Admin
	SpacePath     string          // example: /root/projects
	Resource      Resource
	DiffObject    DiffObject
	ClientIP      string
	RequestMethod string
	Data          map[string]string // internal data like correlationID/requestID
}

func (*Event) Validate

func (e *Event) Validate() error

type FuncOption

type FuncOption func(e *Event)

func WithClientIP

func WithClientIP(value string) FuncOption

func WithData

func WithData(keyValues ...string) FuncOption

func WithID

func WithID(value string) FuncOption

func WithNewObject

func WithNewObject(value any) FuncOption

func WithOldObject

func WithOldObject(value any) FuncOption

func WithRequestMethod

func WithRequestMethod(value string) FuncOption

func (FuncOption) Apply

func (f FuncOption) Apply(event *Event)

type Noop

type Noop struct{}

func New

func New() *Noop

func (*Noop) Log

type Option

type Option interface {
	Apply(e *Event)
}

type RepositoryObject

type RepositoryObject struct {
	types.Repository
	IsPublic bool `yaml:"is_public"`
}

RepositoryObject is the object used for emitting repository related audits. TODO: ensure audit only takes audit related objects?

type Resource

type Resource struct {
	Type       ResourceType
	Identifier string
	Data       map[string]string
}

func NewResource

func NewResource(rtype ResourceType, identifier string, keyValues ...string) Resource

func (Resource) DataAsSlice

func (r Resource) DataAsSlice() []string

func (Resource) Validate

func (r Resource) Validate() error

type ResourceType

type ResourceType string
const (
	ResourceTypeRepository         ResourceType = "repository"
	ResourceTypeBranchRule         ResourceType = "branch_rule"
	ResourceTypeRepositorySettings ResourceType = "repository_settings"
)

func (ResourceType) Validate

func (a ResourceType) Validate() error

type Service

type Service interface {
	Log(
		ctx context.Context,
		user types.Principal,
		resource Resource,
		action Action,
		spacePath string,
		options ...Option,
	) error
}

func ProvideAuditService

func ProvideAuditService() Service

Jump to

Keyboard shortcuts

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