Skip to content

Commit

Permalink
stop refreshing when a subject has no active DID Documents (#3461)
Browse files Browse the repository at this point in the history
  • Loading branch information
woutslakhorst authored Oct 8, 2024
1 parent b5c5c2d commit d2df24f
Show file tree
Hide file tree
Showing 5 changed files with 208 additions and 222 deletions.
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ func CreateSystem(shutdownCallback context.CancelFunc) *core.System {
vdrInstance := vdr.NewVDR(cryptoInstance, networkInstance, didStore, eventManager, storageInstance)
credentialInstance := vcr.NewVCRInstance(cryptoInstance, vdrInstance, networkInstance, jsonld, eventManager, storageInstance, pkiInstance)
didmanInstance := didman.NewDidmanInstance(vdrInstance, credentialInstance, jsonld)
discoveryInstance := discovery.New(storageInstance, credentialInstance, vdrInstance)
discoveryInstance := discovery.New(storageInstance, credentialInstance, vdrInstance, vdrInstance)
authInstance := auth.NewAuthInstance(auth.DefaultConfig(), vdrInstance, vdrInstance, credentialInstance, cryptoInstance, didmanInstance, jsonld, pkiInstance)
statusEngine := status.NewStatusEngine(system)
metricsEngine := core.NewMetricsEngine()
Expand Down
24 changes: 22 additions & 2 deletions discovery/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"github.com/nuts-foundation/nuts-node/vcr/pe"
"github.com/nuts-foundation/nuts-node/vcr/signature/proof"
"github.com/nuts-foundation/nuts-node/vdr/didsubject"
"github.com/nuts-foundation/nuts-node/vdr/resolver"
"slices"
"strings"
"time"
Expand All @@ -56,15 +57,17 @@ type defaultClientRegistrationManager struct {
client client.HTTPClient
vcr vcr.VCR
subjectManager didsubject.Manager
didResolver resolver.DIDResolver
}

func newRegistrationManager(services map[string]ServiceDefinition, store *sqlStore, client client.HTTPClient, vcr vcr.VCR, subjectManager didsubject.Manager) *defaultClientRegistrationManager {
func newRegistrationManager(services map[string]ServiceDefinition, store *sqlStore, client client.HTTPClient, vcr vcr.VCR, subjectManager didsubject.Manager, didResolver resolver.DIDResolver) *defaultClientRegistrationManager {
return &defaultClientRegistrationManager{
services: services,
store: store,
client: client,
vcr: vcr,
subjectManager: subjectManager,
didResolver: didResolver,
}
}

Expand All @@ -87,9 +90,26 @@ func (r *defaultClientRegistrationManager) activate(ctx context.Context, service
}
}
subjectDIDs = subjectDIDs[:j]

if len(subjectDIDs) == 0 {
return fmt.Errorf("%w: %w for %s", ErrPresentationRegistrationFailed, ErrDIDMethodsNotSupported, subjectID)
}
}

// and filter by deactivated status
j := 0
for i, did := range subjectDIDs {
_, _, err := r.didResolver.Resolve(did, nil)
// any temporary error, like db errors should not cause a deregister action, only ErrDeactivated
if err == nil || !errors.Is(err, resolver.ErrDeactivated) {
subjectDIDs[j] = subjectDIDs[i]
j++
}
}
subjectDIDs = subjectDIDs[:j]

if len(subjectDIDs) == 0 {
return fmt.Errorf("%w: %w for %s", ErrPresentationRegistrationFailed, ErrDIDMethodsNotSupported, subjectID)
return fmt.Errorf("%w: %w for %s", ErrPresentationRegistrationFailed, didsubject.ErrSubjectNotFound, subjectID)
}

log.Logger().Debugf("Registering Verifiable Presentation on Discovery Service (service=%s, subject=%s)", service.ID, subjectID)
Expand Down
Loading

0 comments on commit d2df24f

Please sign in to comment.