From 9405cc7df76dd73312a3bddea47093aa0328d7f5 Mon Sep 17 00:00:00 2001 From: Thy Ton Date: Mon, 10 Jun 2024 10:58:44 -0700 Subject: [PATCH] restructure to follow entAddExtPlugins() go build tag usage pattern --- helper/builtinplugins/registry.go | 17 ++++++++--------- helper/builtinplugins/registry_full.go | 12 +++++++----- helper/builtinplugins/registry_full_test.go | 10 +++++----- helper/builtinplugins/registry_min.go | 4 ++-- 4 files changed, 22 insertions(+), 21 deletions(-) diff --git a/helper/builtinplugins/registry.go b/helper/builtinplugins/registry.go index ca463e5fa4d4..e5a6044e5f3c 100644 --- a/helper/builtinplugins/registry.go +++ b/helper/builtinplugins/registry.go @@ -5,7 +5,6 @@ package builtinplugins import ( "context" - "maps" credJWT "github.com/hashicorp/vault-plugin-auth-jwt" logicalKv "github.com/hashicorp/vault-plugin-secrets-kv" @@ -54,8 +53,8 @@ func removedFactory(ctx context.Context, config *logical.BackendConfig) (logical return removedBackend, nil } -func newCommonRegistry() *registry { - reg := ®istry{ +func newMinimalRegistry() *registry { + return ®istry{ credentialBackends: map[string]credentialBackend{ "approle": {Factory: credAppRole.Factory}, "cert": {Factory: credCert.Factory}, @@ -71,6 +70,12 @@ func newCommonRegistry() *registry { "transit": {Factory: logicalTransit.Factory}, }, } +} + +func newRegistry() *registry { + reg := newMinimalRegistry() + + extendAddonPlugins(reg) entAddExtPlugins(reg) @@ -159,12 +164,6 @@ func (r *registry) DeprecationStatus(name string, pluginType consts.PluginType) return consts.Unknown, false } -func (r *registry) Extend(other *registry) { - maps.Copy(other.credentialBackends, r.credentialBackends) - maps.Copy(other.databasePlugins, r.databasePlugins) - maps.Copy(other.logicalBackends, r.logicalBackends) -} - func toFunc(ifc interface{}) func() (interface{}, error) { return func() (interface{}, error) { return ifc, nil diff --git a/helper/builtinplugins/registry_full.go b/helper/builtinplugins/registry_full.go index 7eaf41d481ce..32bba4048796 100644 --- a/helper/builtinplugins/registry_full.go +++ b/helper/builtinplugins/registry_full.go @@ -6,6 +6,8 @@ package builtinplugins import ( + "maps" + credAliCloud "github.com/hashicorp/vault-plugin-auth-alicloud" credAzure "github.com/hashicorp/vault-plugin-auth-azure" credCF "github.com/hashicorp/vault-plugin-auth-cf" @@ -138,10 +140,10 @@ func newFullAddonRegistry() *registry { } } -func newRegistry() *registry { - reg := newFullAddonRegistry() - - reg.Extend(newCommonRegistry()) +func extendAddonPlugins(reg *registry) { + addonReg := newFullAddonRegistry() - return reg + maps.Copy(reg.credentialBackends, addonReg.credentialBackends) + maps.Copy(reg.databasePlugins, addonReg.databasePlugins) + maps.Copy(reg.logicalBackends, addonReg.logicalBackends) } diff --git a/helper/builtinplugins/registry_full_test.go b/helper/builtinplugins/registry_full_test.go index 947d972eb0d5..2f4938be0097 100644 --- a/helper/builtinplugins/registry_full_test.go +++ b/helper/builtinplugins/registry_full_test.go @@ -11,17 +11,17 @@ import ( func Test_newRegistry(t *testing.T) { actual := newRegistry() - expCommon := newCommonRegistry() + expMinimal := newMinimalRegistry() expFullAddon := newFullAddonRegistry() - assert.Equal(t, len(actual.credentialBackends), len(expCommon.credentialBackends)+len(expFullAddon.credentialBackends), + assert.Equal(t, len(expMinimal.credentialBackends)+len(expFullAddon.credentialBackends), len(actual.credentialBackends), "newRegistry() total auth backends mismatch total of common and full addon registries") - assert.Equal(t, len(actual.databasePlugins), len(expCommon.databasePlugins)+len(expFullAddon.databasePlugins), + assert.Equal(t, len(expMinimal.databasePlugins)+len(expFullAddon.databasePlugins), len(actual.databasePlugins), "newRegistry() total database plugins mismatch total of common and full addon registries") - assert.Equal(t, len(actual.logicalBackends), len(expCommon.logicalBackends)+len(expFullAddon.logicalBackends), + assert.Equal(t, len(expMinimal.logicalBackends)+len(expFullAddon.logicalBackends), len(actual.logicalBackends), "newRegistry() total logical backends mismatch total of common and full addon registries") - assertRegistrySubset(t, actual, expCommon, "common") + assertRegistrySubset(t, actual, expMinimal, "common") assertRegistrySubset(t, actual, expFullAddon, "full addon") } diff --git a/helper/builtinplugins/registry_min.go b/helper/builtinplugins/registry_min.go index fe3a1c31880c..75b281f631b7 100644 --- a/helper/builtinplugins/registry_min.go +++ b/helper/builtinplugins/registry_min.go @@ -5,6 +5,6 @@ package builtinplugins -func newRegistry() *registry { - return newCommonRegistry() +func extendAddonPlugins(_ *registry) { + // No-op }