Skip to content

Commit

Permalink
feat: Store VC and retrieve VC using edge client
Browse files Browse the repository at this point in the history
closes: #9

Signed-off-by: talwinder.kaur <talwinder.kaur@securekey.com>
  • Loading branch information
talwinder50 committed Jan 25, 2020
1 parent def1f9f commit 6f448a8
Show file tree
Hide file tree
Showing 12 changed files with 463 additions and 84 deletions.
3 changes: 2 additions & 1 deletion cmd/vc-rest/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ require (
github.com/sirupsen/logrus v1.4.2
github.com/spf13/cobra v0.0.5
github.com/stretchr/testify v1.4.0
github.com/trustbloc/edge-core v0.0.0-20200117135316-f80bd93997ef
github.com/trustbloc/edge-core v0.0.0-20200117175518-7997acf8ed7a
github.com/trustbloc/edge-service v0.0.0
github.com/trustbloc/edv v0.0.0-20200117213234-9e415c572513
)

go 1.13
8 changes: 4 additions & 4 deletions cmd/vc-rest/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/hyperledger/aries-framework-go v0.1.1-0.20200113160002-41ea60bef355 h1:NUrliVMvnPd35H8T9xVDZCMXMy0vpBNInUL2Dy2pnho=
github.com/hyperledger/aries-framework-go v0.1.1-0.20200113160002-41ea60bef355/go.mod h1:1wIgYlQulTD2fQSrslEalfuQADm1VB0UBDTPZJvQeFg=
github.com/hyperledger/aries-framework-go v0.1.1-0.20200121182508-01fa9ee94644 h1:BRYsh0ubFrsDYRdjQrl/i6baBy/jGEzGfUA70GT9bFc=
github.com/hyperledger/aries-framework-go v0.1.1-0.20200121182508-01fa9ee94644/go.mod h1:EWYMDfPqWVI/XxSvvCQJHJYEwYRWChhN7ItoM1SGinI=
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
Expand Down Expand Up @@ -108,8 +106,10 @@ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ=
github.com/trustbloc/edge-core v0.0.0-20200117135316-f80bd93997ef h1:DxV490TVnFaHeHpNKeRfS2X7MLWJVc8D+94FAGkbl8M=
github.com/trustbloc/edge-core v0.0.0-20200117135316-f80bd93997ef/go.mod h1:aEkFOyP99eRGPLwCN/4XKFe4ZAPmtroMkf49SRirXkU=
github.com/trustbloc/edge-core v0.0.0-20200117175518-7997acf8ed7a h1:461cXE3gwaUQpVtUX0xZpNLMHHQDOJmiDd3PAps/U08=
github.com/trustbloc/edge-core v0.0.0-20200117175518-7997acf8ed7a/go.mod h1:aEkFOyP99eRGPLwCN/4XKFe4ZAPmtroMkf49SRirXkU=
github.com/trustbloc/edv v0.0.0-20200117213234-9e415c572513 h1:Oekjpu5Sy7F80w5q8oI6nJPvTGDg0/KwcvQe6KGhsB4=
github.com/trustbloc/edv v0.0.0-20200117213234-9e415c572513/go.mod h1:NLcjKKzcNi096J1ikORIGODxhj/r4HMiaDswXtJdUN4=
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f h1:J9EGpcZtP0E/raorCMxlFGSTBrsSlaDGf3jU/qvAE2c=
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU=
Expand Down
17 changes: 15 additions & 2 deletions cmd/vc-rest/startcmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"errors"
"net/http"

"github.com/trustbloc/edv/pkg/client/edv"

