From b0d8f0f4e204db79f92e71059dcbf6592c08916d Mon Sep 17 00:00:00 2001 From: "anastasia.malysheva" Date: Thu, 28 Jul 2022 10:06:04 +0700 Subject: [PATCH] enable authorizeMonitorConnectionServer option Signed-off-by: anastasia.malysheva --- .../chains/forwarder/options.go | 31 +++++++++++++------ pkg/networkservice/chains/forwarder/server.go | 13 +++++--- 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/pkg/networkservice/chains/forwarder/options.go b/pkg/networkservice/chains/forwarder/options.go index 49fd8bc6..bfab8546 100644 --- a/pkg/networkservice/chains/forwarder/options.go +++ b/pkg/networkservice/chains/forwarder/options.go @@ -33,16 +33,17 @@ import ( ) type forwarderOptions struct { - name string - authorizeServer networkservice.NetworkServiceServer - clientURL *url.URL - dialTimeout time.Duration - domain2Device map[string]string - statsOpts []stats.Option - cleanupOpts []cleanup.Option - vxlanOpts []vxlan.Option - dialOpts []grpc.DialOption - clientAdditionalFunctionality []networkservice.NetworkServiceClient + name string + authorizeServer networkservice.NetworkServiceServer + authorizeMonitorConnectionServer networkservice.MonitorConnectionServer + clientURL *url.URL + dialTimeout time.Duration + domain2Device map[string]string + statsOpts []stats.Option + cleanupOpts []cleanup.Option + vxlanOpts []vxlan.Option + dialOpts []grpc.DialOption + clientAdditionalFunctionality []networkservice.NetworkServiceClient } // Option is an option pattern for forwarder chain elements @@ -65,6 +66,16 @@ func WithAuthorizeServer(authorizeServer networkservice.NetworkServiceServer) Op } } +// WithAuthorizeMonitorConnectionServer sets authorization server chain element +func WithAuthorizeMonitorConnectionServer(authorizeMonitorConnectionServer networkservice.MonitorConnectionServer) Option { + if authorizeMonitorConnectionServer == nil { + panic("Authorize monitor server cannot be nil") + } + return func(o *forwarderOptions) { + o.authorizeMonitorConnectionServer = authorizeMonitorConnectionServer + } +} + // WithClientURL sets clientURL. func WithClientURL(clientURL *url.URL) Option { return func(c *forwarderOptions) { diff --git a/pkg/networkservice/chains/forwarder/server.go b/pkg/networkservice/chains/forwarder/server.go index 88845341..59591be3 100644 --- a/pkg/networkservice/chains/forwarder/server.go +++ b/pkg/networkservice/chains/forwarder/server.go @@ -43,6 +43,7 @@ import ( "github.com/networkservicemesh/sdk/pkg/networkservice/common/mechanisms/sendfd" "github.com/networkservicemesh/sdk/pkg/networkservice/common/mechanismtranslation" "github.com/networkservicemesh/sdk/pkg/networkservice/common/roundrobin" + authmonitor "github.com/networkservicemesh/sdk/pkg/tools/monitorconnection/authorize" "github.com/networkservicemesh/sdk/pkg/tools/token" registryclient "github.com/networkservicemesh/sdk/pkg/registry/chains/client" @@ -79,11 +80,12 @@ type xconnectNSServer struct { // NewServer - returns an implementation of the xconnectns network service func NewServer(ctx context.Context, tokenGenerator token.GeneratorFunc, vppConn Connection, tunnelIP net.IP, options ...Option) endpoint.Endpoint { opts := &forwarderOptions{ - name: "forwarder-vpp-" + uuid.New().String(), - authorizeServer: authorize.NewServer(authorize.Any()), - clientURL: &url.URL{Scheme: "unix", Host: "connect.to.socket"}, - dialTimeout: time.Millisecond * 200, - domain2Device: make(map[string]string), + name: "forwarder-vpp-" + uuid.New().String(), + authorizeServer: authorize.NewServer(authorize.Any()), + authorizeMonitorConnectionServer: authmonitor.NewMonitorConnectionServer(authmonitor.Any()), + clientURL: &url.URL{Scheme: "unix", Host: "connect.to.socket"}, + dialTimeout: time.Millisecond * 200, + domain2Device: make(map[string]string), } for _, opt := range options { opt(opts) @@ -161,6 +163,7 @@ func NewServer(ctx context.Context, tokenGenerator token.GeneratorFunc, vppConn rv.Endpoint = endpoint.NewServer(ctx, tokenGenerator, endpoint.WithName(opts.name), endpoint.WithAuthorizeServer(opts.authorizeServer), + endpoint.WithAuthorizeMonitorConnectionServer(opts.authorizeMonitorConnectionServer), endpoint.WithAdditionalFunctionality(additionalFunctionality...)) return rv