Skip to content

Commit

Permalink
restructure to follow entAddExtPlugins() go build tag usage pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
thyton committed Jun 10, 2024
1 parent b66d3e0 commit 9405cc7
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 21 deletions.
17 changes: 8 additions & 9 deletions helper/builtinplugins/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -54,8 +53,8 @@ func removedFactory(ctx context.Context, config *logical.BackendConfig) (logical
return removedBackend, nil
}

func newCommonRegistry() *registry {
reg := &registry{
func newMinimalRegistry() *registry {
return &registry{
credentialBackends: map[string]credentialBackend{
"approle": {Factory: credAppRole.Factory},
"cert": {Factory: credCert.Factory},
Expand All @@ -71,6 +70,12 @@ func newCommonRegistry() *registry {
"transit": {Factory: logicalTransit.Factory},
},
}
}

func newRegistry() *registry {
reg := newMinimalRegistry()

extendAddonPlugins(reg)

entAddExtPlugins(reg)

Expand Down Expand Up @@ -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
Expand Down
12 changes: 7 additions & 5 deletions helper/builtinplugins/registry_full.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
10 changes: 5 additions & 5 deletions helper/builtinplugins/registry_full_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ import (

func Test_newRegistry(t *testing.T) {

Check failure on line 12 in helper/builtinplugins/registry_full_test.go

View workflow job for this annotation

GitHub Actions / Code checks

Test Test_newRegistry is missing a go doc
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")
}

Expand Down
4 changes: 2 additions & 2 deletions helper/builtinplugins/registry_min.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@

package builtinplugins

func newRegistry() *registry {
return newCommonRegistry()
func extendAddonPlugins(_ *registry) {
// No-op
}

0 comments on commit 9405cc7

Please sign in to comment.