-
Notifications
You must be signed in to change notification settings - Fork 486
/
bearer.go
64 lines (54 loc) · 1.97 KB
/
bearer.go
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Package bearer provides an otelcol.auth.bearer component.
package bearer
import (
"github.com/grafana/agent/component"
"github.com/grafana/agent/component/otelcol/auth"
otel_service "github.com/grafana/agent/service/otel"
"github.com/grafana/river/rivertypes"
"github.com/open-telemetry/opentelemetry-collector-contrib/extension/bearertokenauthextension"
otelcomponent "go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config/configopaque"
otelextension "go.opentelemetry.io/collector/extension"
)
func init() {
component.Register(component.Registration{
Name: "otelcol.auth.bearer",
Args: Arguments{},
Exports: auth.Exports{},
NeedsServices: []string{otel_service.ServiceName},
Build: func(opts component.Options, args component.Arguments) (component.Component, error) {
fact := bearertokenauthextension.NewFactory()
return auth.New(opts, fact, args.(Arguments))
},
})
}
// Arguments configures the otelcol.auth.bearer component.
type Arguments struct {
// Do not include the "filename" attribute - users should use local.file instead.
Scheme string `river:"scheme,attr,optional"`
Token rivertypes.Secret `river:"token,attr"`
}
var _ auth.Arguments = Arguments{}
// DefaultArguments holds default settings for Arguments.
var DefaultArguments = Arguments{
Scheme: "Bearer",
}
// SetToDefault implements river.Defaulter.
func (args *Arguments) SetToDefault() {
*args = DefaultArguments
}
// Convert implements auth.Arguments.
func (args Arguments) Convert() (otelcomponent.Config, error) {
return &bearertokenauthextension.Config{
Scheme: args.Scheme,
BearerToken: configopaque.String(args.Token),
}, nil
}
// Extensions implements auth.Arguments.
func (args Arguments) Extensions() map[otelcomponent.ID]otelextension.Extension {
return nil
}
// Exporters implements auth.Arguments.
func (args Arguments) Exporters() map[otelcomponent.DataType]map[otelcomponent.ID]otelcomponent.Component {
return nil
}