-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Expand file tree
/
Copy pathconfig.go
More file actions
49 lines (38 loc) · 1.7 KB
/
config.go
File metadata and controls
49 lines (38 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package bearertokenauthextension // import "github.com/open-telemetry/opentelemetry-collector-contrib/extension/bearertokenauthextension"
import (
"errors"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config/configopaque"
)
// Config specifies how the Per-RPC bearer token based authentication data should be obtained.
type Config struct {
// Header specifies the auth-header for the token. Defaults to "Authorization"
Header string `mapstructure:"header,omitempty"`
// Scheme specifies the auth-scheme for the token. Defaults to "Bearer"
Scheme string `mapstructure:"scheme,omitempty"`
// BearerToken specifies the bearer token to use for every RPC.
BearerToken configopaque.String `mapstructure:"token,omitempty"`
// Tokens specifies multiple bearer tokens to use for every RPC.
Tokens []configopaque.String `mapstructure:"tokens,omitempty"`
// Filename points to a file that contains the bearer token(s) to use for every RPC.
Filename string `mapstructure:"filename,omitempty"`
// prevent unkeyed literal initialization
_ struct{}
}
var (
_ component.Config = (*Config)(nil)
errNoTokenProvided = errors.New("no bearer token provided")
errTokensAndTokenProvided = errors.New("either tokens or token should be provided, not both")
)
// Validate checks if the extension configuration is valid
func (cfg *Config) Validate() error {
if cfg.BearerToken == "" && len(cfg.Tokens) == 0 && cfg.Filename == "" {
return errNoTokenProvided
}
if cfg.BearerToken != "" && len(cfg.Tokens) > 0 {
return errTokensAndTokenProvided
}
return nil
}