@@ -12,27 +12,34 @@ import (
12
12
"go.opentelemetry.io/collector/extension"
13
13
)
14
14
15
- // Client is an Extension that can be used as an authenticator for the configauth.Authentication option.
15
+ // HTTPClient is an Extension that can be used as an HTTP authenticator for the configauth.Authentication option.
16
16
// Authenticators are then included as part of OpenTelemetry Collector builds and can be referenced by their
17
17
// names from the Authentication configuration.
18
- type Client interface {
18
+ type HTTPClient interface {
19
19
extension.Extension
20
20
21
21
// RoundTripper returns a RoundTripper that can be used to authenticate HTTP requests.
22
22
RoundTripper (base http.RoundTripper ) (http.RoundTripper , error )
23
+ }
24
+
25
+ // GRPCClient is an Extension that can be used as an HTTP authenticator for the configauth.Authentication option.
26
+ // Authenticators are then included as part of OpenTelemetry Collector builds and can be referenced by their
27
+ // names from the Authentication configuration.
28
+ type GRPCClient interface {
29
+ extension.Extension
23
30
24
31
// PerRPCCredentials returns a PerRPCCredentials that can be used to authenticate gRPC requests.
25
32
PerRPCCredentials () (credentials.PerRPCCredentials , error )
26
33
}
27
34
28
35
// ClientOption represents the possible options for NewClient.
29
36
type ClientOption interface {
30
- apply (* defaultClient )
37
+ apply (* Client )
31
38
}
32
39
33
- type clientOptionFunc func (* defaultClient )
40
+ type clientOptionFunc func (* Client )
34
41
35
- func (of clientOptionFunc ) apply (e * defaultClient ) {
42
+ func (of clientOptionFunc ) apply (e * Client ) {
36
43
of (e )
37
44
}
38
45
@@ -42,25 +49,29 @@ type ClientRoundTripperFunc func(base http.RoundTripper) (http.RoundTripper, err
42
49
// ClientPerRPCCredentialsFunc specifies the function that returns a PerRPCCredentials that can be used to authenticate gRPC requests.
43
50
type ClientPerRPCCredentialsFunc func () (credentials.PerRPCCredentials , error )
44
51
45
- var _ Client = (* defaultClient )(nil )
52
+ var (
53
+ _ HTTPClient = (* Client )(nil )
54
+ _ GRPCClient = (* Client )(nil )
55
+ )
46
56
47
- type defaultClient struct {
57
+ // Client is an Extension that can be used as an HTTP and gRPC authenticator for the configauth.Authentication option.
58
+ type Client struct {
48
59
component.StartFunc
49
60
component.ShutdownFunc
50
61
clientRoundTripperFunc ClientRoundTripperFunc
51
62
clientPerRPCCredentialsFunc ClientPerRPCCredentialsFunc
52
63
}
53
64
54
65
// PerRPCCredentials implements Client.
55
- func (d * defaultClient ) PerRPCCredentials () (credentials.PerRPCCredentials , error ) {
66
+ func (d * Client ) PerRPCCredentials () (credentials.PerRPCCredentials , error ) {
56
67
if d .clientPerRPCCredentialsFunc == nil {
57
68
return nil , nil
58
69
}
59
70
return d .clientPerRPCCredentialsFunc ()
60
71
}
61
72
62
73
// RoundTripper implements Client.
63
- func (d * defaultClient ) RoundTripper (base http.RoundTripper ) (http.RoundTripper , error ) {
74
+ func (d * Client ) RoundTripper (base http.RoundTripper ) (http.RoundTripper , error ) {
64
75
if d .clientRoundTripperFunc == nil {
65
76
return base , nil
66
77
}
@@ -70,38 +81,38 @@ func (d *defaultClient) RoundTripper(base http.RoundTripper) (http.RoundTripper,
70
81
// WithClientStart overrides the default `Start` function for a component.Component.
71
82
// The default always returns nil.
72
83
func WithClientStart (startFunc component.StartFunc ) ClientOption {
73
- return clientOptionFunc (func (o * defaultClient ) {
84
+ return clientOptionFunc (func (o * Client ) {
74
85
o .StartFunc = startFunc
75
86
})
76
87
}
77
88
78
89
// WithClientShutdown overrides the default `Shutdown` function for a component.Component.
79
90
// The default always returns nil.
80
91
func WithClientShutdown (shutdownFunc component.ShutdownFunc ) ClientOption {
81
- return clientOptionFunc (func (o * defaultClient ) {
92
+ return clientOptionFunc (func (o * Client ) {
82
93
o .ShutdownFunc = shutdownFunc
83
94
})
84
95
}
85
96
86
97
// WithClientRoundTripper provides a `RoundTripper` function for this client authenticator.
87
98
// The default round tripper is no-op.
88
99
func WithClientRoundTripper (roundTripperFunc ClientRoundTripperFunc ) ClientOption {
89
- return clientOptionFunc (func (o * defaultClient ) {
100
+ return clientOptionFunc (func (o * Client ) {
90
101
o .clientRoundTripperFunc = roundTripperFunc
91
102
})
92
103
}
93
104
94
105
// WithClientPerRPCCredentials provides a `PerRPCCredentials` function for this client authenticator.
95
106
// There's no default.
96
107
func WithClientPerRPCCredentials (perRPCCredentialsFunc ClientPerRPCCredentialsFunc ) ClientOption {
97
- return clientOptionFunc (func (o * defaultClient ) {
108
+ return clientOptionFunc (func (o * Client ) {
98
109
o .clientPerRPCCredentialsFunc = perRPCCredentialsFunc
99
110
})
100
111
}
101
112
102
113
// NewClient returns a Client configured with the provided options.
103
- func NewClient (options ... ClientOption ) (Client , error ) {
104
- bc := & defaultClient {}
114
+ func NewClient (options ... ClientOption ) (* Client , error ) {
115
+ bc := & Client {}
105
116
106
117
for _ , op := range options {
107
118
op .apply (bc )
0 commit comments