This repository has been archived by the owner on Mar 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Framework Init - base template with Outbound transport config
- Add New(opts) function which takes in the options to configuration - Support outbound transport configuration Signed-off-by: Rolson Quadras <[email protected]>
- Loading branch information
1 parent
b74857f
commit f4a9ffc
Showing
10 changed files
with
298 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
Copyright SecureKey Technologies Inc. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package api | ||
|
||
import ( | ||
"github.com/hyperledger/aries-framework-go/pkg/didcomm/protocol/exchange" | ||
) | ||
|
||
// ProtocolProviderFactory allows overriding of aries protocol providers | ||
type ProtocolProviderFactory interface { | ||
CreateExchangeProvider() exchange.Provider | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
Copyright SecureKey Technologies Inc. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package aries | ||
|
||
import ( | ||
"github.com/hyperledger/aries-framework-go/pkg/framework/aries/api" | ||
"github.com/hyperledger/aries-framework-go/pkg/framework/aries/factory/protocol" | ||
) | ||
|
||
// defFramework provides default framework configs | ||
type defFramework struct{} | ||
|
||
// outboundTransport provides default OutboundTransport | ||
func (d defFramework) protocolProviderFactory() api.ProtocolProviderFactory { | ||
return protocol.NewProviderFactory() | ||
} | ||
|
||
// defFrameworkOpts provides default framework options | ||
func defFrameworkOpts() []Option { | ||
// get the default framework configs | ||
def := defFramework{} | ||
|
||
var opts []Option | ||
// protocol provider factory | ||
opt := WithProtocolProviderFactory(def.protocolProviderFactory()) | ||
opts = append(opts, opt) | ||
|
||
return opts | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
Copyright SecureKey Technologies Inc. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package protocol | ||
|
||
import ( | ||
"github.com/hyperledger/aries-framework-go/pkg/didcomm/protocol/exchange" | ||
) | ||
|
||
// ProviderFactory represents the default protocol provider factory. | ||
type ProviderFactory struct { | ||
} | ||
|
||
// NewProviderFactory returns the default protocol provider factory. | ||
func NewProviderFactory() *ProviderFactory { | ||
f := ProviderFactory{} | ||
return &f | ||
} | ||
|
||
// CreateExchangeProvider returns a new default implementation of Exchange provider | ||
func (f *ProviderFactory) CreateExchangeProvider() exchange.Provider { | ||
// TODO - https://github.com/hyperledger/aries-framework-go/issues/83 | ||
return nil | ||
} |
18 changes: 18 additions & 0 deletions
18
pkg/framework/aries/factory/protocol/protocol_factory_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
Copyright SecureKey Technologies Inc. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package protocol | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestNewProviderFactory(t *testing.T) { | ||
f := NewProviderFactory() | ||
require.Empty(t, f.CreateExchangeProvider()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
Copyright SecureKey Technologies Inc. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package aries | ||
|
||
import ( | ||
"github.com/hyperledger/aries-framework-go/pkg/framework/aries/api" | ||
"github.com/hyperledger/aries-framework-go/pkg/framework/context" | ||
errors "golang.org/x/xerrors" | ||
) | ||
|
||
// Aries provides access to clients being managed by the framework. | ||
type Aries struct { | ||
protocol api.ProtocolProviderFactory | ||
} | ||
|
||
// Option configures the framework. | ||
type Option func(opts *Aries) error | ||
|
||
// New initializes the Aries framework based on the set of options provided. | ||
func New(opts ...Option) (*Aries, error) { | ||
// get the default framework options | ||
defOpts := defFrameworkOpts() | ||
|
||
frameworkOpts := &Aries{} | ||
|
||
// generate framework configs from options | ||
for _, option := range append(defOpts, opts...) { | ||
err := option(frameworkOpts) | ||
if err != nil { | ||
return nil, errors.Errorf("Error in option passed to New: %w", err) | ||
} | ||
} | ||
|
||
return frameworkOpts, nil | ||
} | ||
|
||
// WithProtocolProviderFactory injects a protocol provider factory interface to Aries | ||
func WithProtocolProviderFactory(ot api.ProtocolProviderFactory) Option { | ||
return func(opts *Aries) error { | ||
opts.protocol = ot | ||
return nil | ||
} | ||
} | ||
|
||
// Context provides handle to framework context | ||
func (a *Aries) Context() (*context.Provider, error) { | ||
return context.New(context.WithExchangeProvider(a.protocol.CreateExchangeProvider())) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
Copyright SecureKey Technologies Inc. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package aries | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hyperledger/aries-framework-go/pkg/didcomm/protocol/exchange" | ||
mocktransport "github.com/hyperledger/aries-framework-go/pkg/internal/didcomm/transport/mock" | ||
"github.com/stretchr/testify/require" | ||
errors "golang.org/x/xerrors" | ||
) | ||
|
||
func TestFramework(t *testing.T) { | ||
// framework new - error | ||
_, err := New(func(opts *Aries) error { | ||
return errors.New("error creating the framework option") | ||
}) | ||
require.Error(t, err) | ||
|
||
// framework new - success | ||
aries, err := New(WithProtocolProviderFactory(&mockProtocolProviderFactory{})) | ||
require.NoError(t, err) | ||
|
||
// context | ||
ctx, err := aries.Context() | ||
require.NoError(t, err) | ||
|
||
// exchange client | ||
exClient := exchange.New(ctx.ExchangeProvider()) | ||
require.NoError(t, err) | ||
|
||
req := &exchange.Request{ | ||
ID: "5678876542345", | ||
Label: "Bob", | ||
} | ||
require.NoError(t, exClient.SendExchangeRequest(req, "http://example/didexchange")) | ||
require.Error(t, exClient.SendExchangeRequest(req, "")) | ||
} | ||
|
||
type mockProtocolProviderFactory struct { | ||
} | ||
|
||
func (f *mockProtocolProviderFactory) CreateExchangeProvider() exchange.Provider { | ||
return mocktransport.NewOutboundTransport("success") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
Copyright SecureKey Technologies Inc. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package context | ||
|
||
import ( | ||
"github.com/hyperledger/aries-framework-go/pkg/didcomm/protocol/exchange" | ||
errors "golang.org/x/xerrors" | ||
) | ||
|
||
// Provider supplies the framework configuration to client objects. | ||
type Provider struct { | ||
exProv exchange.Provider | ||
} | ||
|
||
// New instantiated new context provider | ||
func New(opts ...ProviderOption) (*Provider, error) { | ||
ctxProvider := Provider{} | ||
for _, opt := range opts { | ||
err := opt(&ctxProvider) | ||
if err != nil { | ||
return nil, errors.Errorf("Error in option passed to New: %w", err) | ||
} | ||
} | ||
return &ctxProvider, nil | ||
} | ||
|
||
// ExchangeProvider returns exchange protocol provider | ||
func (p *Provider) ExchangeProvider() exchange.Provider { | ||
return p.exProv | ||
} | ||
|
||
// ProviderOption configures the framework. | ||
type ProviderOption func(opts *Provider) error | ||
|
||
// WithExchangeProvider injects exchange provider into the framework | ||
func WithExchangeProvider(ot exchange.Provider) ProviderOption { | ||
return func(opts *Provider) error { | ||
opts.exProv = ot | ||
return nil | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
Copyright SecureKey Technologies Inc. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package context | ||
|
||
import ( | ||
"testing" | ||
|
||
mocktransport "github.com/hyperledger/aries-framework-go/pkg/internal/didcomm/transport/mock" | ||
"github.com/stretchr/testify/require" | ||
errors "golang.org/x/xerrors" | ||
) | ||
|
||
func TestNewProvider(t *testing.T) { | ||
prov, err := New() | ||
require.NoError(t, err) | ||
require.Empty(t, prov.ExchangeProvider()) | ||
|
||
prov, err = New(WithExchangeProvider(mocktransport.NewOutboundTransport("success"))) | ||
require.NoError(t, err) | ||
require.NotEmpty(t, prov.ExchangeProvider()) | ||
|
||
_, err = New(func(opts *Provider) error { | ||
return errors.New("error creating the framework option") | ||
}) | ||
require.Error(t, err) | ||
} |