Skip to content
This repository has been archived by the owner on Mar 27, 2024. It is now read-only.

Commit

Permalink
feat: Framework Init - base template with Outbound transport config
Browse files Browse the repository at this point in the history
- Add New(opts) function which takes in the options to configuration
- Support outbound transport configuration

Closes #78

Signed-off-by: Rolson Quadras <[email protected]>
  • Loading branch information
rolsonquadras committed Aug 12, 2019
1 parent a8eff94 commit 94efeb3
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 0 deletions.
40 changes: 40 additions & 0 deletions pkg/framework/aries/default.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
Copyright SecureKey Technologies Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/

package aries

import (
"github.com/hyperledger/aries-framework-go/pkg/didcomm/transport"
errors "golang.org/x/xerrors"
)

// defFramework provides default framework configs
type defFramework struct{}

// outboundTransport provides default OutboundTransport
func (d defFramework) outboundTransport() (transport.OutboundTransport, error) {
// TODO - https://github.com/hyperledger/aries-framework-go/issues/83
return nil, nil
}

// defFrameworkOpts provides default framework optios
func defFrameworkOpts() ([]Option, error) {
// get the default framework configs
def := defFramework{}

// outbound transport
ot, err := def.outboundTransport()
if err != nil {
return nil, errors.Errorf("Default outbound transport init failed : %w", err)
}

var opts []Option

opt := WithOutboundTransport(ot)
opts = append(opts, opt)

return opts, nil
}
63 changes: 63 additions & 0 deletions pkg/framework/aries/framework.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
Copyright SecureKey Technologies Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/

package aries

import (
"github.com/hyperledger/aries-framework-go/pkg/didcomm/transport"
errors "golang.org/x/xerrors"
)

// Framework provides access to clients being managed by the Framework.
type Framework struct {
opts options
}

type options struct {
OutboundTransport transport.OutboundTransport
}

// Option configures the framework.
type Option func(opts *options) error

// New initializes the Framework based on the set of options provided.
func New(opts ...Option) (*Framework, error) {
// get the default framework options
defOpts, err := defFrameworkOpts()
if err != nil {
return nil, errors.Errorf("Default option init failed : %w", err)
}

frameworkOpts := options{}

// 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)
}
}

// create framework with default configs
framework := &Framework{
opts: frameworkOpts,
}

return framework, nil
}

// WithOutboundTransport injects a OutboundTransport interface to the Framework
func WithOutboundTransport(ot transport.OutboundTransport) Option {
return func(opts *options) error {
opts.OutboundTransport = ot
return nil
}
}

// OutboundTransport provides configured OutboundTransport
func (f *Framework) OutboundTransport() transport.OutboundTransport {
return f.opts.OutboundTransport
}
29 changes: 29 additions & 0 deletions pkg/framework/aries/framework_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
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"
)

func TestFramework(t *testing.T) {
ot := mocktransport.NewOutboundTransport("success")

f, err := New(WithOutboundTransport(ot))
require.NoError(t, err)

req := &exchange.Request{
ID: "5678876542345",
Label: "Bob",
}

require.NoError(t, exchange.SendExchangeRequest(req, "http://example/didexchange", f.OutboundTransport()))
}

0 comments on commit 94efeb3

Please sign in to comment.