Files
at-container-registry/pkg/hold/pds/imageconfig.go
T

54 lines
1.6 KiB
Go

package pds
import (
"context"
"fmt"
"atcr.io/pkg/atproto"
"github.com/ipfs/go-cid"
)
// CreateImageConfigRecord creates or updates an OCI image config record in the hold's PDS.
// Uses a deterministic rkey based on the manifest digest, so re-pushes upsert.
func (p *HoldPDS) CreateImageConfigRecord(ctx context.Context, record *atproto.ImageConfigRecord, manifestDigest string) (string, cid.Cid, error) {
if record.Type != atproto.ImageConfigCollection {
return "", cid.Undef, fmt.Errorf("invalid record type: %s", record.Type)
}
if record.Manifest == "" {
return "", cid.Undef, fmt.Errorf("manifest AT-URI is required")
}
rkey := atproto.ScanRecordKey(manifestDigest)
rpath, recordCID, _, err := p.repomgr.UpsertRecord(
ctx,
p.uid,
atproto.ImageConfigCollection,
rkey,
record,
)
if err != nil {
return "", cid.Undef, fmt.Errorf("failed to upsert image config record: %w", err)
}
return rpath, recordCID, nil
}
// GetImageConfigRecord retrieves an OCI image config record by manifest digest.
func (p *HoldPDS) GetImageConfigRecord(ctx context.Context, manifestDigest string) (cid.Cid, *atproto.ImageConfigRecord, error) {
rkey := atproto.ScanRecordKey(manifestDigest)
recordCID, val, err := p.repomgr.GetRecord(ctx, p.uid, atproto.ImageConfigCollection, rkey, cid.Undef)
if err != nil {
return cid.Undef, nil, fmt.Errorf("failed to get image config record: %w", err)
}
configRecord, ok := val.(*atproto.ImageConfigRecord)
if !ok {
return cid.Undef, nil, fmt.Errorf("unexpected type for image config record: %T", val)
}
return recordCID, configRecord, nil
}