audit

package
v0.0.0-...-94d0466 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ResourceName                    = "resourceName"
	RepoName                        = "repoName"
	BypassedResourceType            = "bypassedResourceType"
	BypassedResourceName            = "bypassedResourceName"
	RepoPath                        = "repoPath"
	BypassedResourceTypePullRequest = "pull_request"
	BypassedResourceTypeBranch      = "branch"
	BypassedResourceTypeCommit      = "commit"
	BypassAction                    = "bypass_action"
	BypassActionDeleted             = "deleted"
	BypassActionCreated             = "created"
	BypassActionCommitted           = "committed"
	BypassActionMerged              = "merged"
	BypassSHALabelFormat            = "%s @%s"
	BypassPullReqLabelFormat        = "%s #%s"
)

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"
	ActionBypassed Action = "bypassed"
)

func (Action) Validate

func (a Action) Validate() error

type BranchObject

type BranchObject struct {
	BranchName     string                 `yaml:"branch_name"`
	RepoPath       string                 `yaml:"repo_path"`
	RuleViolations []types.RuleViolations `yaml:"rule_violations"`
}

type CommitObject

type CommitObject struct {
	CommitSHA      string                 `yaml:"commit_sha"`
	RepoPath       string                 `yaml:"repo_path"`
	RuleViolations []types.RuleViolations `yaml:"rule_violations"`
}

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 PullRequestObject

type PullRequestObject struct {
	PullReq        types.PullReq
	RepoPath       string                 `yaml:"repo_path"`
	RuleViolations []types.RuleViolations `yaml:"rule_violations"`
}

type RegistryUpstreamProxyConfigObject

type RegistryUpstreamProxyConfigObject struct {
	ID         int64
	RegistryID int64
	Source     string
	URL        string
	AuthType   string
	CreatedAt  time.Time
	UpdatedAt  time.Time
	CreatedBy  int64
	UpdatedBy  int64
}

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"
	ResourceTypeBranch                ResourceType = "branch"
	ResourceTypePullRequest           ResourceType = "pull_request"
	ResourceTypeRepositorySettings    ResourceType = "repository_settings"
	ResourceTypeRegistry              ResourceType = "registry"
	ResourceTypeRegistryUpstreamProxy ResourceType = "registry_upstream_proxy"
)

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