diff --git a/pkg/framework/default.go b/pkg/framework/default.go new file mode 100644 index 0000000000..998f183475 --- /dev/null +++ b/pkg/framework/default.go @@ -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 +} diff --git a/pkg/framework/framework.go b/pkg/framework/framework.go new file mode 100644 index 0000000000..49c1f4a01b --- /dev/null +++ b/pkg/framework/framework.go @@ -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 +} diff --git a/pkg/framework/framework_test.go b/pkg/framework/framework_test.go new file mode 100644 index 0000000000..7eb4ee6bb8 --- /dev/null +++ b/pkg/framework/framework_test.go @@ -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())) +}