objects

package
v0.4.5 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package objects owns the policies that normalize, identify, authorize, and merge generated DRS objects.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AccessMethodID

func AccessMethodID(accessType, accessURL string) string

AccessMethodID is stable for a type/URL pair and is safe to expose as the selector used by the DRS access endpoint.

func AccessResources

func AccessResources(obj *drs.DrsObject) []string

func AuthorizeRegistration added in v0.4.3

func AuthorizeRegistration(ctx context.Context, incoming *drs.DrsObject, current *ContentAccess) error

AuthorizeRegistration checks additions against the current stored policy. A nil current policy means this registration creates a new content row.

func AuthorizeReplacementResources added in v0.4.3

func AuthorizeReplacementResources(ctx context.Context, incoming []string, current ContentAccess) error

func CanonicalSHA256

func CanonicalSHA256(checksums []drs.Checksum) (string, bool)

func CleanToBasename

func CleanToBasename(name string) string

CleanToBasename extracts a portable basename from either Windows or Unix path syntax.

func LooksLikeSHA256

func LooksLikeSHA256(v string) bool

func MaterializeCandidate added in v0.4.2

func MaterializeCandidate(c drs.DrsObjectCandidate, now time.Time) (drs.DrsObject, error)

func MintRecordIDFromChecksum

func MintRecordIDFromChecksum(checksum string, authz []string) (string, error)

MintRecordIDFromChecksum returns a deterministic record ID for a checksum and one canonical project scope.

func NormalizeChecksumType

func NormalizeChecksumType(checksumType string) string

func NormalizeNameAliases

func NormalizeNameAliases(primary string, aliases []string) []string

func NormalizeOID added in v0.4.2

func NormalizeOID(oid string) string

func NormalizeRecord added in v0.4.2

func NormalizeRecord(record drs.DrsObject, fallback time.Time) (drs.DrsObject, error)

NormalizeRecord applies canonical identity, timestamp, name, checksum, access, and alias values.

func ParseHashQuery

func ParseHashQuery(rawHash string, rawType string) (string, string)

func RecordHasChecksumTypeAndValue

func RecordHasChecksumTypeAndValue(obj drs.DrsObject, hashType, hashValue string) bool

func ValidateCanonicalSHA256

func ValidateCanonicalSHA256(checksums []drs.Checksum) (string, bool, error)

Types

type BulkOverwriteResult added in v0.4.2

type BulkOverwriteResult struct {
	Created         int
	Replaced        int
	DIDMatched      int
	ChecksumMatched int
}

BulkOverwriteResult summarizes a project-scoped, source-wins metadata copy.

type CanonicalRepair added in v0.4.2

type CanonicalRepair struct {
	Canonical    drs.DrsObject
	DuplicateIDs []string
}

CanonicalRepair describes one atomic repair of physical records that share a project-scoped checksum. Canonical remains a physical record; duplicate IDs become aliases after their rows are removed.

type ChecksumQuery added in v0.4.2

type ChecksumQuery struct {
	Type  string
	Value string
}

type ContentAccess added in v0.4.3

type ContentAccess struct {
	Resources  []string
	PublicRead bool
}

ContentAccess is the access policy read inside a content write transaction.

type LookupResult added in v0.4.4

type LookupResult struct {
	Object *drs.DrsObject
	Err    error
}

LookupResult retains the result for one requested identifier, including a missing or denied error that a filtered bulk list cannot represent.

type ObjectIDPageQuery added in v0.4.3

type ObjectIDPageQuery struct {
	Scope                      Scope
	ObjectURL                  string
	StartAfter                 string
	Limit                      int
	Offset                     int
	VisibleResources           []string
	IncludeUnscoped            bool
	RestrictToVisibleResources bool
}

ObjectIDPageQuery selects one deterministic page of object IDs. An empty ObjectURL pages by scope; a non-empty URL also filters by the access method.

type ObjectStore added in v0.4.2

