2023-04-20 12:40:22 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2023-04-11 18:23:14 +00:00
|
|
|
package resource
|
|
|
|
|
|
|
|
import "github.com/hashicorp/consul/proto-public/pbresource"
|
|
|
|
|
|
|
|
// Reference returns a reference to the resource with the given ID.
|
|
|
|
func Reference(id *pbresource.ID, section string) *pbresource.Reference {
|
|
|
|
return &pbresource.Reference{
|
|
|
|
Type: id.Type,
|
|
|
|
Tenancy: id.Tenancy,
|
|
|
|
Name: id.Name,
|
|
|
|
Section: section,
|
|
|
|
}
|
|
|
|
}
|
2023-08-01 18:39:15 +00:00
|
|
|
|
|
|
|
// IDFromReference returns a Reference converted into an ID. NOTE: the UID
|
|
|
|
// field is not populated, and the Section field of a reference is dropped.
|
|
|
|
func IDFromReference(ref *pbresource.Reference) *pbresource.ID {
|
|
|
|
return &pbresource.ID{
|
|
|
|
Type: ref.Type,
|
|
|
|
Tenancy: ref.Tenancy,
|
|
|
|
Name: ref.Name,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ReferenceOrID is the common accessors shared by pbresource.Reference and
|
|
|
|
// pbresource.ID.
|
|
|
|
type ReferenceOrID interface {
|
|
|
|
GetType() *pbresource.Type
|
|
|
|
GetTenancy() *pbresource.Tenancy
|
|
|
|
GetName() string
|
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
_ ReferenceOrID = (*pbresource.ID)(nil)
|
|
|
|
_ ReferenceOrID = (*pbresource.Reference)(nil)
|
|
|
|
)
|