"github.com/gorilla/mux"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
Expand All @@ -22,15 +24,20 @@ import (
const (
hostURLFlagName = "host-url"
hostURLFlagShorthand = "u"
hostURLFlagUsage = "URL to run the vc-rest instance on. Format: HostName:Port."
hostURLFlagUsage = "URL vc-rest instance is running on. Format: HostName:Port."
hostURLEnvKey = "VC_REST_HOST_URL"
edvURLFlagName = "edv-url"
edvURLFlagShorthand = "e"
edvURLFlagUsage = "URL EDV instance is running on. Format: HostName:Port."
edvURLEnvKey = "EDV_REST_HOST_URL"
)

var errMissingHostURL = errors.New("host URL not provided")

type vcRestParameters struct {
srv server
hostURL string
edvURL string
}

type server interface {
Expand Down Expand Up @@ -64,9 +71,14 @@ func createStartCmd(srv server) *cobra.Command {
if err != nil {
return err
}
edvURL, err := cmdutils.GetUserSetVar(cmd, edvURLFlagName, edvURLEnvKey)
if err != nil {
return err
}
parameters := &vcRestParameters{
srv: srv,
hostURL: hostURL,
edvURL: edvURL,
}
return startEdgeService(parameters)
},
Expand All @@ -75,14 +87,15 @@ func createStartCmd(srv server) *cobra.Command {

func createFlags(startCmd *cobra.Command) {
startCmd.Flags().StringP(hostURLFlagName, hostURLFlagShorthand, "", hostURLFlagUsage)
startCmd.Flags().StringP(edvURLFlagName, edvURLFlagShorthand, "", edvURLFlagUsage)
}

func startEdgeService(parameters *vcRestParameters) error {
if parameters.hostURL == "" {
return errMissingHostURL
}

vcService, err := operation.New(memstore.NewProvider())
vcService, err := operation.New(memstore.NewProvider(), edv.New(parameters.edvURL))
if err != nil {
return err
}
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ require (
github.com/sirupsen/logrus v1.4.2
github.com/spf13/cobra v0.0.5
github.com/stretchr/testify v1.4.0
github.com/trustbloc/edge-core v0.0.0-20200117135316-f80bd93997ef
github.com/trustbloc/edge-core v0.0.0-20200117175518-7997acf8ed7a
github.com/trustbloc/edv v0.0.0-20200117213234-9e415c572513
)
8 changes: 6 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSR
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/VictoriaMetrics/fastcache v1.5.5 h1:HsBlzPgzKG0566YOl1mmfyz8SCU0zLKfbl9RDLsiLD8=
github.com/VictoriaMetrics/fastcache v1.5.5/go.mod h1:ptDBkNMQI4RtmVo8VS/XwRY6RoTu1dAWCbrk+6WsEM8=
github.com/agl/ed25519 v0.0.0-20170116200512-5312a6153412 h1:w1UutsfOrms1J05zt7ISrnJIXKzwaspym5BTKGx93EI=
github.com/agl/ed25519 v0.0.0-20170116200512-5312a6153412/go.mod h1:WPjqKcmVOxf0XSf3YxCJs6N6AOSrOx3obionmG7T0y0=
github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156 h1:eMwmnE/GDgah4HI848JfFxHt+iPb26b4zyfspmqY0/8=
github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156/go.mod h1:Cb/ax3seSYIx7SuZdm2G2xzfwmv3TPSk2ucNfQESPXM=
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
github.com/aws/aws-sdk-go v1.25.39/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo=
github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d h1:yJzD/yFppdVCf6ApMkVy8cUxV0XrxdP9rVf6D87/Mng=
github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg=
github.com/cespare/xxhash/v2 v2.1.1 h1:6MnRN8NT7+YBpUIWxHtefFZOKTAPgGjpQSxqLNn0+qY=
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
Expand Down Expand Up @@ -106,8 +108,10 @@ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ=
github.com/trustbloc/edge-core v0.0.0-20200117135316-f80bd93997ef h1:DxV490TVnFaHeHpNKeRfS2X7MLWJVc8D+94FAGkbl8M=
github.com/trustbloc/edge-core v0.0.0-20200117135316-f80bd93997ef/go.mod h1:aEkFOyP99eRGPLwCN/4XKFe4ZAPmtroMkf49SRirXkU=
github.com/trustbloc/edge-core v0.0.0-20200117175518-7997acf8ed7a h1:461cXE3gwaUQpVtUX0xZpNLMHHQDOJmiDd3PAps/U08=
github.com/trustbloc/edge-core v0.0.0-20200117175518-7997acf8ed7a/go.mod h1:aEkFOyP99eRGPLwCN/4XKFe4ZAPmtroMkf49SRirXkU=
github.com/trustbloc/edv v0.0.0-20200117213234-9e415c572513 h1:Oekjpu5Sy7F80w5q8oI6nJPvTGDg0/KwcvQe6KGhsB4=
github.com/trustbloc/edv v0.0.0-20200117213234-9e415c572513/go.mod h1:NLcjKKzcNi096J1ikORIGODxhj/r4HMiaDswXtJdUN4=
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f h1:J9EGpcZtP0E/raorCMxlFGSTBrsSlaDGf3jU/qvAE2c=
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU=
Expand Down
35 changes: 35 additions & 0 deletions pkg/internal/mock/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
Copyright SecureKey Technologies Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/

package mock

import (
"github.com/trustbloc/edv/pkg/restapi/edv/operation"
)

// Client is the mock edv client
type Client struct {
edvServerURL string
}

// NewMockEDVClient is the mock version of edv client
func NewMockEDVClient(edvServerURL string) *Client {
return &Client{edvServerURL: edvServerURL}
}

// CreateDataVault creates a new data vault.
func (c *Client) CreateDataVault(config *operation.DataVaultConfiguration) (string, error) {
return "", nil
}

// CreateDocument stores the specified document.
func (c *Client) CreateDocument(vaultID string, document *operation.StructuredDocument) (string, error) {
return "", nil
}

// RetrieveDocument retrieves the specified document.
func (c *Client) RetrieveDocument(vaultID, docID string) ([]byte, error) {
return nil, nil
}
4 changes: 2 additions & 2 deletions pkg/restapi/vc/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ import (
)

// New returns new controller instance.
func New(provider storage.Provider) (*Controller, error) {
func New(provider storage.Provider, client operation.Client) (*Controller, error) {
var allHandlers []operation.Handler

vcService, err := operation.New(provider)
vcService, err := operation.New(provider, client)
if err != nil {
return nil, err
}
Expand Down
11 changes: 7 additions & 4 deletions pkg/restapi/vc/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,27 @@ import (
"testing"

"github.com/stretchr/testify/require"

"github.com/trustbloc/edge-core/pkg/storage/memstore"

"github.com/trustbloc/edge-service/pkg/internal/mock"
)

func TestController_New(t *testing.T) {
controller, err := New(memstore.NewProvider())
client := mock.NewMockEDVClient("test")
controller, err := New(memstore.NewProvider(), client)
require.NoError(t, err)
require.NotNil(t, controller)
}

func TestController_GetOperations(t *testing.T) {
controller, err := New(memstore.NewProvider())
client := mock.NewMockEDVClient("test")
controller, err := New(memstore.NewProvider(), client)
require.NoError(t, err)
require.NotNil(t, controller)

ops := controller.GetOperations()

require.Equal(t, 4, len(ops))
require.Equal(t, 6, len(ops))

require.Equal(t, "/credential", ops[0].Path())
require.Equal(t, http.MethodPost, ops[0].Method())
Expand Down
10 changes: 8 additions & 2 deletions pkg/restapi/vc/operation/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,20 @@ import (
"github.com/hyperledger/aries-framework-go/pkg/doc/verifiable"
)

// CreateCredential input data for edge service issuer rest api
type CreateCredential struct {
// CreateCrendentialRequest input data for edge service issuer rest api
type CreateCrendentialRequest struct {
Subject verifiable.Subject `json:"credentialSubject"`
Issuer verifiable.Issuer `json:"issuer"`
Type []string `json:"type,omitempty"`
Profile string `json:"profile,omitempty"`
}

// CreateCrendentialResponse returns the credential with an ID
type CreateCrendentialResponse struct {
ID string `json:"id"`
CreateCrendentialRequest
}

// ProfileRequest struct the input for creating profile
type ProfileRequest struct {
Name string `json:"name"`
Expand Down
Loading

0 comments on commit 6f448a8

Please sign in to comment.