type ObjectStore interface {
	// GetObject resolves a physical ID or alias to its stored row.
	GetObject(context.Context, string) (*drs.DrsObject, error)
	GetBulkObjects(context.Context, []string) ([]drs.DrsObject, error)
	DeleteObject(context.Context, string) error
	BulkDeleteObjects(context.Context, []string) error
	RegisterObjects(context.Context, []drs.DrsObject) error
	RegisterObjectsIfPending(context.Context, []drs.DrsObject, PendingRegistration) error
	RepairCanonicalDuplicates(context.Context, []CanonicalRepair) error
	ReplaceObjects(context.Context, []drs.DrsObject) error
	ReplaceObject(context.Context, string, string, drs.DrsObject) error
	UpdateObjectAccessMethods(context.Context, string, []drs.AccessMethod) error
	BulkUpdateAccessMethods(context.Context, map[string][]drs.AccessMethod) error
	RemoveObjectControlledAccess(context.Context, string, string) error
	RemoveObjectControlledAccessBulk(context.Context, []string, string) (int, error)
	CreateObjectAlias(context.Context, string, string) error
	ResolveObjectAlias(context.Context, string) (string, error)
	ResolveObjectAliases(context.Context, []string) (map[string]string, error)
	ResolveObjectIDs(context.Context, []string) (map[string]string, error)
	GetObjectsByChecksums(context.Context, []string) (map[string][]drs.DrsObject, error)
	GetPublicReadByIDs(context.Context, []string) (map[string]bool, error)
	ListScopedObjectIDsByChecksums(context.Context, string, string, []string) (map[string][]string, error)
	ListObjectIDsByScope(context.Context, string, string) ([]string, error)
	ListObjectIDsByResources(context.Context, []string, bool) ([]string, error)
	ListObjectIDsPage(context.Context, ObjectIDPageQuery) ([]string, error)
}

ObjectStore is the persistence capability required by Service.

type PendingRegistration added in v0.4.3

type PendingRegistration struct {
	OID           string
	CandidateJSON []byte
	ReceiptJSON   []byte
	CreatedAt     time.Time
	ExpiresAt     time.Time
}

PendingRegistration identifies the staged LFS metadata that must still own an object when its catalog registration commits.

type RecordListQuery added in v0.4.2

type RecordListQuery struct {
	Scope          Scope
	Checksum       *ChecksumQuery
	ObjectURL      string
	StartAfter     string
	Limit          int
	Page           int
	RequiredMethod string
}

RecordListQuery describes the selection and pagination policy for a record listing.

type RegistrationMergeInput

type RegistrationMergeInput struct {
	ExistingName        string
	ExistingVersion     string
	ExistingDescription string
	ExistingSize        int64
	ExistingUpdated     time.Time
	IncomingName        string
	IncomingVersion     string
	IncomingDescription string
	IncomingSize        int64
	IncomingUpdated     time.Time
	IncomingResources   []string
	CurrentResources    []string
}

type RegistrationMergeResult

type RegistrationMergeResult struct {
	Name        string
	Version     string
	Description string
	Size        int64
	Updated     time.Time
	NameAlias   string
}

RegistrationMergeResult contains merged metadata and an optional name alias for the persistence write. It carries no SQL, context, or authorization state.

func MergeRegistrationMetadata

func MergeRegistrationMetadata(input RegistrationMergeInput) RegistrationMergeResult

MergeRegistrationMetadata applies registration-specific metadata replacement rules, including resource-overlap handling.

type RepairCandidatePage added in v0.4.3

type RepairCandidatePage struct {
	Objects        []drs.DrsObject
	Scanned        int
	NextStartAfter string
}

type RepairCandidateQuery added in v0.4.3

type RepairCandidateQuery struct {
	Scope      Scope
	Bucket     string
	Prefix     string
	StartAfter string
	Limit      int
}

type Scope added in v0.4.2

type Scope struct {
	Organization string
	Project      string
}

Scope identifies the optional organization/project boundary for a record query or mutation. An empty Scope represents an unscoped operation.

