| 1 |
// Copyright The OpenTelemetry Authors |
| 2 |
// SPDX-License-Identifier: Apache-2.0 |
| 3 |
|
| 4 |
package extensionauth // import "go.opentelemetry.io/collector/extension/extensionauth" |
| 5 |
|
| 6 |
import ( |
| 7 |
"net/http" |
| 8 |
|
| 9 |
"google.golang.org/grpc/credentials" |
| 10 |
) |
| 11 |
|
| 12 |
// HTTPClient is an optional Extension interface that can be used as an HTTP authenticator for the configauth.Config option. |
| 13 |
// Authenticators are then included as part of OpenTelemetry Collector builds and can be referenced by their |
| 14 |
// names from the [configauth.Config] configuration. |
| 15 |
type HTTPClient interface { |
| 16 |
// RoundTripper returns a RoundTripper that can be used to authenticate HTTP requests. |
| 17 |
RoundTripper(base http.RoundTripper) (http.RoundTripper, error) |
| 18 |
} |
| 19 |
|
| 20 |
// GRPCClient is an optional Extension interface that can be used as a gRPC authenticator for the configauth.Config option. |
| 21 |
// Authenticators are then included as part of OpenTelemetry Collector builds and can be referenced by their |
| 22 |
// names from the [configauth.Config] configuration. |
| 23 |
type GRPCClient interface { |
| 24 |
// PerRPCCredentials returns a PerRPCCredentials that can be used to authenticate gRPC requests. |
| 25 |
PerRPCCredentials() (credentials.PerRPCCredentials, error) |
| 26 |
} |
| 27 |
|
| 28 |
var _ HTTPClient = (*ClientRoundTripperFunc)(nil) |
| 29 |
|
| 30 |
// ClientRoundTripperFunc specifies the function that returns a RoundTripper that can be used to authenticate HTTP requests. |
| 31 |
type ClientRoundTripperFunc func(base http.RoundTripper) (http.RoundTripper, error) |
| 32 |
|
| 33 |
func (f ClientRoundTripperFunc) RoundTripper(base http.RoundTripper) (http.RoundTripper, error) { |
| 34 |
if f == nil { |
| 35 |
return base, nil |
| 36 |
} |
| 37 |
return f(base) |
| 38 |
} |
| 39 |
|
| 40 |
var _ GRPCClient = (*ClientPerRPCCredentialsFunc)(nil) |
| 41 |
|
| 42 |
// ClientPerRPCCredentialsFunc specifies the function that returns a PerRPCCredentials that can be used to authenticate gRPC requests. |
| 43 |
type ClientPerRPCCredentialsFunc func() (credentials.PerRPCCredentials, error) |
| 44 |
|
| 45 |
func (f ClientPerRPCCredentialsFunc) PerRPCCredentials() (credentials.PerRPCCredentials, error) { |
| 46 |
if f == nil { |
| 47 |
return nil, nil |
| 48 |
} |
| 49 |
return f() |
| 50 |
} |