resource: Add scope to resource type registration [NET-4976] (#18214)

Enables querying a resource type's registration to determine if a resource is cluster, partition, or partition and namespace scoped.
pull/18259/head
Semir Patel 1 year ago committed by GitHub
parent 639210e28d
commit efb45fe851
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -133,6 +133,7 @@ func RegisterTypes(r resource.Registry) {
List: makeListACL(TypeV1Artist),
},
Validate: validateV1ArtistFn,
Scope: resource.ScopeNamespace,
})
r.Register(resource.Registration{
@ -143,6 +144,7 @@ func RegisterTypes(r resource.Registry) {
Write: writeACL,
List: makeListACL(TypeV1Album),
},
Scope: resource.ScopeNamespace,
})
r.Register(resource.Registration{
@ -155,6 +157,7 @@ func RegisterTypes(r resource.Registry) {
},
Validate: validateV2ArtistFn,
Mutate: mutateV2ArtistFn,
Scope: resource.ScopeNamespace,
})
r.Register(resource.Registration{
@ -165,6 +168,7 @@ func RegisterTypes(r resource.Registry) {
Write: writeACL,
List: makeListACL(TypeV2Album),
},
Scope: resource.ScopeNamespace,
})
}

@ -20,6 +20,34 @@ var (
kindRegexp = regexp.MustCompile(`^[A-Z][A-Za-z\d]+$`)
)
// Scope describes the tenancy scope of a resource.
type Scope int
const (
// There is no default scope, it must be set explicitly.
ScopeUndefined Scope = iota
// ScopeCluster describes a resource that is scoped to a cluster.
ScopeCluster
// ScopePartition describes a resource that is scoped to a partition.
ScopePartition
// ScopeNamespace applies to a resource that is scoped to a partition and namespace.
ScopeNamespace
)
func (s Scope) String() string {
switch s {
case ScopeUndefined:
return "undefined"
case ScopeCluster:
return "cluster"
case ScopePartition:
return "partition"
case ScopeNamespace:
return "namespace"
}
panic(fmt.Sprintf("string mapping missing for scope %v", int(s)))
}
type Registry interface {
// Register the given resource type and its hooks.
Register(reg Registration)
@ -45,6 +73,9 @@ type Registration struct {
// Mutate is called to fill out any autogenerated fields (e.g. UUIDs) or
// apply defaults before validation.
Mutate func(*pbresource.Resource) error
// Scope describes the tenancy scope of a resource.
Scope Scope
}
type ACLHooks struct {

Loading…
Cancel
Save