Skip to content

Commit b636b90

Browse files
authored
Refactor and remove test dependency which is not exported (#147)
1 parent 4c57e66 commit b636b90

File tree

5 files changed

+49
-36
lines changed

5 files changed

+49
-36
lines changed

.github/workflows/snyk.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@ jobs:
2323
with:
2424
args: --sarif-file-output=snyk.sarif
2525
- name: Upload result to GitHub Code Scanning
26-
uses: github/codeql-action/upload-sarif@v1
26+
uses: github/codeql-action/upload-sarif@v2
2727
with:
2828
sarif_file: snyk.sarif

pkg/grpc/connection.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import (
1919
"time"
2020

2121
"github.com/finleap-connect/monoskope/pkg/domain/errors"
22-
test_grpc "github.com/finleap-connect/monoskope/test/grpc"
2322
grpc_retry "github.com/grpc-ecosystem/go-grpc-middleware/retry"
2423
"golang.org/x/oauth2"
2524
"google.golang.org/grpc"
@@ -122,8 +121,8 @@ func NewClientWithAuthForward[T any](ctx context.Context, addr string, requireTr
122121
// NewClientWithInsecureAuth (USE ONLY IF SECURED BY SERVICE MESH OR SIMILAR) creates a new gRPC client which sends the auth token without TLS
123122
func NewClientWithInsecureAuth[T any](ctx context.Context, addr, authToken string, clientFactory func(cc grpc.ClientConnInterface) T) (*grpc.ClientConn, T, error) {
124123
conn, err := NewGrpcConnectionFactory(addr).
125-
WithPerRPCCredentials(test_grpc.NewOauthAccessWithoutTransportSecurity(&oauth2.Token{AccessToken: authToken})).
126124
WithInsecure().
125+
WithPerRPCCredentials(NewOauthAccessWithoutTransportSecurity(&oauth2.Token{AccessToken: authToken})).
127126
WithBlock().
128127
ConnectWithTimeout(ctx, 10*time.Second)
129128
if err != nil {
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,17 @@ import (
2222
"google.golang.org/grpc/credentials"
2323
)
2424

25-
// oauthAccess supplies PerRPCCredentials from a given token.
26-
type oauthAccess struct {
25+
// forwardedOAuthAccess supplies PerRPCCredentials from a given token.
26+
type forwardedOAuthAccess struct {
2727
requireTransportSecurity bool
2828
}
2929

3030
// NewForwardedOauthAccess constructs the PerRPCCredentials which forwards the authorization from header
3131
func NewForwardedOauthAccess(requireTransportSecurity bool) credentials.PerRPCCredentials {
32-
return oauthAccess{requireTransportSecurity}
32+
return forwardedOAuthAccess{requireTransportSecurity}
3333
}
3434

35-
func (oa oauthAccess) GetRequestMetadata(ctx context.Context, uri ...string) (map[string]string, error) {
35+
func (oa forwardedOAuthAccess) GetRequestMetadata(ctx context.Context, uri ...string) (map[string]string, error) {
3636
// Forward authorization header
3737
token, err := grpc_auth.AuthFromMD(ctx, auth.AuthScheme)
3838
if err != nil {
@@ -44,6 +44,6 @@ func (oa oauthAccess) GetRequestMetadata(ctx context.Context, uri ...string) (ma
4444
}, nil
4545
}
4646

47-
func (oa oauthAccess) RequireTransportSecurity() bool {
47+
func (oa forwardedOAuthAccess) RequireTransportSecurity() bool {
4848
return oa.requireTransportSecurity
4949
}

pkg/grpc/insecure_auth_token.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright 2022 Monoskope Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package grpc
16+
17+
import (
18+
"context"
19+
20+
"golang.org/x/oauth2"
21+
"google.golang.org/grpc/credentials"
22+
)
23+
24+
// insecureOauthAccess supplies PerRPCCredentials from a given token.
25+
type insecureOauthAccess struct {
26+
token oauth2.Token
27+
}
28+
29+
// NewOauthAccessWithoutTransportSecurity constructs the PerRPCCredentials using a given token for test purposes where no TLS necessary.
30+
func NewOauthAccessWithoutTransportSecurity(token *oauth2.Token) credentials.PerRPCCredentials {
31+
return insecureOauthAccess{token: *token}
32+
}
33+
34+
func (oa insecureOauthAccess) GetRequestMetadata(ctx context.Context, uri ...string) (map[string]string, error) {
35+
return map[string]string{
36+
"authorization": oa.token.Type() + " " + oa.token.AccessToken,
37+
}, nil
38+
}
39+
40+
func (oa insecureOauthAccess) RequireTransportSecurity() bool {
41+
return false
42+
}

test/grpc/auth_token.go

Lines changed: 0 additions & 28 deletions
This file was deleted.

0 commit comments

Comments
 (0)