func NewScope added in v0.4.2

func NewScope(organization, project string) (Scope, error)

NewScope validates and normalizes an organization/project scope. A project cannot be supplied without an organization; an omitted scope is valid.

type ScopedObject added in v0.4.2

type ScopedObject struct {
	Object drs.DrsObject
	Scope  Scope
}

ScopedObject is a registration candidate together with the project scope whose access claim must be materialized before registration.

type Service added in v0.4.2

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

Service owns stateful object lookup and mutation operations.

func NewService added in v0.4.2

func NewService(store ObjectStore) *Service

func (*Service) BulkDeleteObjects added in v0.4.2

func (s *Service) BulkDeleteObjects(ctx context.Context, ids []string) error

func (*Service) BulkOverwriteObjects added in v0.4.2

func (s *Service) BulkOverwriteObjects(ctx context.Context, organization, project string, candidates []drs.DrsObject) (BulkOverwriteResult, error)

BulkOverwriteObjects replaces records from one project snapshot without canonicalizing checksum siblings. A checksum can therefore exist in more than one project, while still identifying an existing record in this scope.

func (*Service) BulkUpdateAccessMethodsAndRead added in v0.4.2

func (s *Service) BulkUpdateAccessMethodsAndRead(ctx context.Context, updates []drs.AccessMethodUpdate) ([]drs.DrsObject, error)

BulkUpdateAccessMethodsAndRead returns the durable DRS records in first-seen request order; the last update for a duplicate object ID wins.

func (*Service) CollapseProjectChecksumDuplicates added in v0.4.2

func (s *Service) CollapseProjectChecksumDuplicates(ctx context.Context, organization, project string) (int, error)

func (*Service) DeleteBulkByScope added in v0.4.2

func (s *Service) DeleteBulkByScope(ctx context.Context, organization, project string) (int, error)

func (*Service) DeleteBulkByScopeMatchingChecksum added in v0.4.3

func (s *Service) DeleteBulkByScopeMatchingChecksum(ctx context.Context, organization, project string, checksum ChecksumQuery) (int, error)

func (*Service) DeleteObject added in v0.4.2

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

func (*Service) DeleteObjectsByChecksums added in v0.4.2

func (s *Service) DeleteObjectsByChecksums(ctx context.Context, hashes []string) (int, error)

func (*Service) GetBulkObjects added in v0.4.2

func (s *Service) GetBulkObjects(ctx context.Context, ids []string, requiredMethod string) ([]drs.DrsObject, error)

func (*Service) GetObject added in v0.4.2

func (s *Service) GetObject(ctx context.Context, ident string, method string) (*drs.DrsObject, error)

GetObject retrieves the canonical record identified by ID, alias, or checksum and validates access.

func (*Service) GetObjects added in v0.4.4

func (s *Service) GetObjects(ctx context.Context, identifiers []string, method string) (map[string]LookupResult, error)

GetObjects resolves identifiers in one batch while preserving GetObject's per-identifier lookup and authorization rules.

func (*Service) GetObjectsByChecksums added in v0.4.2

func (s *Service) GetObjectsByChecksums(ctx context.Context, hashes []string, requiredMethod string) (map[string][]drs.DrsObject, error)

func (*Service) ListMissingScopedSHA256 added in v0.4.2

func (s *Service) ListMissingScopedSHA256(ctx context.Context, organization, project string, checksums []string) ([]string, error)

func (*Service) ListObjectIDsByScope added in v0.4.2

func (s *Service) ListObjectIDsByScope(ctx context.Context, organization, project string, requiredMethod string) ([]string, error)

func (*Service) ListObjects added in v0.4.2

func (s *Service) ListObjects(ctx context.Context, query RecordListQuery) ([]drs.DrsObject, error)

ListObjects returns one authorized page after project checksum-family merging.

func (*Service) ListPhysicalObjectsByScope added in v0.4.2

func (s *Service) ListPhysicalObjectsByScope(ctx context.Context, organization, project, requiredMethod string) ([]drs.DrsObject, error)

