forked from thanos-io/thanos
-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathprotection_impls.go
More file actions
38 lines (29 loc) · 1.09 KB
/
protection_impls.go
File metadata and controls
38 lines (29 loc) · 1.09 KB
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
// Copyright (c) The Thanos Authors.
// Licensed under the Apache License 2.0.
package queryfrontend
import (
"context"
"github.com/pkg/errors"
)
// This file contains all protection rule implementations.
// Each protection implements the Protection interface defined in protection.go.
// AlwaysMatchProtection is a protection that always matches every query.
type AlwaysMatchProtection struct{}
func (n *AlwaysMatchProtection) Name() string { return "always-match" }
func (n *AlwaysMatchProtection) Run(_ context.Context, _ thanosQueryReq) (bool, error) {
return true, nil
}
// protectionRegistry maps protection names (as used in config) to their factory functions.
var protectionRegistry = map[string]ProtectionFactory{
"always-match": func(_ map[string]string) (Protection, error) {
return &AlwaysMatchProtection{}, nil
},
}
// LookupProtection returns the factory for the given protection name.
func LookupProtection(name string) (ProtectionFactory, error) {
factory, ok := protectionRegistry[name]
if !ok {
return nil, errors.Errorf("unknown protection %q", name)
}
return factory, nil
}