From 8ba919f9132ae28b66ab17f4c24fcac3555979aa Mon Sep 17 00:00:00 2001 From: Semir Patel Date: Tue, 20 Feb 2024 17:38:06 -0600 Subject: [PATCH] v2tenancy: make CE specific version of `resource.Registration` (#20681) --- internal/resource/registry.go | 33 --------------------------- internal/resource/registry_ce.go | 38 ++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 33 deletions(-) create mode 100644 internal/resource/registry_ce.go diff --git a/internal/resource/registry.go b/internal/resource/registry.go index a59e25e447a1..7faf84fe5eb6 100644 --- a/internal/resource/registry.go +++ b/internal/resource/registry.go @@ -10,8 +10,6 @@ import ( "strings" "sync" - "google.golang.org/protobuf/proto" - "github.com/hashicorp/consul/acl" "github.com/hashicorp/consul/internal/storage" "github.com/hashicorp/consul/proto-public/pbresource" @@ -53,37 +51,6 @@ type ValidationHook func(*pbresource.Resource) error // the data gets reencoded and stored back to the Data field. type MutationHook func(*pbresource.Resource) error -type Registration struct { - // Type is the GVK of the resource type. - Type *pbresource.Type - - // Proto is the resource's protobuf message type. - Proto proto.Message - - // ACLs are hooks called to perform authorization on RPCs. - // The hooks can assume that Validate has been called. - ACLs *ACLHooks - - // Validate is called to structurally validate the resource (e.g. - // check for required fields). Validate can assume that Mutate - // has been called. - Validate ValidationHook - - // Mutate is called to fill out any autogenerated fields (e.g. UUIDs) or - // apply defaults before validation. Mutate can assume that - // Resource.ID is populated and has non-empty tenancy fields. This does - // not mean those tenancy fields actually exist. - Mutate MutationHook - - // Scope describes the tenancy scope of a resource. - Scope Scope - - // LicenseFeature is an optional enterprise license feature that the - // resource type is associated with. A string form of license.Feature - // from the consul-licensing module is expected. - LicenseFeature string -} - var ErrNeedResource = errors.New("authorization check requires the entire resource") type ACLAuthorizeReadHook func(acl.Authorizer, *acl.AuthorizerContext, *pbresource.ID, *pbresource.Resource) error diff --git a/internal/resource/registry_ce.go b/internal/resource/registry_ce.go new file mode 100644 index 000000000000..985a81640615 --- /dev/null +++ b/internal/resource/registry_ce.go @@ -0,0 +1,38 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: BUSL-1.1 + +//go:build !consulent + +package resource + +import ( + "google.golang.org/protobuf/proto" + + "github.com/hashicorp/consul/proto-public/pbresource" +) + +type Registration struct { + // Type is the GVK of the resource type. + Type *pbresource.Type + + // Proto is the resource's protobuf message type. + Proto proto.Message + + // ACLs are hooks called to perform authorization on RPCs. + // The hooks can assume that Validate has been called. + ACLs *ACLHooks + + // Validate is called to structurally validate the resource (e.g. + // check for required fields). Validate can assume that Mutate + // has been called. + Validate ValidationHook + + // Mutate is called to fill out any autogenerated fields (e.g. UUIDs) or + // apply defaults before validation. Mutate can assume that + // Resource.ID is populated and has non-empty tenancy fields. This does + // not mean those tenancy fields actually exist. + Mutate MutationHook + + // Scope describes the tenancy scope of a resource. + Scope Scope +}