diff --git a/builtin/README.md b/builtin/README.md index 565c3518..b2b687e0 100644 --- a/builtin/README.md +++ b/builtin/README.md @@ -9,6 +9,6 @@ in turn, can be (re-)generated by running [gen-schemes](../scripts/gen-schemes) script. > **Note**: `gen-schemes` script repeatedly invokes `gopls` and `guru` in order -> to identify plugin implementations. This means that it is very so. Because of +> to identify plugin implementations. This means that it is very slow. Because of > this, a static version of `schemes.gen.go` is currently submitted as part of > the source. diff --git a/builtin/builtin_loader.go b/builtin/builtin_loader.go index a9f41f89..2f36d2a8 100644 --- a/builtin/builtin_loader.go +++ b/builtin/builtin_loader.go @@ -112,6 +112,22 @@ func GetBuiltinHandleByNameUsing[I plugin.IPluggable](ldr *BuiltinLoader, name s return handle, nil } +func GetBuiltinLoadedAttestationSchemes[I plugin.IPluggable](ldr *BuiltinLoader) []string { + schemes := make([]string, len(ldr.loadedByName)) + + i := 0 + for _, ihandle := range ldr.loadedByName { + if _, ok := ihandle.(I); !ok { + continue + } + + schemes[i] = ihandle.GetAttestationScheme() + i += 1 + } + + return schemes +} + func GetBuiltinHandleByAttestationSchemeUsing[I plugin.IPluggable]( ldr *BuiltinLoader, scheme string, diff --git a/builtin/builtin_manager.go b/builtin/builtin_manager.go index 15ec275b..8abbd745 100644 --- a/builtin/builtin_manager.go +++ b/builtin/builtin_manager.go @@ -82,6 +82,10 @@ func (o *BuiltinManager[I]) GetRegisteredMediaTypes() []string { return registeredMediatTypes } +func (o *BuiltinManager[I]) GetRegisteredAttestationSchemes() []string { + return GetBuiltinLoadedAttestationSchemes[I](o.loader) +} + func (o *BuiltinManager[I]) LookupByName(name string) (I, error) { return GetBuiltinHandleByNameUsing[I](o.loader, name) } diff --git a/plugin/goplugin_loader.go b/plugin/goplugin_loader.go index 673dc284..d771a501 100644 --- a/plugin/goplugin_loader.go +++ b/plugin/goplugin_loader.go @@ -212,6 +212,22 @@ func GetGoPluginHandleByNameUsing[I IPluggable](ldr *GoPluginLoader, name string return plugged.Handle, nil } +func GetGoPluginLoadedAttestationSchemes[I IPluggable](ldr *GoPluginLoader) []string { + schemes := make([]string, len(ldr.loadedByName)) + + i := 0 + for _, ictx := range ldr.loadedByName { + if _, ok := ictx.(*PluginContext[I]); !ok { + continue + } + + schemes[i] = ictx.GetAttestationScheme() + i += 1 + } + + return schemes +} + func GetGoPluginHandleByAttestationSchemeUsing[I IPluggable]( ldr *GoPluginLoader, scheme string, diff --git a/plugin/goplugin_manager.go b/plugin/goplugin_manager.go index be341761..5cf259e1 100644 --- a/plugin/goplugin_manager.go +++ b/plugin/goplugin_manager.go @@ -94,6 +94,10 @@ func (o *GoPluginManager[I]) GetRegisteredMediaTypes() []string { return registeredMediatTypes } +func (o *GoPluginManager[I]) GetRegisteredAttestationSchemes() []string { + return GetGoPluginLoadedAttestationSchemes[I](o.loader) +} + func (o *GoPluginManager[I]) LookupByName(name string) (I, error) { return GetGoPluginHandleByNameUsing[I](o.loader, name) } diff --git a/plugin/imanager.go b/plugin/imanager.go index 70ebb16c..940cb06c 100644 --- a/plugin/imanager.go +++ b/plugin/imanager.go @@ -15,17 +15,22 @@ type IManager[I IPluggable] interface { Close() error // IsRegisteredMediaType returns true iff the provided mediaType has - // been regesitred with thet manager as hanedled by one of the + // been registered with the manager as handled by one of the // discovered plugins. IsRegisteredMediaType(mediaType string) bool // GetRegisteredMediaTypes returns a []string of media types that have - // been registered with the manger by discovered plugins. + // been registered with the manager by discovered plugins. GetRegisteredMediaTypes() []string + // GetRegisteredAttestationSchemes returns a []string of names for + // schemes that have been registered with the manager by discovered + // plugins. + GetRegisteredAttestationSchemes() []string + // LookupByMediaType returns a handle (implementation of the managed // interface) to the plugin that handles the specified mediaType. If - // the mediaType is not handled by any of the registred plugins, an + // the mediaType is not handled by any of the registered plugins, an // error is returned. LookupByMediaType(mediaType string) (I, error) diff --git a/provisioning/api/mocks/imanager.go b/provisioning/api/mocks/imanager.go index 587ebed0..ce7d55a6 100644 --- a/provisioning/api/mocks/imanager.go +++ b/provisioning/api/mocks/imanager.go @@ -48,6 +48,20 @@ func (mr *MockIManagerMockRecorder[I]) Close() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Close", reflect.TypeOf((*MockIManager[I])(nil).Close)) } +// GetRegisteredAttestationSchemes mocks base method. +func (m *MockIManager[I]) GetRegisteredAttestationSchemes() []string { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetRegisteredAttestationSchemes") + ret0, _ := ret[0].([]string) + return ret0 +} + +// GetRegisteredAttestationSchemes indicates an expected call of GetRegisteredAttestationSchemes. +func (mr *MockIManagerMockRecorder[I]) GetRegisteredAttestationSchemes() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetRegisteredAttestationSchemes", reflect.TypeOf((*MockIManager[I])(nil).GetRegisteredAttestationSchemes)) +} + // GetRegisteredMediaTypes mocks base method. func (m *MockIManager[I]) GetRegisteredMediaTypes() []string { m.ctrl.T.Helper()