mirror of
https://tangled.org/evan.jarrett.net/at-container-registry
synced 2026-09-19 08:44:14 +00:00
try and create a crew record for the hold owner
This commit is contained in:
+19
-6
@@ -33,7 +33,7 @@ const (
|
||||
CrewCollection = "io.atcr.hold.crew"
|
||||
)
|
||||
|
||||
// AddCrewMember adds a new crew member to the hold
|
||||
// AddCrewMember adds a new crew member to the hold and commits to carstore
|
||||
func (p *HoldPDS) AddCrewMember(ctx context.Context, memberDID, role string, permissions []string) (cid.Cid, error) {
|
||||
crewRecord := &CrewRecord{
|
||||
Member: memberDID,
|
||||
@@ -42,15 +42,28 @@ func (p *HoldPDS) AddCrewMember(ctx context.Context, memberDID, role string, per
|
||||
AddedAt: time.Now(),
|
||||
}
|
||||
|
||||
// Create record in repo
|
||||
recordCID, rkey, err := p.repo.CreateRecord(ctx, CrewCollection, crewRecord)
|
||||
// Create record in repo (using memberDID as rkey for easy lookup)
|
||||
recordCID, _, err := p.repo.CreateRecord(ctx, CrewCollection, crewRecord)
|
||||
if err != nil {
|
||||
return cid.Undef, fmt.Errorf("failed to create crew record: %w", err)
|
||||
}
|
||||
|
||||
// TODO: Commit the changes
|
||||
// For now, just return the CID
|
||||
_ = rkey // We'll use rkey for GetCrewMember later
|
||||
// Create signer function from signing key
|
||||
signer := func(ctx context.Context, did string, data []byte) ([]byte, error) {
|
||||
return p.signingKey.HashAndSign(data)
|
||||
}
|
||||
|
||||
// Commit the changes to get new root CID
|
||||
root, rev, err := p.repo.Commit(ctx, signer)
|
||||
if err != nil {
|
||||
return cid.Undef, fmt.Errorf("failed to commit crew record: %w", err)
|
||||
}
|
||||
|
||||
// Close the delta session with the new root
|
||||
_, err = p.session.CloseWithRoot(ctx, root, rev)
|
||||
if err != nil {
|
||||
return cid.Undef, fmt.Errorf("failed to persist commit: %w", err)
|
||||
}
|
||||
|
||||
return recordCID, nil
|
||||
}
|
||||
|
||||
@@ -98,6 +98,31 @@ func (p *HoldPDS) SigningKey() *crypto.PrivateKeyK256 {
|
||||
return p.signingKey
|
||||
}
|
||||
|
||||
// Bootstrap initializes the hold with the owner as the first crew member
|
||||
func (p *HoldPDS) Bootstrap(ctx context.Context, ownerDID string) error {
|
||||
if ownerDID == "" {
|
||||
// No owner specified, skip bootstrap
|
||||
return nil
|
||||
}
|
||||
|
||||
// Check if repo already has commits
|
||||
_, err := p.carstore.GetUserRepoHead(ctx, p.uid)
|
||||
if err == nil {
|
||||
// Repo already has commits, skip bootstrap
|
||||
return nil
|
||||
}
|
||||
|
||||
// Add hold owner as first crew member with admin role
|
||||
fmt.Printf("🚀 Bootstrapping hold PDS with owner: %s\n", ownerDID)
|
||||
_, err = p.AddCrewMember(ctx, ownerDID, "admin", []string{"blob:read", "blob:write", "crew:admin"})
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to add owner as crew member: %w", err)
|
||||
}
|
||||
|
||||
fmt.Printf("✅ Added %s as hold admin\n", ownerDID)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Close closes the session and carstore
|
||||
func (p *HoldPDS) Close() error {
|
||||
// TODO: Close session properly
|
||||
|
||||
Reference in New Issue
Block a user