Documentation
¶
Overview ¶
Package item writes and removes artifact items: deploy, checksum deploy, folders, client checksums and sidecars, delete into the trash can, copy, move, archive explode, the remote cache and zap, and the derived work the formats queue.
Role ¶
artifacts module, core layer. The deploy flow of decision 0004 and every other write of an item run here, and every write reaches the repository's format through its hooks (decision 0032). The target layout publishes this service to other modules as artifacts/api.Items, which P9d does not create: no other module calls it today, and artifacts/api's Status names it. As artifacts core, it never imports the module's adapters or an ecosystem http package (decision 0044, dependency rule 8); of the format slices it imports only the generic one, the handler a nil format registry falls back to.
Inputs ¶
- Driving: the artifacts HTTP handlers and the format protocol packages (deploy, checksum deploy, folders, delete, copy and move, explode, sidecars, restore); remote retrieval, which stores upstream content in a remote repository's cache (Cache) and zaps it (Zap); the build, registry and Terraform state services; and the composition root, which registers the formats' derived work and the remote cache cleanup with the work queue (RegisterWork, RegisterCacheMaintenance).
- Driven: the metadata store, through Store: what the formats see (format.Store: repositories, items, the package index, the remote cache and transactions), with the blob references, the trash can, the settings and configuration documents, the work queue and the lease table, which the registry and build services' stores embed; the blob store (platform/blob.Store); the format registry (core/format.Registry; nil means the generic handler for every type); the access module's Keys, which derived work signs metadata with; and the work queue that takes derived work (Enqueuer).
Outputs ¶
- Items and their blob references, written in one transaction, with the format's hooks run inside it and the package index kept in step (core/pkgindex).
- Deleted content moved to the trash can while it is on, and restored from it (Restore); purged content's blob references released.
- Copy and move results (TransferResult), explode results, and the remote cache's entries and zap counts.
- Derived work queued on the persistent work queue (decision 0033), and its runs: reindexes (Reindex, ReindexPath) and the remote cache cleanup (KindCacheCleanupSchedule, KindCacheCleanup).
- Errors the HTTP layer maps onto statuses: ErrChecksumMismatch, ErrBadChecksum, ErrNoBlob, ErrConflict, ErrCollected, ErrBadArchive, ErrOverwriteDenied with OverwriteDeniedError, and SidecarError.
- StorageFault, with MarkStorageFault: a failure of the server's own storage while the cache keeps a remote file: a failed open or read of its copy by the format's Validate hook, its inspection or a publication hook, a failed write or commit of the copy or of its spool file, or a failed call of the store that publishes it (the store's verdicts, not found, conflict and invalid, excepted). It is format.ErrStorageFault, a server fault, not the upstream's; a failed read of the upstream's body stays the upstream's (https://github.com/weaveplatform/artifactweave/issues/1269). So is a format hook's failure (guard, Admit, Deployed, Annotated) while the cache keeps a file when a statement the store failed to run lies under it (kernel.ErrStore); a hook's refusal keeps its error (https://github.com/weaveplatform/artifactweave/issues/1470).
Invariants ¶
- Content is written to the blob store before the transaction opens, so no blob write holds the write lock; the item and its blob reference then commit together or not at all.
- Every write runs the repository's format hooks inside its transaction, so a format indexes what it deploys and a delete prunes the package index for every format.
- Work kind strings and the JSON written to work items are persisted, so they never change; error and refusal texts reach clients and stay byte-identical, Artifactory's where JFrog documents one.
References ¶
- Decision 0004: docs/research/decisions/0004-storage-sql-metadata-and-blobs.md (the deploy flow, items and content-addressed blobs).
- Decision 0010: docs/research/decisions/0010-retention-trash-and-gc.md (the trash can).
- Decision 0032: docs/research/decisions/0032-package-format-handlers.md (every write reaches a format through the item service).
- Decision 0033: docs/research/decisions/0033-persistent-work-queue.md (derived work and cache maintenance kinds).
- Decision 0044: docs/research/decisions/0044-modular-monolith-migration.md, "Public types and published api surface" and "Dependency rules".
- Research 24: docs/research/24-package-format-handlers.md.
- Target layout: docs/research/architecture-options/5-modular-monolith.md, lines 199 to 200 (core/item), the deploy write path at lines 459 to 500, line 1029 (the mapping row) and rule 2 at lines 35 to 36.
- Plan: docs/implementation/plan.md#p3-repositories-generic-artifacts-cli-aql-shape to #p9-remote-repositories, and #p9d-modular-monolith-migration, epic ART (https://github.com/weaveplatform/artifactweave/issues/941).
- https://github.com/weaveplatform/artifactweave/issues/1010 and https://github.com/weaveplatform/artifactweave/issues/1088
Status ¶
Implemented P3 to P9c. Moved here in P9d. Roadmap: gate.go (P17), events.go (P11).
Testing ¶
- item_test.go, format_test.go, admit_test.go and overwrite_test.go: deploys, checksums and the format hooks around every write.
- transfer*_test.go, archive_test.go and sidecar_test.go: copy and move, explode and checksum sidecars.
- cache_test.go, cache_check_test.go, cache_fault_test.go, cache_hook_test.go, cache_maintenance_test.go, smart_test.go and restore_test.go: the remote cache, a failed read of its copy under check, a failed write or store call while it keeps one, a statement the store failed to run under a hook, its cleanup, smart remote properties, restore and zap. cache_restart_test.go's TestAcc tests run the cleanup over SQLite across a restart and a concurrent download.
- work_test.go: derived work and reindexes; fault_test.go, guard_test.go and the *_absent_test.go files: store failures, write guards and races.
- snapshot_parity_test.go (package item_test): the item service's non-unique snapshot rule matches the Maven slice's.
Index ¶
- Constants
- Variables
- func DeclaresContentOf(declared kernel.Checksums, f model.Item) bool
- func FolderDownload(ctx context.Context, st interface{ ... }) (model.FolderDownloadSettings, error)
- func MarkStorageFault(ctx context.Context, cause, err error) error
- func MergeRemoteProperties(current model.Properties, prior *model.RemoteSmartState, ...) (model.Properties, *model.RemoteSmartState)
- func MimeType(name string) string
- func ParseChecksums(c kernel.Checksums) (kernel.Checksums, error)
- func RefuseLabel(c repo.Config, path, label string, accept []string) error
- func ServedChecksum(c repo.Config, it model.Item, a Algorithm) string
- func TrashEnabled(ctx context.Context, st interface{ ... }) (bool, error)
- type Algorithm
- type ArchiveKind
- type CacheResult
- type CacheUpload
- type Deploy
- type Enqueuer
- type Explode
- type Freshener
- type MIMERefusal
- type Message
- type OverwriteDeniedError
- type Service
- func (s *Service) Annotate(ctx context.Context, c repo.Config, it model.Item, set model.Properties, ...) error
- func (s *Service) ArchiveEntry(ctx context.Context, it model.Item, entry string, ...) error
- func (s *Service) ArchiveFiles(ctx context.Context, files []model.Item, base string, kind ArchiveKind, ...) error
- func (s *Service) Cache(ctx context.Context, u CacheUpload) (CacheResult, error)
- func (s *Service) Delete(ctx context.Context, t Target, by string) (port.DeleteResult, error)
- func (s *Service) Deploy(ctx context.Context, d Deploy) (model.Item, error)
- func (s *Service) DeployByChecksum(ctx context.Context, d Deploy) (model.Item, error)
- func (s *Service) DeployCommitted(ctx context.Context, d Deploy, info blob.Info) (model.Item, error)
- func (s *Service) EnsureRoot(ctx context.Context, t Target, by string) (model.Item, error)
- func (s *Service) Env() format.Env
- func (s *Service) Explode(ctx context.Context, d Explode) (model.Item, error)
- func (s *Service) HasRemoteProperties(ctx context.Context, token model.RemoteCacheToken) (bool, error)
- func (s *Service) Layout(ctx context.Context, name string) (*layout.Layout, error)
- func (s *Service) MakeFolder(ctx context.Context, t Target, props model.Properties, by string) (model.Item, error)
- func (s *Service) OwnsSidecars(c repo.Config) bool
- func (s *Service) PropagateRemotePropertyState(ctx context.Context, current model.RemoteCacheEntry) error
- func (s *Service) Purge(ctx context.Context, t Target) (port.DeleteResult, error)
- func (s *Service) RecordChecksum(ctx context.Context, t Target, a Algorithm, value string) (model.Item, error)
- func (s *Service) RecordSidecar(ctx context.Context, t Target, a Algorithm, value string, size int64) (model.Item, error)
- func (s *Service) RegisterCacheMaintenance(ctx context.Context, q *work.Queue) error
- func (s *Service) RegisterWork(q *work.Queue) error
- func (s *Service) Reindex(ctx context.Context, c repo.Config) error
- func (s *Service) ReindexPath(ctx context.Context, c repo.Config, path string) error
- func (s *Service) Resolve(ctx context.Context, c repo.Config, d format.Download) (string, error)
- func (s *Service) Restore(ctx context.Context, t Target, rec model.TrashRecord, by string) (model.Item, error)
- func (s *Service) Sidecars(c repo.Config, p string) []string
- func (s *Service) SidecarsBeside(ctx context.Context, t Target, to string) ([]SidecarMove, error)
- func (s *Service) Transfer(ctx context.Context, t Transfer) (TransferResult, error)
- func (s *Service) Tree(ctx context.Context, t Target) ([]model.Item, error)
- func (s *Service) Upload(ctx context.Context, d Deploy) (blob.Info, error)
- func (s *Service) Zap(ctx context.Context, t Target) (int, error)
- type SidecarError
- type SidecarMove
- type StorageFault
- type Store
- type Target
- type Transfer
- type TransferResult
Constants ¶
const ( // MaxExplodeBytes bounds both the uploaded archive and the total of its // extracted entries. MaxExplodeBytes = 4 << 30 // MaxExplodeEntries bounds the entries of one archive. MaxExplodeEntries = 10_000 )
Limits on exploding an archive. Entry sizes in an archive's headers are the uploader's claim, so the extracted bytes are counted as they are written, which is what stops a zip bomb.
const ( NotArchive = archive.KindNone Zip = archive.KindZip Tar = archive.KindTar TarGz = archive.KindTarGz )
Archive kinds; NotArchive is a file none of them.
const ( KindCacheCleanupSchedule = "remote.cache-cleanup-schedule" KindCacheCleanup = "remote.cache-cleanup" CacheCleanupInterval = time.Hour CacheCleanupBatch = 128 )
The remote cache cleanup's work on the persistent queue (decision 0033). KindCacheCleanupSchedule is the scheduler, one item keyed "scan" that runs every CacheCleanupInterval and queues a KindCacheCleanup item, keyed by the repository, for each remote repository with a positive unusedArtifactsCleanupPeriodHours. Each KindCacheCleanup run cleans one page of at most CacheCleanupBatch cache entries or cached items and queues the next page at once. The two kind strings are persisted in work items, so they never change: an item queued under an old kind would never run again.
const ( PropTrashOriginalRepository = "trash.originalRepository" PropTrashRestoredTime = "trash.restoredTime" )
The properties a restore sets on every item it brings back. 7.x lists both on restored items (RTFACT-29810); their values are 6.20's: the key of the repository the item was deleted from, and the restore's time in Unix milliseconds (TrashService, TrashInterceptor.afterMove).
const ( LevelInfo = "INFO" LevelWarning = "WARNING" LevelError = "ERROR" )
Levels of a copy or move message (the CopyOrMoveMessage enum).
Variables ¶
var ( ErrRemoteLength = errors.New("item: remote response length mismatch") ErrRemoteMIME = errors.New("item: remote response mime mismatch") ErrRemoteLimit = errors.New("item: remote response exceeds limit") ErrRemoteChecksumRequired = errors.New("item: upstream checksum required") )
Remote ingestion errors are source failures, never negative cache entries.
var ( // ErrChecksumMismatch is a declared checksum that differs from the // content under the client-checksums policy (409). ErrChecksumMismatch = errors.New("item: checksum mismatch") // ErrBadChecksum is a declared checksum that is not hex of a known // length (400). ErrBadChecksum = errors.New("item: malformed checksum") // ErrNoBlob is a checksum deploy for content the server does not hold // (404, after which the client uploads the content). ErrNoBlob = errors.New("item: no stored content has the checksum") // ErrConflict is a file where a folder must go, or the reverse (409). ErrConflict = errors.New("item: path conflict") // ErrCollected is content garbage collection removed while it was being // deployed: nothing was stored, and the deploy must be repeated (503, // which the JFrog CLI retries). ErrCollected = errors.New( "item: the content was removed by garbage collection while it was deployed; deploy it again", ) // ErrNotFound is a missing item. ErrNotFound = kernel.ErrNotFound // ErrExists is a deploy with IfAbsent to a path that holds an item. ErrExists = errors.New("item: the path already holds an item") )
Errors the HTTP layer maps onto statuses.
var ErrBadArchive = archive.ErrUnusable
ErrBadArchive is an upload that is not a usable archive: an unknown or corrupt format, an entry escaping its folder, or limits exceeded (400).
var ErrDuplicateKind = errors.New("item: two formats claim one kind of work")
ErrDuplicateKind reports two formats that claim one kind of work.
var ErrInvalidTransfer = errors.New("item: invalid copy or move")
ErrInvalidTransfer is a copy or move that cannot run at all: onto itself, into its own subtree, or below a file at the target (400).
var ErrNoReindex = errors.New("item: the format keeps no index to rebuild")
ErrNoReindex reports a package type whose format keeps no index to rebuild.
var ErrNoSource = fmt.Errorf("item: no source: %w", kernel.ErrNotFound)
ErrNoSource is a copy or move whose source does not exist (400 with a report). It wraps kernel.ErrNotFound, so a caller that tests for that, such as a promotion whose file went in the meantime, still sees a miss.
var ErrOverwriteDenied = errors.New("item: no permission to overwrite")
ErrOverwriteDenied is a deploy or an explode that would replace existing files the caller may not delete (403). The service returns it as an *OverwriteDeniedError, which names the file and the caller.
Functions ¶
func DeclaresContentOf ¶
DeclaresContentOf reports whether parsed declared checksums name f's content: a SHA-1 or SHA-256 that equals f's, and neither that differs. MD5 and SHA-512 do not count, as in Artifactory 6.20's isFileOverwrite, which compares the SHA-1 and SHA-256 alone.
func FolderDownload ¶
func FolderDownload( ctx context.Context, st interface{ Settings() settings.SettingsStore }, ) (model.FolderDownloadSettings, error)
FolderDownload reads the folder download setting, with Artifactory's defaults for what is unset: off, 1024 MB and 5000 files.
func MarkStorageFault ¶
MarkStorageFault is err, an error that cause, a failure of the server's own storage, brought about, marked as a StorageFault, unless ctx is done: a call that fails because the request ended answers as it did before. An error already marked keeps its mark.
func MergeRemoteProperties ¶
func MergeRemoteProperties( current model.Properties, prior *model.RemoteSmartState, incoming model.Properties, at time.Time, ) (model.Properties, *model.RemoteSmartState)
MergeRemoteProperties changes only values which still match the previous synchronized value. A local edit or deletion permanently takes ownership of that key for this source lifetime; upstream disappearance cannot erase it.
func ParseChecksums ¶
ParseChecksums checks declared checksums: lowercase hex of the length of their algorithm, or empty.
func RefuseLabel ¶
RefuseLabel is the check Cache makes of a file with no format hint, for an upstream answer whose body is not cached, such as a HEAD's: a *MIMERefusal when c refuses label for path, the URL asked for or the file's path (requestedName), under the client's accept values, nil otherwise.
func ServedChecksum ¶
ServedChecksum is the value of the file it that its sidecar for algorithm a answers a GET with, where c is the repository that holds the file, as Artifactory's LocalRepoChecksumPolicy.getChecksum (6.20) chooses it. Under client-checksums it is the client's checksum, and empty while the client has sent none, so the sidecar answers 404 until one is deployed, as local-repositories documents for 7.x. Under server-generated-checksums, for a file named maven-metadata.xml in any repository (the server computes those checksums, and drops a client's), and in a remote cache, which that policy does not govern, it is the computed checksum.
func TrashEnabled ¶
func TrashEnabled( ctx context.Context, st interface{ Settings() settings.SettingsStore }, ) (bool, error)
TrashEnabled reads the trash can setting; unset means on, as in Artifactory.
Types ¶
type Algorithm ¶
type Algorithm string
Algorithm names a checksum sidecar's digest.
const ( SHA256 Algorithm = "sha256" SHA512 Algorithm = "sha512" SHA1 Algorithm = "sha1" MD5 Algorithm = "md5" )
Sidecar algorithms, by file extension.
type ArchiveKind ¶
ArchiveKind is an archive container format.
func ParseArchiveKind ¶
func ParseArchiveKind(s string) (ArchiveKind, bool)
ParseArchiveKind reads an archiveType parameter (zip, tar, tar.gz, tgz).
type CacheResult ¶
type CacheResult struct {
Declared kernel.Checksums
Entry model.RemoteCacheEntry
Item model.Item
Info blob.Info
Body io.ReadSeekCloser
}
CacheResult is either committed content or an owned transient reader. Close Body after a no-store response; closing removes its temporary file.
type CacheUpload ¶
type CacheUpload struct {
// SmartProperties is a complete validated peer snapshot. Merge it inside
// the publication transaction so a concurrent local annotation wins.
SmartProperties *model.Properties
SmartPropertiesStarted time.Time
// Expected comes from authoritative protocol metadata, not optional remote
// headers. It is enforced even when their checksum policy says ignore.
Expected kernel.Checksums
// Validate inspects complete bytes outside SQL, before either publication
// or transient delivery. It must not retain or close its reader.
Validate func(context.Context, io.ReadSeeker, int64) error
Token model.RemoteCacheToken
Repo repo.Config
Body io.Reader
Kind model.RemoteKind
Declared kernel.Checksums
Properties model.Properties
// PublishMetadata keeps protocol metadata in its native item/index layout
// while retaining metadata expiry and zap behavior. Ordinary raw upstream
// metadata deliberately stays outside the derived package tree.
PublishMetadata bool
Length int64 // -1 means unknown; zero requires an empty body
// ExpectedContentType is a trusted format-adapter hint for raw metadata
// whose route has no extension (for example a PyPI HTML simple index).
// Never derive it from the upstream Content-Type or arbitrary caller Accept.
ExpectedContentType string
ExpectedContentTypes []string
RemoteURL string // sanitized origin, without userinfo or query
ContentType string
ETag string
LastModified string
CacheControl string
Vary string
By string
NoStore bool
// MaxBytes bounds transient storage and parsed metadata, zero means the
// default 64MiB for metadata and no additional artifact size limit.
MaxBytes int64
CheckCurrent func(context.Context, Store) error
// ClientAccept is the client's Accept values for a file with no format
// hint, which 7.x's MIME check takes the requested types from
// (HttpRepo.getAcceptableHeaders); nil, as for a format route, takes
// the type of RequestURL. Only that check reads it: it is not part of
// the cache identity.
ClientAccept []string
// RequestURL is the URL the upstream was asked for, the one 7.x's
// refusal names (requestedName); empty takes the path's type.
RequestURL string
}
CacheUpload is a complete upstream response awaiting validation/publication. Token was obtained before network I/O. CheckCurrent rechecks authorization and effective proxy/certificate revision without network I/O in the transaction.
type Deploy ¶
type Deploy struct {
Target
// Body is streamed into the blob store; a checksum deploy ignores it.
Body io.Reader
// ResolvePath derives a destination from the format inspection before any
// transaction begins, for uploads whose content names their canonical path.
// Its error refuses the write without publishing items or package metadata.
ResolvePath func(inspection any) (string, error)
// Declared holds the checksums the client sent.
Declared kernel.Checksums
// Properties are set on the item (matrix parameters).
Properties model.Properties
By string
// IfAbsent stores the file only when nothing is at its path, and
// refuses with ErrExists otherwise, for a file published once, such as
// an npm version's tarball. The check is made in the write's
// transaction, after the content is stored.
IfAbsent bool
// CanOverwritePath, when set, is the caller's right to replace the file
// at a full path. It is asked about the path the format admits, which a
// format may rename (Maven's unique snapshots), so a caller's check of
// the path it sent does not cover it; an *OverwriteDeniedError naming
// that path and By when it says no.
CanOverwritePath func(fullPath string) bool
// OverwriteIdentical replaces a file without CanOverwritePath's consent
// when the deploy declares the file's content (DeclaresContentOf) and
// stores exactly that content, as Artifactory lets a re-deploy of
// identical content through without the delete permission. The stored
// content is compared too, because a declaration alone is only the
// client's claim: under server-generated-checksums nothing checks it.
OverwriteIdentical bool
// Trusted records the computed checksums as the client's, as
// Artifactory does for the files it writes itself (6.20
// InternalArtifactoryRequest.isTrustServerChecksums) and for a checksum
// deploy. A file the server writes, such as a build-info document or a
// registry's manifest, has no client to send its checksums, and under
// client-checksums its checksum files would otherwise answer 404.
Trusted bool
// Reusable, when set, decides whether a checksum deploy may store the
// content it found; when it says no, the deploy fails with ErrNoBlob as
// if the content were not there, so the answer does not reveal that it
// is. A caller's checksum deploy sets it (knowing a checksum must not
// copy content the caller cannot read); a write that already holds the
// content, such as a registry upload's completion, leaves it nil.
Reusable func(ctx context.Context, b blob.Blob) (bool, error)
// contains filtered or unexported fields
}
Deploy is a file write.
type Explode ¶
type Explode struct {
Deploy
// Atomic stores every entry or none.
Atomic bool
// CanOverwrite is the caller's right to replace existing files.
CanOverwrite bool
}
Explode is a deploy whose body is an archive: its entries are deployed into the folder of Path, and the archive itself is not stored.
type Freshener ¶
Freshener brings derived work up to date before a reader reads what it derives; *work.Queue is one.
type MIMERefusal ¶
MIMERefusal is ErrRemoteMIME with what 7.x's refusal names: the requested types, in the order its message lists them, and the upstream's label.
func (*MIMERefusal) Error ¶
func (e *MIMERefusal) Error() string
func (*MIMERefusal) Is ¶
func (e *MIMERefusal) Is(target error) bool
Is makes a refusal ErrRemoteMIME, which a format route answers as before.
func (*MIMERefusal) Message ¶
func (e *MIMERefusal) Message(url string) string
Message is HttpRepo.blockMismatchingMimeTypes's text for a refusal of the file at url. The list is a Java Set's toString, "[a, b]".
type OverwriteDeniedError ¶
type OverwriteDeniedError struct {
// Repo is the key of the repository that holds the file.
Repo string
// Path is the file's path in it, where the format stored the write,
// which for a Maven unique snapshot is not the path sent.
Path string
// User is the caller's name: kernel.AnonymousUser for an anonymous one.
User string
}
OverwriteDeniedError is a write refused because it would replace a file the caller may not delete. Its text is Artifactory 7.x's, which clients match rather than read: Poetry's publish --skip-existing takes a 403 whose text holds "overwrite artifact" for a file that is already there, and fails on any other wording.
func (*OverwriteDeniedError) Error ¶
func (e *OverwriteDeniedError) Error() string
Error returns Artifactory 7.x's text for the refusal, naming the repository, the path and the user. Clients match it, so it stays byte-identical.
func (*OverwriteDeniedError) Unwrap ¶
func (e *OverwriteDeniedError) Unwrap() error
Unwrap returns ErrOverwriteDenied, so errors.Is matches every overwrite refusal whatever its repository, path and user.
type Service ¶
type Service struct {
Store Store
Blobs blob.Store
// Keys is the format.Env.Keys of every operation, which the formats'
// derived work signs Alpine, Debian, Opkg and RPM metadata with. Nil
// leaves Env.Keys nil, so a service that runs derived work for a
// repository that names a signing key pair must set it.
Keys accessapi.Keys
// Now supplies the time; nil means time.Now.
Now func() time.Time
// Formats returns a package type's format; nil means the generic
// handler for every type, which indexes nothing, so a service that
// writes to other formats' repositories must set it. Tests substitute
// formats that record or fail their hooks.
Formats format.Registry
// Work takes the derived work formats ask for. Nil writes it to the
// store's queue directly, where every node's workers find it on their
// next poll; a queue also wakes its own idle workers on commit.
Work Enqueuer
// Periodic names the kinds of derived work RegisterWork runs on a timer
// rather than as soon as they are due, each with its interval
// (work.Queue.HandleEvery).
Periodic map[string]time.Duration
// ReindexAuthorize checks the original caller of queued remote maintenance.
// A remote job fails closed when this runtime hook is absent.
ReindexAuthorize func(context.Context, repo.Config, format.WorkRequest) error
}
Service writes items into a store and its blob store.
func (*Service) Annotate ¶
func (s *Service) Annotate( ctx context.Context, c repo.Config, it model.Item, set model.Properties, remove []string, ) error
Annotate changes the properties of it, an item of c: set replaces the values of its keys and remove drops keys. It runs inside ctx's transaction, or one of its own, once the format admits the change (format.AnnotationAdmitter), and with the format's Annotated hook, so a format whose index follows properties stays in step whichever API made the change.
func (*Service) ArchiveEntry ¶
func (s *Service) ArchiveEntry( ctx context.Context, it model.Item, entry string, serve func(size int64, r io.Reader) error, ) error
ArchiveEntry finds the entry at entry inside the archive file it and calls serve with its size and content, returning serve's error. ErrNotFound when the file is not an archive, is a corrupt one or has no such entry, or when serve fails on a read of an entry too corrupt to read through; when a read of the file's blob fails, the error is that read's.
func (*Service) ArchiveFiles ¶
func (s *Service) ArchiveFiles( ctx context.Context, files []model.Item, base string, kind ArchiveKind, sums bool, w io.Writer, ) error
ArchiveFiles writes files to w as one archive of kind, each named by its path relative to base, with ".md5", ".sha1" and ".sha256" sidecars when sums is set. The archive is streamed: nothing is buffered beyond one file's copy buffer.
func (*Service) Cache ¶
func (s *Service) Cache(ctx context.Context, u CacheUpload) (CacheResult, error)
Cache streams and validates outside SQL, then atomically publishes item/index hooks and raw cache state. A failed refresh never changes the former entry.
func (*Service) Delete ¶
Delete removes the item at t.Path and everything below it ("" is the repository root), with the sidecars its format keeps with each file (format.SidecarKeeper). Files of local repositories go to the trash can when it is on, keeping their blob references for a restore; otherwise, and for remote caches, the references are released for garbage collection.
func (*Service) DeployByChecksum ¶
DeployByChecksum stores the item from content the server already holds, found by the strongest declared checksum. Every other declared checksum must match too, and d.Reusable must allow it; otherwise, and when the content is gone, ErrNoBlob.
func (*Service) DeployCommitted ¶
func (s *Service) DeployCommitted( ctx context.Context, d Deploy, info blob.Info, ) (model.Item, error)
DeployCommitted stores the item for content the caller already committed to the blob store, the second half of Deploy. A registry upload commits in a later request than it began, so it cannot hand Deploy a body.
func (*Service) EnsureRoot ¶
EnsureRoot returns the record of the root of t's repository, or of its cache when t.Cached, creating it when absent. The record holds the properties set on the repository itself (port.ItemStore).
func (*Service) Env ¶
Env is the environment of one operation a format offers beside its hooks, such as Maven's calculateMetadata, which reads and queues as a hook does.
func (*Service) Explode ¶
Explode deploys the entries of the archive in d.Body and returns the folder they landed in. The archive is spooled to a temporary file, checked against d.Declared, and read twice: once to validate every entry name and the limits, so nothing is written for an archive that would be refused, then to store the entries. Only the archive's own faults are ErrBadArchive: a failed read of the spooled archive, or a blob store that fails to write an entry, returns its own error, which the routes answer 500.
func (*Service) HasRemoteProperties ¶
func (s *Service) HasRemoteProperties( ctx context.Context, token model.RemoteCacheToken, ) (bool, error)
HasRemoteProperties applies legacy initial-only synchronization to the item, not each HTTP representation another client may independently request.
func (*Service) Layout ¶
Layout compiles a repository layout: one the descriptor stored, else a bundled one.
func (*Service) MakeFolder ¶
func (s *Service) MakeFolder( ctx context.Context, t Target, props model.Properties, by string, ) (model.Item, error)
MakeFolder creates the folder at t.Path and its parents, once the format admits it (format.FolderAdmitter); an existing folder is returned as it is, with props added.
func (*Service) OwnsSidecars ¶
OwnsSidecars reports whether c's format takes every upload named as a checksum sidecar as one, even without its file (format.SidecarOwner).
func (*Service) PropagateRemotePropertyState ¶
func (s *Service) PropagateRemotePropertyState( ctx context.Context, current model.RemoteCacheEntry, ) error
PropagateRemotePropertyState keeps item-level ownership coherent across a bounded set of current HTTP representations. It joins the caller's item/cache transaction and preserves each representation's separate statistics claims.
func (*Service) Purge ¶
Purge is Delete bypassing the trash can: the references are released at once. It is for an item whose record lives elsewhere, such as a build-info document (decision 0014), which a restore would bring back without its run.
func (*Service) RecordChecksum ¶
func (s *Service) RecordChecksum( ctx context.Context, t Target, a Algorithm, value string, ) (model.Item, error)
RecordChecksum is RecordSidecar for a sidecar whose length is unknown.
func (*Service) RecordSidecar ¶
func (s *Service) RecordSidecar( ctx context.Context, t Target, a Algorithm, value string, size int64, ) (model.Item, error)
RecordSidecar handles a checksum sidecar upload of size bytes (-1 when the client declared none) for the file at t.Path, once the format admits it: the client's value is recorded as the file's original checksum, and under the client-checksums policy it must equal the content's (decision 0004).
func (*Service) RegisterCacheMaintenance ¶
RegisterCacheMaintenance registers a periodic scheduler and bounded worker. Existing queued pages survive restart. The scheduler repeats; each repository worker drains pages without waiting another hour between batches.
func (*Service) RegisterWork ¶
RegisterWork registers with q a handler for the reindex kinds every format shares and for every kind of derived work a format runs, each run through s, on a timer for the kinds s.Periodic names. Call it before q.Run, which leases only the kinds registered when it starts.
func (*Service) Reindex ¶
Reindex rebuilds c's package index from its item tree through its format; ErrNoReindex when the format keeps none.
func (*Service) ReindexPath ¶
ReindexPath rebuilds the part of c's package index that the files under path give, through a format that is a PathReindexer, or the whole index through any other Reindexer; ErrNoReindex when the format keeps none.
func (*Service) Resolve ¶
Resolve returns the path a download d from c, a repository that is not virtual, reads: the format's resolution of it, or d.Path itself. The derived work the format owes that path is done first (EnsureFresh).
func (*Service) Restore ¶
func (s *Service) Restore( ctx context.Context, t Target, rec model.TrashRecord, by string, ) (model.Item, error)
Restore recreates a trashed item at t.Path with its recorded content, times and properties, creating missing parent folders, and runs the format's hooks as a deploy does. Call it inside a transaction that also removes the trash entry: a trashed file still holds its blob reference, which the restored item takes over, so no reference is taken here. A file it replaces releases its own reference, as an overwrite by deploy does; a folder already at the path keeps its content and gains the recorded properties. A folder in the way of a file, or a file in the way of a folder, is ErrConflict. Every restored item also carries PropTrashOriginalRepository and PropTrashRestoredTime.
func (*Service) Sidecars ¶
Sidecars returns the paths in c of the sidecars that the file at p owns and that c's format keeps with it (format.SidecarKeeper), whether or not any exists; none when the format keeps none.
func (*Service) SidecarsBeside ¶
SidecarsBeside returns the stored sidecars that the file at t.Path keeps (format.SidecarKeeper), each with its path beside to, the file's target; to is t.Path for a delete. None for a folder, a path with nothing at it, a format that keeps none, or a target the format gives no such sidecar, which a transfer leaves behind (planFollowers). Those are the paths a delete, copy or move of the file changes besides its own, which a caller must hold the same rights on (decision 0039).
func (*Service) Transfer ¶
Transfer copies or moves t.From to t.To. Every item is planned first: an item that cannot land (a file where a folder must go, or the reverse, an overwrite the caller may not make, or a file the target's format refuses) is reported and skipped with its subtree, or ends the plan when t.FailFast. A file's sidecars that its format keeps with it go with it (format.SidecarKeeper). The planned items are then written in one transaction; a dry run stops after the plan.
func (*Service) Tree ¶
Tree lists the item at t.Path (none for the repository root) and every item below it, parents before their children.
func (*Service) Upload ¶
Upload streams d.Body into the blob store and commits it under the repository's checksum policy, as Deploy does, but stores no item, for a caller that must see the content's digests before deciding what to store: DeployCommitted then stores it. Content no item comes to reference is collected as an orphan.
type SidecarError ¶
SidecarError is a checksum sidecar upload refused for its file, with Artifactory's answer (UploadServiceImpl.validatePathAndUploadChecksum): Err is kernel.ErrNotFound for a missing file, ErrConflict for a folder and ErrChecksumMismatch for a value the client-checksums policy refuses.
func (*SidecarError) Error ¶
func (e *SidecarError) Error() string
Error returns Message, Artifactory's text for the refusal, which the HTTP layer answers with as it is.
func (*SidecarError) Unwrap ¶
func (e *SidecarError) Unwrap() error
Unwrap returns Err, so errors.Is tells a missing file, a folder and a refused checksum apart.
type SidecarMove ¶
type SidecarMove struct {
From, To string
}
SidecarMove is a stored sidecar of a file, at From, and the path To beside the file's target where a copy or move of the file takes it.
type StorageFault ¶
StorageFault is a failure of the server's own storage while the cache keeps a remote file: a failed open or read of the copy it checks or inspects or that a hook reads, a failed write of the copy or of its spool file, or a failed call of the store that publishes it. It is format.ErrStorageFault and Cause, the store's error, and so answers 500 "internal error" rather than the 502 an upstream's failure gets.
Err is the error the cache returned without the mark, and is not unwrapped: a hook's refusal must not answer for a fault of the storage. The remote policy maps it as it did before wherever that answer served a stale copy or counted toward the assumed-offline circuit (remote.PolicyError), so only what answered 502 changes.
func (*StorageFault) Error ¶
func (e *StorageFault) Error() string
Error names the store's error, for the log.
func (*StorageFault) Unwrap ¶
func (e *StorageFault) Unwrap() []error
Unwrap is format.ErrStorageFault and the store's error.
type Store ¶
type Store interface {
format.Store
Blobs() port.BlobIndex
Trash() port.TrashStore
Settings() settings.SettingsStore
Configs() configdoc.ConfigStore
WorkQueue() work.WorkQueue
Leases() work.LeaseStore
}
Store is what the item service reads and writes: what its formats see (format.Store), with the blob index, the trash can, the settings and configuration documents, the work queue and the lease table. Every call joins the transaction ctx carries, and the service runs each operation as one transaction through Tx, so the blob references, the trash entries and the work a write queues commit or roll back with the item. Each composite store in app is a Store.
type Target ¶
Target is where a write lands: a repository (or its remote cache) and a repository-relative path without a leading slash.
type Transfer ¶
type Transfer struct {
From Target
To Target
// IntoFolder is a target given with a trailing slash: the source lands
// inside it under its own name, as it does inside an existing folder.
IntoFolder bool
Move bool
Dry bool
FailFast bool
// TranslateLayouts converts file paths from the source repository's
// layout to the target's (suppressLayouts=0).
TranslateLayouts bool
// CanOverwrite is the caller's right to replace files at the target.
CanOverwrite bool
// IfAbsent requires a new destination file, including when another
// writer creates it after planning. A collision rolls back the transfer.
IfAbsent bool
By string
}
Transfer is a copy or a move of the item at From.Path (a file, a folder and everything below it, or "" for the whole repository) to To.