Debian Codegraph @

extension/extensionauth/server.go

raw
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 "context"
8 )
9
10 // Server is an optional Extension interface that can be used as an authenticator for the configauth.Config option.
11 // Authenticators are then included as part of OpenTelemetry Collector builds and can be referenced by their
12 // names from the [configauth.Config] configuration. Each Server is free to define its own behavior and configuration options,
13 // but note that the expectations that come as part of Extensions exist here as well. For instance, multiple instances of the same
14 // authenticator should be possible to exist under different names.
15 type Server interface {
16 // Authenticate checks whether the given map contains valid auth data. Successfully authenticated calls will always return a nil error.
17 // When the authentication fails, an error must be returned and the caller must not retry. This function is typically called from interceptors,
18 // on behalf of receivers, but receivers can still call this directly if the usage of interceptors isn't suitable.
19 // The deadline and cancellation given to this function must be respected, but note that authentication data has to be part of the map, not context.
20 // The resulting context should contain the authentication data, such as the principal/username, group membership (if available), and the raw
21 // authentication data (if possible). This will allow other components in the pipeline to make decisions based on that data, such as routing based
22 // on tenancy as determined by the group membership, or passing through the authentication data to the next collector/backend.
23 // The context keys to be used are not defined yet.
24 Authenticate(ctx context.Context, sources map[string][]string) (context.Context, error)
25 }
26
27 // ServerAuthenticateFunc defines the signature for the function responsible for performing the authentication based
28 // on the given sources map. See Server.Authenticate.
29 type ServerAuthenticateFunc func(ctx context.Context, sources map[string][]string) (context.Context, error)
30
31 func (f ServerAuthenticateFunc) Authenticate(ctx context.Context, sources map[string][]string) (context.Context, error) {
32 if f == nil {
33 return ctx, nil
34 }
35 return f(ctx, sources)
36 }