ListPhysicalObjectsByScope returns stored rows without checksum-family merging.

func (*Service) ListReadableObjectIDsAmongScopes added in v0.4.4

func (s *Service) ListReadableObjectIDsAmongScopes(ctx context.Context, scopes []Scope, requested []string) ([]string, error)

ListReadableObjectIDsAmongScopes applies each scope's read policy to the requested records while loading those records once.

func (*Service) ListRepairCandidates added in v0.4.3

func (s *Service) ListRepairCandidates(ctx context.Context, query RepairCandidateQuery) (RepairCandidatePage, error)

ListRepairCandidates returns checksum-identified records whose access rows are missing but whose stored S3 URL belongs to the requested project scope.

func (*Service) LookupChecksumQueries added in v0.4.2

func (s *Service) LookupChecksumQueries(ctx context.Context, queries []ChecksumQuery, requiredMethod string) ([][]drs.DrsObject, error)

LookupChecksumQueries preserves input order and duplicate queries.

func (*Service) RegisterCandidates added in v0.4.2

func (s *Service) RegisterCandidates(ctx context.Context, candidates []drs.DrsObjectCandidate) ([]drs.DrsObject, error)

RegisterCandidates materializes DRS candidates and returns their durable records in request order under the registration policy.

func (*Service) RegisterObjects added in v0.4.2

func (s *Service) RegisterObjects(ctx context.Context, objs []drs.DrsObject) ([]drs.DrsObject, error)

RegisterObjects persists objects and returns their durable records in the same order as the submitted objects.

func (*Service) RegisterObjectsIfPending added in v0.4.3

func (s *Service) RegisterObjectsIfPending(ctx context.Context, objs []drs.DrsObject, pending PendingRegistration) ([]drs.DrsObject, error)

func (*Service) RegisterScopedObjects added in v0.4.2

func (s *Service) RegisterScopedObjects(ctx context.Context, candidates []ScopedObject) ([]drs.DrsObject, error)

RegisterScopedObjects canonicalizes project access, materializes timestamps, authorizes, and registers a batch of scoped objects in input order.

func (*Service) RemoveObjectControlledAccess added in v0.4.2

func (s *Service) RemoveObjectControlledAccess(ctx context.Context, objectID, resource string) (*drs.DrsObject, error)

func (*Service) RepairMissingControlledAccess added in v0.4.3

func (s *Service) RepairMissingControlledAccess(ctx context.Context, id, sha string, scope Scope) error

RepairMissingControlledAccess restores a project association only when the record ID is derived from its SHA-256 and that exact project scope.

func (*Service) ReplaceCandidate added in v0.4.3

func (s *Service) ReplaceCandidate(ctx context.Context, objectID, expectedOldSHA string, candidate drs.DrsObjectCandidate) (*drs.DrsObject, error)

ReplaceCandidate replaces one DID after its bytes have been uploaded. The store checks the preflight SHA and applies the metadata mutation atomically.

func (*Service) ResolveObjectIDs added in v0.4.3

func (s *Service) ResolveObjectIDs(ctx context.Context, requested []string) (map[string]string, error)

ResolveObjectIDs maps physical IDs and aliases to their canonical physical IDs for callers that need to query data keyed by the canonical ID.

func (*Service) UpdateAccessMethodsAndRead added in v0.4.2

func (s *Service) UpdateAccessMethodsAndRead(ctx context.Context, objectID string, methods []drs.AccessMethod) (*drs.DrsObject, error)

UpdateAccessMethodsAndRead updates one record and returns its durable DRS representation. DRS object metadata is public, so write success does not depend on a second read-authorization check after commit.

func (*Service) UpdateObjectMetadata added in v0.4.2

func (s *Service) UpdateObjectMetadata(ctx context.Context, id string, update drs.DrsObject, scope Scope, explicitSize *int64) (drs.DrsObject, error)

Jump to

Keyboard shortcuts

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