Skip to content

Commit

Permalink
Discovery: DID registration by clients
Browse files Browse the repository at this point in the history
  • Loading branch information
reinkrul committed Jan 3, 2024
1 parent ccf5590 commit 4655327
Show file tree
Hide file tree
Showing 11 changed files with 924 additions and 3 deletions.
5 changes: 2 additions & 3 deletions auth/api/iam/generated.go

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

40 changes: 40 additions & 0 deletions discovery/api/v1/client/http.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package client

import (
"bytes"
"context"
"fmt"
"github.com/nuts-foundation/go-did/vc"
"github.com/nuts-foundation/nuts-node/core"
"net/http"
)

// Invoker is the interface for the client that invokes the remote Discovery Service.
type Invoker interface {
// Register registers a Verifiable Presentation on the remote Discovery Service.
Register(ctx context.Context, serviceEndpointURL string, presentation vc.VerifiablePresentation) error
}

var _ Invoker = &HTTPInvoker{}

// HTTPInvoker is a
type HTTPInvoker struct {
client core.HTTPRequestDoer
}

func (h HTTPInvoker) Register(ctx context.Context, serviceEndpointURL string, presentation vc.VerifiablePresentation) error {
requestBody, _ := presentation.MarshalJSON()
httpRequest, err := http.NewRequestWithContext(ctx, http.MethodPost, serviceEndpointURL, bytes.NewReader(requestBody))
if err != nil {
return err
}
httpResponse, err := h.client.Do(httpRequest)
if err != nil {
return fmt.Errorf("failed to invoke remote Discovery Service (url=%s): %w", serviceEndpointURL, err)
}
defer httpResponse.Body.Close()
if err := core.TestResponseCode(201, httpResponse); err != nil {
return fmt.Errorf("non-OK response from remote Discovery Service (url=%s): %w", serviceEndpointURL, err)
}
return nil
}
Loading

0 comments on commit 4655327

Please sign in to comment.