Skip to content

Commit

Permalink
plugin: add IManager.GetRegisteredAttestationSchemes
Browse files Browse the repository at this point in the history
Add a method to retrieve the names of attestation schemes implemented by
registered plugins.

Signed-off-by: Sergei Trofimov <[email protected]>
  • Loading branch information
setrofim committed Jul 19, 2023
1 parent 704fd40 commit 27f3f3d
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 4 deletions.
2 changes: 1 addition & 1 deletion builtin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
16 changes: 16 additions & 0 deletions builtin/builtin_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions builtin/builtin_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
16 changes: 16 additions & 0 deletions plugin/goplugin_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions plugin/goplugin_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
11 changes: 8 additions & 3 deletions plugin/imanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
14 changes: 14 additions & 0 deletions provisioning/api/mocks/imanager.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 27f3f3d

Please sign in to comment.