aboutsummaryrefslogtreecommitdiff
path: root/plugin/metadata/provider.go
diff options
context:
space:
mode:
Diffstat (limited to 'plugin/metadata/provider.go')
-rw-r--r--plugin/metadata/provider.go16
1 files changed, 16 insertions, 0 deletions
diff --git a/plugin/metadata/provider.go b/plugin/metadata/provider.go
index eb7bb9755..276a44127 100644
--- a/plugin/metadata/provider.go
+++ b/plugin/metadata/provider.go
@@ -32,6 +32,7 @@ package metadata
import (
"context"
+ "strings"
"github.com/coredns/coredns/request"
)
@@ -48,6 +49,21 @@ type Provider interface {
// Func is the type of function in the metadata, when called they return the value of the label.
type Func func() string
+// IsLabel check that the provided name looks like a valid label name
+func IsLabel(label string) bool {
+ p := strings.Index(label, "/")
+ if p <= 0 || p >= len(label)-1 {
+ // cannot accept namespace empty nor label empty
+ return false
+ }
+ if strings.LastIndex(label, "/") != p {
+ // several slash in the Label
+ return false
+ }
+ return true
+
+}
+
// Labels returns all metadata keys stored in the context. These label names should be named
// as: plugin/NAME, where NAME is something descriptive.
func Labels(ctx context.Context) []string {