forked from hyperledger-archives/aries-framework-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request hyperledger-archives#88 from rolsonquadras/issue-78
feat: Framework Init - base template with Outbound transport config
- Loading branch information
Showing
10 changed files
with
311 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/transport" | ||
) | ||
|
||
// TransportProviderFactory allows overriding of aries protocol providers | ||
type TransportProviderFactory interface { | ||
CreateOutboundTransport() transport.OutboundTransport | ||
} |
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/transport" | ||
) | ||
|
||
// defFramework provides default framework configs | ||
type defFramework struct{} | ||
|
||
// transportProviderFactory provides default Outbound Transport provider factory | ||
func (d defFramework) transportProviderFactory() api.TransportProviderFactory { | ||
return transport.NewProviderFactory() | ||
} | ||
|
||
// defFrameworkOpts provides default framework options | ||
func defFrameworkOpts() []Option { | ||
// get the default framework configs | ||
def := defFramework{} | ||
|
||
var opts []Option | ||
// protocol provider factory | ||
opt := WithTransportProviderFactory(def.transportProviderFactory()) | ||
opts = append(opts, opt) | ||
|
||
return opts | ||
} |
27 changes: 27 additions & 0 deletions
27
pkg/framework/aries/factory/transport/transport_factory.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,27 @@ | ||
/* | ||
Copyright SecureKey Technologies Inc. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package transport | ||
|
||
import ( | ||
"github.com/hyperledger/aries-framework-go/pkg/didcomm/transport" | ||
) | ||
|
||
// ProviderFactory represents the default transport provider factory. | ||
type ProviderFactory struct { | ||
} | ||
|
||
// NewProviderFactory returns the default transport provider factory. | ||
func NewProviderFactory() *ProviderFactory { | ||
f := ProviderFactory{} | ||
return &f | ||
} | ||
|
||
// CreateOutboundTransport returns a new default implementation of outbound transport provider | ||
func (f *ProviderFactory) CreateOutboundTransport() transport.OutboundTransport { | ||
// TODO - https://github.com/hyperledger/aries-framework-go/issues/83 | ||
return nil | ||
} |
18 changes: 18 additions & 0 deletions
18
pkg/framework/aries/factory/transport/transport_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 transport | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestNewProviderFactory(t *testing.T) { | ||
f := NewProviderFactory() | ||
require.Empty(t, f.CreateOutboundTransport()) | ||
} |
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 { | ||
transport api.TransportProviderFactory | ||
} | ||
|
||
// 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 | ||
} | ||
|
||
// WithTransportProviderFactory injects a protocol provider factory interface to Aries | ||
func WithTransportProviderFactory(ot api.TransportProviderFactory) Option { | ||
return func(opts *Aries) error { | ||
opts.transport = ot | ||
return nil | ||
} | ||
} | ||
|
||
// Context provides handle to framework context | ||
func (a *Aries) Context() (*context.Provider, error) { | ||
return context.New(context.WithOutboundTransport(a.transport.CreateOutboundTransport())) | ||
} |
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 ( | ||
"testing" | ||
|
||
"github.com/hyperledger/aries-framework-go/pkg/didcomm/transport" | ||
|
||
"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(WithTransportProviderFactory(&mockTransportProviderFactory{})) | ||
require.NoError(t, err) | ||
|
||
// context | ||
ctx, err := aries.Context() | ||
require.NoError(t, err) | ||
|
||
// exchange client | ||
exClient := exchange.New(ctx) | ||
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 mockTransportProviderFactory struct { | ||
} | ||
|
||
func (f *mockTransportProviderFactory) CreateOutboundTransport() transport.OutboundTransport { | ||
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/transport" | ||
errors "golang.org/x/xerrors" | ||
) | ||
|
||
// Provider supplies the framework configuration to client objects. | ||
type Provider struct { | ||
outboundTransport transport.OutboundTransport | ||
} | ||
|
||
// 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 | ||
} | ||
|
||
// OutboundTransport returns the outbound transport provider | ||
func (p *Provider) OutboundTransport() transport.OutboundTransport { | ||
return p.outboundTransport | ||
} | ||
|
||
// ProviderOption configures the framework. | ||
type ProviderOption func(opts *Provider) error | ||
|
||
// WithOutboundTransport injects transport provider into the framework | ||
func WithOutboundTransport(ot transport.OutboundTransport) ProviderOption { | ||
return func(opts *Provider) error { | ||
opts.outboundTransport = ot | ||
return nil | ||
} | ||
} |
Oops, something went wrong.