2022-02-22 16:36:36 +00:00
|
|
|
package configentry
|
|
|
|
|
|
|
|
import (
|
2022-04-05 21:10:06 +00:00
|
|
|
"github.com/hashicorp/consul/acl"
|
2022-02-22 16:36:36 +00:00
|
|
|
"github.com/hashicorp/consul/agent/structs"
|
|
|
|
)
|
|
|
|
|
|
|
|
// KindName is a value type useful for maps. You can use:
|
|
|
|
// map[KindName]Payload
|
|
|
|
// instead of:
|
|
|
|
// map[string]map[string]Payload
|
|
|
|
type KindName struct {
|
|
|
|
Kind string
|
|
|
|
Name string
|
2022-04-05 21:10:06 +00:00
|
|
|
acl.EnterpriseMeta
|
2022-02-22 16:36:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewKindName returns a new KindName. The EnterpriseMeta values will be
|
|
|
|
// normalized based on the kind.
|
|
|
|
//
|
|
|
|
// Any caller which modifies the EnterpriseMeta field must call Normalize
|
|
|
|
// before persisting or using the value as a map key.
|
2022-04-05 21:10:06 +00:00
|
|
|
func NewKindName(kind, name string, entMeta *acl.EnterpriseMeta) KindName {
|
2022-02-22 16:36:36 +00:00
|
|
|
ret := KindName{
|
|
|
|
Kind: kind,
|
|
|
|
Name: name,
|
|
|
|
}
|
|
|
|
if entMeta == nil {
|
|
|
|
entMeta = structs.DefaultEnterpriseMetaInDefaultPartition()
|
|
|
|
}
|
|
|
|
|
|
|
|
ret.EnterpriseMeta = *entMeta
|
|
|
|
ret.Normalize()
|
|
|
|
return ret
|
|
|
|
}
|
2022-02-25 21:46:34 +00:00
|
|
|
|
|
|
|
func NewKindNameForEntry(entry structs.ConfigEntry) KindName {
|
|
|
|
return NewKindName(entry.GetKind(), entry.GetName(), entry.GetEnterpriseMeta())
|
|
|
|
}
|