2023-03-28 18:39:22 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
2023-08-11 13:12:13 +00:00
|
|
|
// SPDX-License-Identifier: BUSL-1.1
|
2023-03-28 18:39:22 +00:00
|
|
|
|
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:
|
2022-10-21 19:58:06 +00:00
|
|
|
//
|
|
|
|
// map[KindName]Payload
|
|
|
|
//
|
2022-02-22 16:36:36 +00:00
|
|
|
// instead of:
|
2022-10-21 19:58:06 +00:00
|
|
|
//
|
|
|
|
// map[string]map[string]Payload
|
2022-02-22 16:36:36 +00:00
|
|
|
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())
|
|
|
|
}
|