mirror of https://github.com/status-im/consul.git
54 lines
1.2 KiB
Go
54 lines
1.2 KiB
Go
|
// Copyright (c) HashiCorp, Inc.
|
||
|
// SPDX-License-Identifier: MPL-2.0
|
||
|
|
||
|
package resource
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"strings"
|
||
|
|
||
|
"github.com/hashicorp/consul/proto-public/pbresource"
|
||
|
)
|
||
|
|
||
|
const (
|
||
|
DefaultPartitionName = "default"
|
||
|
DefaultNamespaceName = "default"
|
||
|
)
|
||
|
|
||
|
// Scope describes the tenancy scope of a resource.
|
||
|
type Scope int
|
||
|
|
||
|
const (
|
||
|
// There is no default scope, it must be set explicitly.
|
||
|
ScopeUndefined Scope = iota
|
||
|
// ScopeCluster describes a resource that is scoped to a cluster.
|
||
|
ScopeCluster
|
||
|
// ScopePartition describes a resource that is scoped to a partition.
|
||
|
ScopePartition
|
||
|
// ScopeNamespace applies to a resource that is scoped to a partition and namespace.
|
||
|
ScopeNamespace
|
||
|
)
|
||
|
|
||
|
func (s Scope) String() string {
|
||
|
switch s {
|
||
|
case ScopeUndefined:
|
||
|
return "undefined"
|
||
|
case ScopeCluster:
|
||
|
return "cluster"
|
||
|
case ScopePartition:
|
||
|
return "partition"
|
||
|
case ScopeNamespace:
|
||
|
return "namespace"
|
||
|
}
|
||
|
panic(fmt.Sprintf("string mapping missing for scope %v", int(s)))
|
||
|
}
|
||
|
|
||
|
// Normalize lowercases partition and namespace.
|
||
|
func Normalize(tenancy *pbresource.Tenancy) {
|
||
|
if tenancy == nil {
|
||
|
return
|
||
|
}
|
||
|
tenancy.Partition = strings.ToLower(tenancy.Partition)
|
||
|
tenancy.Namespace = strings.ToLower(tenancy.Namespace)
|
||
|
}
|