Skip to content

Commit

Permalink
one step further
Browse files Browse the repository at this point in the history
  • Loading branch information
woutslakhorst committed Dec 1, 2023
1 parent b412627 commit 11fbed1
Show file tree
Hide file tree
Showing 8 changed files with 126 additions and 46 deletions.
21 changes: 11 additions & 10 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,9 @@ import (
"context"
"errors"
"fmt"
"github.com/nuts-foundation/nuts-node/discovery"
"github.com/nuts-foundation/nuts-node/vdr/resolver"

"github.com/nuts-foundation/nuts-node/golden_hammer"
goldenHammerCmd "github.com/nuts-foundation/nuts-node/golden_hammer/cmd"
"github.com/nuts-foundation/nuts-node/vdr/didnuts"
"github.com/nuts-foundation/nuts-node/vdr/didnuts/didstore"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"io"
"os"
"runtime/pprof"
Expand All @@ -47,9 +43,12 @@ import (
"github.com/nuts-foundation/nuts-node/didman"
didmanAPI "github.com/nuts-foundation/nuts-node/didman/api/v1"
didmanCmd "github.com/nuts-foundation/nuts-node/didman/cmd"
"github.com/nuts-foundation/nuts-node/discovery"
discoveryCmd "github.com/nuts-foundation/nuts-node/discovery/cmd"
"github.com/nuts-foundation/nuts-node/events"
eventsCmd "github.com/nuts-foundation/nuts-node/events/cmd"
"github.com/nuts-foundation/nuts-node/golden_hammer"
goldenHammerCmd "github.com/nuts-foundation/nuts-node/golden_hammer/cmd"
httpEngine "github.com/nuts-foundation/nuts-node/http"
httpCmd "github.com/nuts-foundation/nuts-node/http/cmd"
"github.com/nuts-foundation/nuts-node/jsonld"
Expand All @@ -65,10 +64,11 @@ import (
vcrCmd "github.com/nuts-foundation/nuts-node/vcr/cmd"
"github.com/nuts-foundation/nuts-node/vdr"
vdrAPI "github.com/nuts-foundation/nuts-node/vdr/api/v1"
vdrAPIv2 "github.com/nuts-foundation/nuts-node/vdr/api/v2"
vdrCmd "github.com/nuts-foundation/nuts-node/vdr/cmd"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/nuts-foundation/nuts-node/vdr/didnuts"
"github.com/nuts-foundation/nuts-node/vdr/didnuts/didstore"
"github.com/nuts-foundation/nuts-node/vdr/resolver"
)

var stdOutWriter io.Writer = os.Stdout
Expand Down Expand Up @@ -209,6 +209,7 @@ func CreateSystem(shutdownCallback context.CancelFunc) *core.System {
Updater: vdrInstance,
Resolver: vdrInstance.Resolver(),
}})
system.RegisterRoutes(&vdrAPIv2.Wrapper{VDR: vdrInstance, Storage: storageInstance, Crypto: cryptoInstance})

Check failure on line 212 in cmd/root.go

View workflow job for this annotation

GitHub Actions / Run govulncheck

unknown field Storage in struct literal of type "github.com/nuts-foundation/nuts-node/vdr/api/v2".Wrapper

Check failure on line 212 in cmd/root.go

View workflow job for this annotation

GitHub Actions / Run govulncheck

