Skip to content

Commit

Permalink
VDR: Added happy flow logging for subject manager
Browse files Browse the repository at this point in the history
  • Loading branch information
reinkrul committed Sep 3, 2024
1 parent 931dacb commit 922ea09
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions vdr/didsubject/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"github.com/nuts-foundation/nuts-node/storage/orm"
"github.com/nuts-foundation/nuts-node/vdr/log"
"gorm.io/gorm"
"strings"
"time"
)

Expand Down Expand Up @@ -159,13 +160,18 @@ func (r *Manager) Create(ctx context.Context, options CreationOptions) ([]did.Do
}

docs := make([]did.Document, 0)
var dids []string
for _, sqlDoc := range sqlDocs {
doc, err := sqlDoc.ToDIDDocument()
if err != nil {
return nil, subject, err
}
docs = append(docs, doc)
dids = append(dids, sqlDoc.DID.ID)
}
log.Logger().
WithField(core.LogFieldDIDSubject, subject).
Infof("Created new subject (DIDs: [%s])", strings.Join(dids, ", "))
return docs, subject, nil
}

Expand Down Expand Up @@ -242,7 +248,9 @@ func (r *Manager) CreateService(ctx context.Context, subject string, service did
if err != nil {
return nil, fmt.Errorf("could not add service to DID Documents: %w", err)
}

log.Logger().
WithField(core.LogFieldDIDSubject, subject).
Infof("Created new service for subject (type: %s, id: %s)", service.Type, service.ID)
return services, nil
}

Expand Down Expand Up @@ -298,6 +306,9 @@ func (r *Manager) DeleteService(ctx context.Context, subject string, serviceID s
if err != nil {
return fmt.Errorf("could not delete service from DID Documents: %w", err)
}
log.Logger().
WithField(core.LogFieldDIDSubject, subject).
Infof("Deleted service for subject (id: %s)", serviceID.String())
return nil
}

Expand Down Expand Up @@ -336,14 +347,17 @@ func (r *Manager) UpdateService(ctx context.Context, subject string, serviceID s
if err != nil {
return nil, fmt.Errorf("could not update service for DID Documents: %w", err)
}
log.Logger().
WithField(core.LogFieldDIDSubject, subject).
Infof("Updated service for subject (id: %s)", serviceID.String())
return services, nil
}

func (r *Manager) AddVerificationMethod(ctx context.Context, subject string, keyUsage orm.DIDKeyFlags) ([]did.VerificationMethod, error) {
log.Logger().Debug("Creating new VerificationMethods.")

verificationMethods := make([]did.VerificationMethod, 0)

var vmIDs []string
err := r.applyToDIDDocuments(ctx, subject, func(tx *gorm.DB, id did.DID, current *orm.DIDDocument) (*orm.DIDDocument, error) {
// known limitation
if keyUsage.Is(orm.KeyAgreementUsage) && id.Method == "web" {
Expand All @@ -367,12 +381,16 @@ func (r *Manager) AddVerificationMethod(ctx context.Context, subject string, key
Data: data,
}
current.VerificationMethods = append(current.VerificationMethods, sqlMethod)
vmIDs = append(vmIDs, vm.ID.String())
return current, nil
})

if err != nil {
return nil, fmt.Errorf("could not update DID documents: %w", err)
}
log.Logger().
WithField(core.LogFieldDIDSubject, subject).
Infof("Added verification method for subject (IDs: [%s])", strings.Join(vmIDs, ", "))
return verificationMethods, nil
}

Expand Down

0 comments on commit 922ea09

Please sign in to comment.