memory

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package memory provides an in-memory implementation of the Chronicle store. It is intended for unit testing and development only.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Store

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

Store is an in-memory implementation of all Chronicle store interfaces.

func New

func New() *Store

New creates a new in-memory store.

func (*Store) Accept

func (s *Store) Accept(ctx context.Context, request acceptance.Request, h *hash.Chain, prepare func(*audit.Event) error) (*acceptance.Receipt, error)

Accept commits the event, stream and receipt under the shared store lock.

func (*Store) Aggregate

Aggregate returns grouped counts/stats.

func (*Store) Append

func (s *Store) Append(_ context.Context, event *audit.Event) error

Append persists a single event.

func (*Store) AppendBatch

func (s *Store) AppendBatch(_ context.Context, events []*audit.Event) error

AppendBatch persists a batch of events atomically.

func (*Store) AppendCheckpoint

func (s *Store) AppendCheckpoint(_ context.Context, cp *checkpoint.Checkpoint) error

AppendCheckpoint persists a checkpoint. Checkpoints are append-only: there is no update or delete, since a checkpoint that could be revised would assert nothing.

func (*Store) AppendWithChain

func (s *Store) AppendWithChain(ctx context.Context, e *audit.Event, h *hash.Chain) error

AppendWithChain links a legacy event under the same lock as Accept.

func (*Store) ByUser

func (s *Store) ByUser(_ context.Context, userID string, opts audit.TimeRange) (*audit.QueryResult, error)

ByUser returns events for a specific user within a time range.

func (*Store) CheckpointsInRange

func (s *Store) CheckpointsInRange(
	_ context.Context, streamID id.ID, fromSeq, toSeq uint64,
) ([]*checkpoint.Checkpoint, error)

CheckpointsInRange returns every checkpoint whose range overlaps [fromSeq, toSeq], ascending by ToSeq.

Overlap rather than containment: a caller verifying sequences 150 to 160 still needs the checkpoint covering 101 to 200, because that is the one whose signed assertion those events fall under. Containment would silently return nothing for a range that sits inside a wider checkpoint.

func (*Store) Close

func (s *Store) Close() error

Close marks the store as closed.

func (*Store) CompleteErasure

func (s *Store) CompleteErasure(_ context.Context, erasureID id.ID, o erasure.Outcome) error

CompleteErasure writes an erasure's outcome and marks it completed. The stored record is replaced rather than edited, so a pointer GetErasure handed out earlier is never written under a reader.

func (*Store) Count

func (s *Store) Count(_ context.Context, q *audit.CountQuery) (int64, error)

Count returns the total number of events matching filters.

func (*Store) CountBySubject

func (s *Store) CountBySubject(_ context.Context, sq erasure.SubjectQuery) (int64, error)

CountBySubject returns the number of events for a subject within the query's scope.

func (*Store) CountErasures

func (s *Store) CountErasures(_ context.Context, sc erasure.Scope) (int64, error)

CountErasures returns the number of erasure records in the given scope.

func (*Store) CreateStream

func (s *Store) CreateStream(_ context.Context, st *stream.Stream) error

CreateStream initializes a new hash chain stream.

func (*Store) DeletePolicy

func (s *Store) DeletePolicy(_ context.Context, policyID id.ID) error

DeletePolicy removes a retention policy.

func (*Store) DeleteReport

func (s *Store) DeleteReport(_ context.Context, reportID id.ID) error

DeleteReport removes a report.

func (*Store) EventRange

func (s *Store) EventRange(_ context.Context, streamID id.ID, fromSeq, toSeq uint64) ([]*audit.Event, error)

EventRange returns events in a sequence range for chain verification.

func (*Store) EventsOlderThan

func (s *Store) EventsOlderThan(_ context.Context, q retention.PurgeQuery) ([]*audit.Event, error)

EventsOlderThan returns the events the purge query selects, restricted to the query's scope.

func (*Store) Gaps

func (s *Store) Gaps(_ context.Context, streamID id.ID, fromSeq, toSeq uint64) ([]uint64, error)

Gaps detects missing sequence numbers in a range.

func (*Store) Get

func (s *Store) Get(_ context.Context, eventID id.ID) (*audit.Event, error)

Get returns a single event by ID.

func (*Store) GetCheckpoint

func (s *Store) GetCheckpoint(_ context.Context, checkpointID id.ID) (*checkpoint.Checkpoint, error)

GetCheckpoint returns one checkpoint by ID.

func (*Store) GetErasure

func (s *Store) GetErasure(_ context.Context, erasureID id.ID) (*erasure.Erasure, error)

GetErasure returns an erasure record by ID.

func (*Store) GetPolicy

func (s *Store) GetPolicy(_ context.Context, policyID id.ID) (*retention.Policy, error)

