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 Closes #78 Signed-off-by: Rolson Quadras <[email protected]>
- Loading branch information
1 parent
a8eff94
commit 9b194c7
Showing
3 changed files
with
115 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
Copyright SecureKey Technologies Inc. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package framework | ||
|
||
import ( | ||
"github.com/hyperledger/aries-framework-go/pkg/didcomm/transport" | ||
) | ||
|
||
// 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 | ||
} |
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,66 @@ | ||
/* | ||
Copyright SecureKey Technologies Inc. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package framework | ||
|
||
import ( | ||
"github.com/hyperledger/aries-framework-go/pkg/didcomm/transport" | ||
errors "golang.org/x/xerrors" | ||
) | ||
|
||
// AriesFramework provides access to clients being managed by the Framework. | ||
type AriesFramework 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) (*AriesFramework, 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) | ||
} | ||
|
||
// create framework with default configs | ||
framework := &AriesFramework{ | ||
opts: options{ | ||
OutboundTransport: ot, | ||
}, | ||
} | ||
|
||
// generate framework configs from options | ||
for _, option := range opts { | ||
err := option(&framework.opts) | ||
if err != nil { | ||
return nil, errors.Errorf("Error in option passed to New: %w", err) | ||
} | ||
} | ||
|
||
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 *AriesFramework) OutboundTransport() transport.OutboundTransport { | ||
return f.opts.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,29 @@ | ||
/* | ||
Copyright SecureKey Technologies Inc. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package framework | ||
|
||
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())) | ||
} |