-
Notifications
You must be signed in to change notification settings - Fork 185
/
sigv4.go
99 lines (85 loc) · 2.99 KB
/
sigv4.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package sigv4
import (
"github.com/grafana/alloy/internal/component"
"github.com/grafana/alloy/internal/component/otelcol/auth"
otelcolCfg "github.com/grafana/alloy/internal/component/otelcol/config"
"github.com/grafana/alloy/internal/featuregate"
"github.com/open-telemetry/opentelemetry-collector-contrib/extension/sigv4authextension"
otelcomponent "go.opentelemetry.io/collector/component"
otelextension "go.opentelemetry.io/collector/extension"
)
func init() {
component.Register(component.Registration{
Name: "otelcol.auth.sigv4",
Stability: featuregate.StabilityGenerallyAvailable,
Args: Arguments{},
Exports: auth.Exports{},
Build: func(opts component.Options, args component.Arguments) (component.Component, error) {
fact := sigv4authextension.NewFactory()
return auth.New(opts, fact, args.(Arguments))
},
})
}
// Arguments configures the otelcol.auth.sigv4 component.
type Arguments struct {
Region string `alloy:"region,attr,optional"`
Service string `alloy:"service,attr,optional"`
AssumeRole AssumeRole `alloy:"assume_role,block,optional"`
// DebugMetrics configures component internal metrics. Optional.
DebugMetrics otelcolCfg.DebugMetricsArguments `alloy:"debug_metrics,block,optional"`
}
var (
_ auth.Arguments = Arguments{}
)
// SetToDefault implements syntax.Defaulter.
func (args *Arguments) SetToDefault() {
args.DebugMetrics.SetToDefault()
}
// Convert implements auth.Arguments.
func (args Arguments) Convert() (otelcomponent.Config, error) {
res := sigv4authextension.Config{
Region: args.Region,
Service: args.Service,
AssumeRole: *args.AssumeRole.Convert(),
}
// sigv4authextension.Config has a private member called "credsProvider" which gets initialized when we call Validate().
// If we don't call validate, the unit tests for this component will fail.
if err := res.Validate(); err != nil {
return nil, err
}
return &res, nil
}
// Validate implements syntax.Validator.
func (args Arguments) Validate() error {
_, err := args.Convert()
return err
}
// 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
}
// DebugMetricsConfig implements auth.Arguments.
func (args Arguments) DebugMetricsConfig() otelcolCfg.DebugMetricsArguments {
return args.DebugMetrics
}
// AssumeRole replicates sigv4authextension.Config.AssumeRole
type AssumeRole struct {
ARN string `alloy:"arn,attr,optional"`
SessionName string `alloy:"session_name,attr,optional"`
STSRegion string `alloy:"sts_region,attr,optional"`
}
// Convert converts args into the upstream type.
func (args *AssumeRole) Convert() *sigv4authextension.AssumeRole {
if args == nil {
return nil
}
return &sigv4authextension.AssumeRole{
ARN: args.ARN,
SessionName: args.SessionName,
STSRegion: args.STSRegion,
}
}