Skip to content

Commit 7eaea71

Browse files
authored
VDR: Added happy flow logging for subject manager (#3339)
1 parent 951361f commit 7eaea71

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

vdr/didsubject/manager.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import (
3434
"github.com/nuts-foundation/nuts-node/storage/orm"
3535
"github.com/nuts-foundation/nuts-node/vdr/log"
3636
"gorm.io/gorm"
37+
"strings"
3738
"time"
3839
)
3940

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

161162
docs := make([]did.Document, 0)
163+
var dids []string
162164
for _, sqlDoc := range sqlDocs {
163165
doc, err := sqlDoc.ToDIDDocument()
164166
if err != nil {
165167
return nil, subject, err
166168
}
167169
docs = append(docs, doc)
170+
dids = append(dids, sqlDoc.DID.ID)
168171
}
172+
log.Logger().
173+
WithField(core.LogFieldDIDSubject, subject).
174+
Infof("Created new subject (DIDs: [%s])", strings.Join(dids, ", "))
169175
return docs, subject, nil
170176
}
171177

@@ -241,7 +247,9 @@ func (r *Manager) CreateService(ctx context.Context, subject string, service did
241247
if err != nil {
242248
return nil, fmt.Errorf("could not add service to DID Documents: %w", err)
243249
}
244-
250+
log.Logger().
251+
WithField(core.LogFieldDIDSubject, subject).
252+
Infof("Created new service for subject (type: %s, id: %s)", service.Type, service.ID)
245253
return services, nil
246254
}
247255

@@ -297,6 +305,9 @@ func (r *Manager) DeleteService(ctx context.Context, subject string, serviceID s
297305
if err != nil {
298306
return fmt.Errorf("could not delete service from DID Documents: %w", err)
299307
}
308+
log.Logger().
309+
WithField(core.LogFieldDIDSubject, subject).
310+
Infof("Deleted service for subject (id: %s)", serviceID.String())
300311
return nil
301312
}
302313

@@ -334,14 +345,17 @@ func (r *Manager) UpdateService(ctx context.Context, subject string, serviceID s
334345
if err != nil {
335346
return nil, fmt.Errorf("could not update service for DID Documents: %w", err)
336347
}
348+
log.Logger().
349+
WithField(core.LogFieldDIDSubject, subject).
350+
Infof("Updated service for subject (id: %s)", serviceID.String())
337351
return services, nil
338352
}
339353

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

343357
verificationMethods := make([]did.VerificationMethod, 0)
344-
358+
var vmIDs []string
345359
err := r.applyToDIDDocuments(ctx, subject, func(tx *gorm.DB, id did.DID, current *orm.DIDDocument) (*orm.DIDDocument, error) {
346360
// known limitation
347361
if keyUsage.Is(orm.KeyAgreementUsage) && id.Method == "web" {
@@ -365,12 +379,16 @@ func (r *Manager) AddVerificationMethod(ctx context.Context, subject string, key
365379
Data: data,
366380
}
367381
current.VerificationMethods = append(current.VerificationMethods, sqlMethod)
382+
vmIDs = append(vmIDs, vm.ID.String())
368383
return current, nil
369384
})
370385

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

0 commit comments

Comments
 (0)