forked from sensu/sensu-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
namespace.go
33 lines (26 loc) · 874 Bytes
/
namespace.go
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
package store
import (
"context"
"github.com/sensu/sensu-go/types"
)
const (
// WildcardValue is the symbol that denotes a wildcard namespace.
WildcardValue = "*"
// Root is the root of the sensu keyspace.
Root = "/sensu.io"
)
// NewNamespaceFromContext creates a new Namespace from a context.
func NewNamespaceFromContext(ctx context.Context) string {
if value := ctx.Value(types.NamespaceKey); value != nil {
return value.(string)
}
return ""
}
// NamespaceContext returns a context populated with the provided namespace.
func NamespaceContext(ctx context.Context, namespace string) context.Context {
return context.WithValue(ctx, types.NamespaceKey, namespace)
}
// NewNamespaceFromResource creates a new Namespace from a MultitenantResource.
func NewNamespaceFromResource(resource types.MultitenantResource) string {
return resource.GetNamespace()
}