2023-08-11 13:12:13 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
|
2023-05-23 17:15:30 +00:00
|
|
|
package configentry
|
|
|
|
|
|
|
|
import (
|
|
|
|
"sort"
|
|
|
|
|
|
|
|
"github.com/hashicorp/consul/agent/structs"
|
|
|
|
)
|
|
|
|
|
|
|
|
func SortSlice(configs []structs.ConfigEntry) {
|
|
|
|
sort.SliceStable(configs, func(i, j int) bool {
|
|
|
|
return Less(configs[i], configs[j])
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func Less(first structs.ConfigEntry, second structs.ConfigEntry) bool {
|
|
|
|
if first.GetKind() < second.GetKind() {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
if first.GetKind() > second.GetKind() {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
if first.GetEnterpriseMeta().LessThan(second.GetEnterpriseMeta()) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
if second.GetEnterpriseMeta().LessThan(first.GetEnterpriseMeta()) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
return first.GetName() < second.GetName()
|
|
|
|
}
|
|
|
|
|
|
|
|
func EqualID(e1, e2 structs.ConfigEntry) bool {
|
|
|
|
return e1.GetKind() == e2.GetKind() &&
|
|
|
|
e1.GetEnterpriseMeta().IsSame(e2.GetEnterpriseMeta()) &&
|
|
|
|
e1.GetName() == e2.GetName()
|
|
|
|
}
|
2023-12-12 13:29:13 +00:00
|
|
|
|
|
|
|
func SameHash(e1, e2 structs.ConfigEntry) bool {
|
|
|
|
if e1.GetHash() == 0 || e2.GetHash() == 0 {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return e1.GetHash() == e2.GetHash()
|
|
|
|
}
|