auditlog

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	RegisterAuditLogFn = registerAuditLog
	GetAuditLogFn      = getAuditLog
)

Functions

func Register

func Register(cfg *config.AuditLogConfig)

Register registers the audit log plugin with the given configuration.

func ResetAuditLog

func ResetAuditLog()

ResetAuditLog clears the registered audit log (for testing).

Types

type AuditLog

type AuditLog interface {
	Name() string
	Description() string
	Version() string

	// RecordEntry logs a version bump with metadata.
	RecordEntry(entry *Entry) error

	// IsEnabled returns whether the plugin is enabled.
	IsEnabled() bool

	// GetConfig returns the plugin configuration.
	GetConfig() *Config
}

AuditLog defines the interface for audit logging.

type AuditLogFile

type AuditLogFile struct {
	Entries []Entry `json:"entries" yaml:"entries"`
}

AuditLogFile represents the structure of the audit log file.

type AuditLogPlugin

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

AuditLogPlugin implements the AuditLog interface.

func NewAuditLog

func NewAuditLog(cfg *Config) *AuditLogPlugin

NewAuditLog creates a new audit log plugin.

func NewAuditLogWithOps

func NewAuditLogWithOps(cfg *Config, gitOps GitOperations, fileOps FileOperations) *AuditLogPlugin

NewAuditLogWithOps creates a new audit log plugin with custom operations (for testing).

func (*AuditLogPlugin) Description

func (p *AuditLogPlugin) Description() string

Description returns the plugin description.

func (*AuditLogPlugin) GetConfig

func (p *AuditLogPlugin) GetConfig() *Config

GetConfig returns the plugin configuration.

func (*AuditLogPlugin) IsEnabled

func (p *AuditLogPlugin) IsEnabled() bool

IsEnabled returns whether the plugin is enabled.

func (*AuditLogPlugin) Name

func (p *AuditLogPlugin) Name() string

Name returns the plugin name.

func (*AuditLogPlugin) RecordEntry

func (p *AuditLogPlugin) RecordEntry(entry *Entry) error

RecordEntry logs a version bump with metadata.

func (*AuditLogPlugin) Version

func (p *AuditLogPlugin) Version() string

Version returns the plugin version.

type Config

type Config struct {
	// Enabled controls whether the plugin is active.
	Enabled bool

	// Path is the path to the audit log file.
	Path string

	// Format specifies the output format: json or yaml.
	Format string

	// IncludeAuthor includes git author in log entries.
	IncludeAuthor bool

	// IncludeTimestamp includes ISO 8601 timestamp in log entries.
	IncludeTimestamp bool

	// IncludeCommitSHA includes current commit SHA in log entries.
	IncludeCommitSHA bool

	// IncludeBranch includes current branch name in log entries.
	IncludeBranch bool
}

Config holds configuration for the audit log plugin.

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns the default audit log configuration.

func FromConfigStruct

func FromConfigStruct(cfg *config.AuditLogConfig) *Config

FromConfigStruct converts the config package struct to internal config.

func (*Config) GetFormat

func (c *Config) GetFormat() string

GetFormat returns the format with default "json".

func (*Config) GetPath

func (c *Config) GetPath() string

GetPath returns the path with default ".version-history.json".

type DefaultFileOps

type DefaultFileOps struct{}

DefaultFileOps implements FileOperations using standard library.

func (*DefaultFileOps) FileExists

func (f *DefaultFileOps) FileExists(path string) bool

FileExists checks if a file exists.

func (*DefaultFileOps) ReadFile

func (f *DefaultFileOps) ReadFile(path string) ([]byte, error)

ReadFile reads a file from disk.

func (*DefaultFileOps) WriteFile

func (f *DefaultFileOps) WriteFile(path string, data []byte, perm os.FileMode) error

WriteFile writes data to a file.

type DefaultGitOps

type DefaultGitOps struct{}

DefaultGitOps implements GitOperations using git commands.

func (*DefaultGitOps) GetAuthor

func (g *DefaultGitOps) GetAuthor() (string, error)

GetAuthor returns the git user name and email.

func (*DefaultGitOps) GetBranch

func (g *DefaultGitOps) GetBranch() (string, error)

GetBranch returns the current branch name.

func (*DefaultGitOps) GetCommitSHA

func (g *DefaultGitOps) GetCommitSHA() (string, error)

GetCommitSHA returns the current commit SHA.

type Entry

type Entry struct {
	Timestamp       string `json:"timestamp,omitempty" yaml:"timestamp,omitempty"`
	PreviousVersion string `json:"previous_version" yaml:"previous_version"`
	NewVersion      string `json:"new_version" yaml:"new_version"`
	BumpType        string `json:"bump_type" yaml:"bump_type"`
	Author          string `json:"author,omitempty" yaml:"author,omitempty"`
	CommitSHA       string `json:"commit_sha,omitempty" yaml:"commit_sha,omitempty"`
	Branch          string `json:"branch,omitempty" yaml:"branch,omitempty"`
}

Entry represents a single audit log entry.

type FileOperations

type FileOperations interface {
	ReadFile(path string) ([]byte, error)
	WriteFile(path string, data []byte, perm os.FileMode) error
	FileExists(path string) bool
}

FileOperations defines the interface for file operations.

type GitOperations

type GitOperations interface {
	GetAuthor() (string, error)
	GetCommitSHA() (string, error)
	GetBranch() (string, error)
}

GitOperations defines the interface for git operations.

Jump to

Keyboard shortcuts

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