daemon: configureLocalContentStore: return concrete types

The interface is defined on the receiver-side, and returning concrete
types makes it more transparent what we're creating.

As these namespaced wrappers were not exported, let's inline them, so
that it's clear at a glance what it's doing.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2023-07-18 14:18:42 +02:00
parent 375c4eb31c
commit 468d6616bf
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C

View file

@ -16,7 +16,7 @@ import (
"go.etcd.io/bbolt"
)
func (daemon *Daemon) configureLocalContentStore(ns string) (content.Store, leases.Manager, error) {
func (daemon *Daemon) configureLocalContentStore(ns string) (*namespacedContent, *namespacedLeases, error) {
if err := os.MkdirAll(filepath.Join(daemon.root, "content"), 0o700); err != nil {
return nil, nil, errors.Wrap(err, "error creating dir for content store")
}
@ -30,7 +30,15 @@ func (daemon *Daemon) configureLocalContentStore(ns string) (content.Store, leas
}
md := metadata.NewDB(db, cs, nil)
daemon.mdDB = db
return namespacedContentProvider(md.ContentStore(), ns), namespacedLeaseManager(metadata.NewLeaseManager(md), ns), nil
cp := &namespacedContent{
ns: ns,
provider: md.ContentStore(),
}
lm := &namespacedLeases{
ns: ns,
manager: metadata.NewLeaseManager(md),
}
return cp, lm, nil
}
// withDefaultNamespace sets the given namespace on the context if the current
@ -105,14 +113,6 @@ func (cp namespacedContent) ReaderAt(ctx context.Context, desc ocispec.Descripto
return cp.provider.ReaderAt(withDefaultNamespace(ctx, cp.ns), desc)
}
// namespacedContentProvider sets the namespace if missing before calling the inner provider
func namespacedContentProvider(provider content.Store, ns string) content.Store {
return namespacedContent{
ns,
provider,
}
}
type namespacedLeases struct {
ns string
manager leases.Manager
@ -147,11 +147,3 @@ func (nl namespacedLeases) List(ctx context.Context, filter ...string) ([]leases
func (nl namespacedLeases) ListResources(ctx context.Context, lease leases.Lease) ([]leases.Resource, error) {
return nl.manager.ListResources(withDefaultNamespace(ctx, nl.ns), lease)
}
// namespacedLeaseManager sets the namespace if missing before calling the inner manager
func namespacedLeaseManager(manager leases.Manager, ns string) leases.Manager {
return namespacedLeases{
ns,
manager,
}
}