unknown field Crypto in struct literal of type "github.com/nuts-foundation/nuts-node/vdr/api/v2".Wrapper
system.RegisterRoutes(&vcrAPI.Wrapper{VCR: credentialInstance, ContextManager: jsonld})
system.RegisterRoutes(&openid4vciAPI.Wrapper{
VCR: credentialInstance,
Expand Down
15 changes: 7 additions & 8 deletions docs/_static/vdr/v2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,12 @@ paths:
* 400 - Returned in case of malformed DID or service
* 404 - Corresponding DID document could not be found
* 500 - An error occurred while processing the request
parameters:
- name: service
in: body
description: Service to be added to the DID document.
required: true
schema:
$ref: '#/components/schemas/Service'
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/Service'
operationId: addService
tags:
- DID
Expand All @@ -111,7 +110,7 @@ paths:
content:
application/json:
schema:
$ref: '#/components/schemas/VerificationMethod'
$ref: '#/components/schemas/Service'
default:
$ref: '../common/error_response.yaml'
/internal/vdr/v2/did/{did}/service/{id}:
Expand Down
16 changes: 13 additions & 3 deletions e2e-tests/oauth-flow/rfc021/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: "3.7"
services:
nodeA-backend:
image: "${IMAGE_NODE_A:-nutsfoundation/nuts-node:master}"
image: "${IMAGE_NODE_A:-nutsfoundation/nuts-node:latest}"
ports:
- "11323:1323"
environment:
Expand All @@ -24,8 +24,8 @@ services:
- "../../tls-certs/nodeA-certificate.pem:/etc/nginx/ssl/key.pem:ro"
- "../../tls-certs/truststore.pem:/etc/nginx/ssl/truststore.pem:ro"
- "./node-A/html:/etc/nginx/html:ro"
nodeB:
image: "${IMAGE_NODE_B:-nutsfoundation/nuts-node:master}"
nodeB-backend:
image: "${IMAGE_NODE_B:-nutsfoundation/nuts-node:latest}"
ports:
- "21323:1323"
environment:
Expand All @@ -38,3 +38,13 @@ services:
- "../../tls-certs/truststore.pem:/etc/ssl/certs/truststore.pem:ro"
healthcheck:
interval: 1s # Make test run quicker by checking health status more often
nodeB:
image: nginx:1.25.1
ports:
- "20443:443"
volumes:
- "./node-B/nginx.conf:/etc/nginx/nginx.conf:ro"
- "../../tls-certs/nodeB-certificate.pem:/etc/nginx/ssl/server.pem:ro"
- "../../tls-certs/nodeB-certificate.pem:/etc/nginx/ssl/key.pem:ro"
- "../../tls-certs/truststore.pem:/etc/nginx/ssl/truststore.pem:ro"
- "./node-B/html:/etc/nginx/html:ro"
1 change: 0 additions & 1 deletion e2e-tests/oauth-flow/rfc021/node-B/nuts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,3 @@ tls:
truststorefile: /opt/nuts/truststore.pem
certfile: /opt/nuts/certificate-and-key.pem
certkeyfile: /opt/nuts/certificate-and-key.pem

4 changes: 2 additions & 2 deletions e2e-tests/oauth-flow/rfc021/run-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ VENDOR_A_DID=$(echo $VENDOR_A_DIDDOC | jq -r .id)
echo Vendor A DID: $VENDOR_A_DID

# Register Vendor B
VENDOR_B_DIDDOC=$(docker compose exec nodeB nuts vdr create-did --v2)
VENDOR_B_DIDDOC=$(docker compose exec nodeB-backend nuts vdr create-did --v2)
VENDOR_B_DID=$(echo $VENDOR_B_DIDDOC | jq -r .id)
echo Vendor B DID: $VENDOR_B_DID

# Issue NutsOrganizationCredential for Vendor B
REQUEST="{\"type\":\"NutsOrganizationCredential\",\"issuer\":\"${VENDOR_B_DID}\", \"credentialSubject\": {\"id\":\"${VENDOR_B_DID}\", \"organization\":{\"name\":\"Caresoft B.V.\", \"city\":\"Caretown\"}},\"visibility\": \"public\"}"
REQUEST="{\"type\":\"NutsOrganizationCredential\",\"issuer\":\"${VENDOR_B_DID}\", \"credentialSubject\": {\"id\":\"${VENDOR_B_DID}\", \"organization\":{\"name\":\"Caresoft B.V.\", \"city\":\"Caretown\"}},\"visibility\": \"private\"}"
RESPONSE=$(echo $REQUEST | curl -X POST --data-binary @- http://localhost:21323/internal/vcr/v2/issuer/vc -H "Content-Type:application/json")
if echo $RESPONSE | grep -q "VerifiableCredential"; then
echo "VC issued"
Expand Down
32 changes: 29 additions & 3 deletions vdr/api/v2/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,15 @@ package v2

import (
"context"
"github.com/labstack/echo/v4"
"github.com/nuts-foundation/go-did/did"
"github.com/nuts-foundation/nuts-node/audit"
"github.com/nuts-foundation/nuts-node/core"
"github.com/nuts-foundation/nuts-node/vdr"
"github.com/nuts-foundation/nuts-node/vdr/didweb"
"github.com/nuts-foundation/nuts-node/vdr/management"
"github.com/nuts-foundation/nuts-node/vdr/resolver"
"net/http"
)

var _ StrictServerInterface = (*Wrapper)(nil)
Expand All @@ -35,9 +40,30 @@ type Wrapper struct {
VDR vdr.VDR
}

func (w Wrapper) ResolveStatusCode(err error) int {
//TODO implement me
panic("implement me")
// ResolveStatusCode maps errors returned by this API to specific HTTP status codes.
func (a *Wrapper) ResolveStatusCode(err error) int {
return core.ResolveStatusCode(err, map[error]int{
resolver.ErrNotFound: http.StatusNotFound,
resolver.ErrDIDNotManagedByThisNode: http.StatusForbidden,
resolver.ErrDuplicateService: http.StatusBadRequest,
did.ErrInvalidDID: http.StatusBadRequest,
})
}

func (a *Wrapper) Routes(router core.EchoRouter) {
RegisterHandlers(router, NewStrictHandler(a, []StrictMiddlewareFunc{
func(f StrictHandlerFunc, operationID string) StrictHandlerFunc {
return func(ctx echo.Context, request interface{}) (response interface{}, err error) {
ctx.Set(core.OperationIDContextKey, operationID)
ctx.Set(core.ModuleNameContextKey, vdr.ModuleName)
ctx.Set(core.StatusCodeResolverContextKey, a)
return f(ctx, request)
}
},
func(f StrictHandlerFunc, operationID string) StrictHandlerFunc {
return audit.StrictMiddleware(f, vdr.ModuleName, operationID)
},
}))
}

func (w Wrapper) CreateDID(ctx context.Context, _ CreateDIDRequestObject) (CreateDIDResponseObject, error) {
Expand Down
80 changes: 64 additions & 16 deletions vdr/api/v2/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions vdr/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,10 @@ type VDR interface {

// Create creates a new DID document according to the given DID method and returns it.
Create(ctx context.Context, method string, options management.DIDCreationOptions) (*did.Document, crypto.Key, error)

// ResolveManaged resolves a DID document that is managed by the local node.
ResolveManaged(id did.DID) (*did.Document, error)

// Resolver returns the resolver for getting the DID document for a DID.
Resolver() resolver.DIDResolver

// ConflictedDocuments returns the DID Document and metadata of all documents with a conflict.
ConflictedDocuments() ([]did.Document, []resolver.DocumentMetadata, error)
}

0 comments on commit 11fbed1

Please sign in to comment.