2023-03-28 19:39:22 +01:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2022-02-22 10:36:36 -06:00
|
|
|
package configentry
|
|
|
|
|
|
|
|
import (
|
2022-04-05 14:10:06 -07:00
|
|
|
"github.com/hashicorp/consul/acl"
|
2022-02-22 10:36:36 -06:00
|
|
|
"github.com/hashicorp/consul/agent/structs"
|
|
|
|
)
|
|
|
|
|
|
|
|
// KindName is a value type useful for maps. You can use:
|
2022-10-21 15:58:06 -04:00
|
|
|
//
|
|
|
|
// map[KindName]Payload
|
|
|
|
//
|
2022-02-22 10:36:36 -06:00
|
|
|
// instead of:
|
2022-10-21 15:58:06 -04:00
|
|
|
//
|
|
|
|
// map[string]map[string]Payload
|
2022-02-22 10:36:36 -06:00
|
|
|
type KindName struct {
|
|
|
|
Kind string
|
|
|
|
Name string
|
2022-04-05 14:10:06 -07:00
|
|
|
acl.EnterpriseMeta
|
2022-02-22 10:36:36 -06: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 14:10:06 -07:00
|
|
|
func NewKindName(kind, name string, entMeta *acl.EnterpriseMeta) KindName {
|
2022-02-22 10:36:36 -06:00
|
|
|
ret := KindName{
|
|
|
|
Kind: kind,
|
|
|
|
Name: name,
|
|
|
|
}
|
|
|
|
if entMeta == nil {
|
|
|
|
entMeta = structs.DefaultEnterpriseMetaInDefaultPartition()
|
|
|
|
}
|
|
|
|
|
|
|
|
ret.EnterpriseMeta = *entMeta
|
|
|
|
ret.Normalize()
|
|
|
|
return ret
|
|
|
|
}
|
2022-02-25 15:46:34 -06:00
|
|
|
|
|
|
|
func NewKindNameForEntry(entry structs.ConfigEntry) KindName {
|
|
|
|
return NewKindName(entry.GetKind(), entry.GetName(), entry.GetEnterpriseMeta())
|
|
|
|
}
|