GetPolicy returns a retention policy by ID.

func (*Store) GetReport

func (s *Store) GetReport(_ context.Context, reportID id.ID) (*compliance.Report, error)

GetReport returns a report by ID.

func (*Store) GetStream

func (s *Store) GetStream(_ context.Context, streamID id.ID) (*stream.Stream, error)

GetStream returns a stream by ID (named to avoid collision with audit.Get).

func (*Store) GetStreamByScope

func (s *Store) GetStreamByScope(_ context.Context, appID, tenantID string) (*stream.Stream, error)

GetStreamByScope returns the stream for a given app+tenant scope.

func (*Store) LastHash

func (s *Store) LastHash(_ context.Context, streamID id.ID) (string, error)

LastHash returns the hash of the most recent event in a stream.

func (*Store) LastSequence

func (s *Store) LastSequence(_ context.Context, streamID id.ID) (uint64, error)

LastSequence returns the highest sequence number for a stream.

func (*Store) LatestCheckpoint

func (s *Store) LatestCheckpoint(_ context.Context, streamID id.ID) (*checkpoint.Checkpoint, error)

LatestCheckpoint returns the checkpoint with the highest ToSeq for a stream.

func (*Store) ListArchives

func (s *Store) ListArchives(_ context.Context, opts retention.ListOpts) ([]*retention.Archive, error)

ListArchives returns archive records matching opts.

func (*Store) ListCheckpoints

func (s *Store) ListCheckpoints(
	_ context.Context, streamID id.ID, opts checkpoint.ListOpts,
) ([]*checkpoint.Checkpoint, error)

ListCheckpoints returns a stream's checkpoints, newest first.

func (*Store) ListErasures

func (s *Store) ListErasures(_ context.Context, opts erasure.ListOpts) ([]*erasure.Erasure, error)

ListErasures returns erasure records matching opts.

func (*Store) ListPolicies

func (s *Store) ListPolicies(_ context.Context, opts retention.ListPoliciesOpts) ([]*retention.Policy, error)

ListPolicies returns retention policies matching opts.

func (*Store) ListReports

func (s *Store) ListReports(_ context.Context, opts compliance.ListOpts) ([]*compliance.Report, error)

ListReports returns reports matching opts, scoped before pagination.

func (*Store) ListStreams

func (s *Store) ListStreams(_ context.Context, opts stream.ListOpts) ([]*stream.Stream, error)

ListStreams returns all streams.

func (*Store) MarkErased

func (s *Store) MarkErased(
	_ context.Context, sq erasure.SubjectQuery, erasureID id.ID,
) (int64, error)

MarkErased flags a subject's events as erased within the query's scope. Events already marked are re-pointed at erasureID; see erasure.Store.

func (*Store) Migrate

func (s *Store) Migrate(_ context.Context) error

Migrate is a no-op for the memory store.

func (*Store) Ping

func (s *Store) Ping(_ context.Context) error

Ping is a no-op for the memory store.

func (*Store) PurgeEvents

func (s *Store) PurgeEvents(_ context.Context, eventIDs []id.ID) (int64, error)

PurgeEvents permanently deletes events by IDs.

func (*Store) Query

func (s *Store) Query(_ context.Context, q *audit.Query) (*audit.QueryResult, error)

Query returns events matching filters.

func (*Store) RecordArchive

func (s *Store) RecordArchive(_ context.Context, a *retention.Archive) error

RecordArchive records that a batch of events was archived.

func (*Store) RecordErasure

func (s *Store) RecordErasure(_ context.Context, e *erasure.Erasure) error

RecordErasure persists an erasure event.

func (*Store) SavePolicy

func (s *Store) SavePolicy(_ context.Context, p *retention.Policy) error

SavePolicy persists a retention policy, replacing any existing policy with the same ID or the same (app, tenant, category) scope.

func (*Store) SaveReport

func (s *Store) SaveReport(_ context.Context, r *compliance.Report) error

SaveReport persists a generated compliance report.

func (*Store) SubjectKeyUsage

func (s *Store) SubjectKeyUsage(_ context.Context, subjectID string) ([]erasure.KeyUsage, error)

SubjectKeyUsage groups a subject's events across every scope by app, tenant, encryption key ID and erased flag. Unscoped on purpose; see erasure.Store.

func (*Store) UpdateStreamHead

func (s *Store) UpdateStreamHead(_ context.Context, streamID id.ID, hash string, seq uint64) error

UpdateStreamHead updates the stream's head hash and sequence.

func (*Store) UpdateStreamScheme

func (s *Store) UpdateStreamScheme(_ context.Context, streamID id.ID, scheme string, since uint64) error

UpdateStreamScheme moves the stream's digest pin.

Jump to

Keyboard shortcuts

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