-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rework sandbox.DefaultDialOptions to sandbox.DialOptions with options (…
…#1059) Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>
- Loading branch information
Vladimir Popov
authored
Aug 11, 2021
1 parent
15a33a4
commit 74e4c20
Showing
11 changed files
with
92 additions
and
44 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
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
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,68 @@ | ||
// Copyright (c) 2020-2021 Doc.ai and/or its affiliates. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at: | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package sandbox | ||
|
||
import ( | ||
"github.com/edwarnicke/grpcfd" | ||
"google.golang.org/grpc" | ||
"google.golang.org/grpc/credentials/insecure" | ||
|
||
"github.com/networkservicemesh/sdk/pkg/tools/opentracing" | ||
"github.com/networkservicemesh/sdk/pkg/tools/token" | ||
) | ||
|
||
type dialOpts struct { | ||
tokenGenerator token.GeneratorFunc | ||
} | ||
|
||
// DialOption is an option pattern for DialOptions | ||
type DialOption func(o *dialOpts) | ||
|
||
// WithTokenGenerator sets tokenGenerator for DialOptions | ||
func WithTokenGenerator(tokenGenerator token.GeneratorFunc) DialOption { | ||
return func(opts *dialOpts) { | ||
opts.tokenGenerator = tokenGenerator | ||
} | ||
} | ||
|
||
// DialOptions is a helper method for building []grpc.DialOption for testing | ||
func DialOptions(options ...DialOption) []grpc.DialOption { | ||
tokenResetCh := make(chan struct{}) | ||
close(tokenResetCh) | ||
|
||
opts := &dialOpts{ | ||
tokenGenerator: GenerateTestToken, | ||
} | ||
for _, o := range options { | ||
o(opts) | ||
} | ||
|
||
return append([]grpc.DialOption{ | ||
grpc.WithTransportCredentials( | ||
grpcfdTransportCredentials(insecure.NewCredentials()), | ||
), | ||
grpc.WithBlock(), | ||
grpc.WithDefaultCallOptions( | ||
grpc.WaitForReady(true), | ||
grpc.PerRPCCredentials(token.NewPerRPCCredentials(opts.tokenGenerator)), | ||
), | ||
grpcfd.WithChainStreamInterceptor(), | ||
grpcfd.WithChainUnaryInterceptor(), | ||
WithInsecureRPCCredentials(), | ||
WithInsecureStreamRPCCredentials(), | ||
}, opentracing.WithTracingDial()...) | ||
} |
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