File tree Expand file tree Collapse file tree 4 files changed +34
-1
lines changed
extension/bearertokenauthextension Expand file tree Collapse file tree 4 files changed +34
-1
lines changed Original file line number Diff line number Diff line change @@ -25,7 +25,7 @@ The authenticator type has to be set to `bearertokenauth`.
25
25
26
26
- ` token ` : Static authorization token that needs to be sent on every gRPC client call as metadata.
27
27
28
- - ` tokens ` : A list of static authorization tokens that needs to be sent on every gRPC client call as metadata.
28
+ - ` tokens ` : A list of static authorization tokens, one of which needs to be sent on every gRPC client call as metadata.
29
29
30
30
- ` filename ` : Name of file that contains a authorization token that needs to be sent in every client call.
31
31
Original file line number Diff line number Diff line change @@ -28,12 +28,16 @@ type Config struct {
28
28
var (
29
29
_ component.Config = (* Config )(nil )
30
30
errNoTokenProvided = errors .New ("no bearer token provided" )
31
+ errTokensAndTokenProvided = errors .New ("either tokens or token should be provided, not both" )
31
32
)
32
33
33
34
// Validate checks if the extension configuration is valid
34
35
func (cfg * Config ) Validate () error {
35
36
if cfg .BearerToken == "" && len (cfg .Tokens ) == 0 && cfg .Filename == "" {
36
37
return errNoTokenProvided
37
38
}
39
+ if cfg .BearerToken != "" && len (cfg .Tokens ) > 0 {
40
+ return errTokensAndTokenProvided
41
+ }
38
42
return nil
39
43
}
Original file line number Diff line number Diff line change @@ -65,6 +65,23 @@ func TestLoadConfig(t *testing.T) {
65
65
Filename : "file-containing.token" ,
66
66
},
67
67
},
68
+ {
69
+ id : component .NewIDWithName (metadata .Type , "tokensandtoken" ),
70
+ expected : & Config {
71
+ Scheme : "Bearer" ,
72
+ BearerToken : "sometoken" ,
73
+ Tokens : []configopaque.String {"token1" , "thistokenalsoworks" },
74
+ },
75
+ expectedErr : true ,
76
+ },
77
+ {
78
+ id : component .NewIDWithName (metadata .Type , "withtokensandfilename" ),
79
+ expected : & Config {
80
+ Scheme : "Bearer" ,
81
+ Tokens : []configopaque.String {"ignoredtoken1" , "ignoredtoken2" },
82
+ Filename : "file-containing.token" ,
83
+ },
84
+ },
68
85
}
69
86
for _ , tt := range tests {
70
87
t .Run (tt .id .String (), func (t * testing.T ) {
Original file line number Diff line number Diff line change @@ -16,3 +16,15 @@ bearertokenauth/both:
16
16
scheme : " Bearer"
17
17
token : " ignoredtoken"
18
18
filename : " file-containing.token"
19
+ bearertokenauth/withtokensandfilename :
20
+ scheme : " Bearer"
21
+ tokens :
22
+ - " ignoredtoken1"
23
+ - " ignoredtoken2"
24
+ filename : " file-containing.token"
25
+ bearertokenauth/tokensandtoken :
26
+ scheme : " Bearer"
27
+ tokens :
28
+ - " token1"
29
+ - " thistokenalsoworks"
30
+ token : " my-token"
You can’t perform that action at this time.
0 commit comments