Documentation
¶
Overview ¶
Package componentversionrepository implements a plugin-based system for managing OCM component version repositories. It provides a registry that supports both internal (Go-based) and external (binary) plugins through a unified interface.
The system implements CRUD operations for component versions, local resources, and sources with credential management and type-safe plugin registration. External plugins communicate via UDS or TCP with JSON schema validation if defined.
Register internal plugins using RegisterInternalComponentVersionRepositoryPlugin:
scheme := runtime.NewScheme() repository.MustAddToScheme(scheme) if err := componentversionrepository.RegisterInternalComponentVersionRepositoryPlugin( scheme, registry, &Plugin{scheme: scheme, memory: inmemory.New()}, &v1.OCIRepository{}, ); err != nil { panic(err) }
Functionality:
- Component version lifecycle management (add, get, list)
- Local resource and source storage with blob handling
- Plugin discovery and credential consumer identity resolution
- External plugin communication with automatic lifecycle management
- Type conversion between internal runtime types and plugin contract types
Architecture components:
- Registry: Plugin registration, lifecycle management, and thread-safe access
- Handlers: HTTP request/response processing with authentication and validation
- Converters: Data transformation between internal and external plugin formats
- Contracts: Type-safe interfaces defining plugin capabilities
Index ¶
- Constants
- func AddComponentVersionHandlerFunc[T runtime.Typed](f func(ctx context.Context, r v1.PostComponentVersionRequest[T], ...) error) http.HandlerFunc
- func AddLocalResourceHandlerFunc[T runtime.Typed](...) http.HandlerFunc
- func AddLocalSourceHandlerFunc[T runtime.Typed](...) http.HandlerFunc
- func GetComponentVersionHandlerFunc[T runtime.Typed](...) http.HandlerFunc
- func GetIdentityHandlerFunc[T runtime.Typed](...) http.HandlerFunc
- func GetLocalResourceHandlerFunc[T runtime.Typed](...) http.HandlerFunc
- func GetLocalSourceHandlerFunc[T runtime.Typed](...) http.HandlerFunc
- func ListComponentVersionsHandlerFunc[T runtime.Typed](...) http.HandlerFunc
- func RegisterComponentVersionRepository[T runtime.Typed](proto T, handler v1.ReadWriteOCMRepositoryPluginContract[T], ...) error
- func RegisterInternalComponentVersionRepositoryPlugin[T runtime.Typed](scheme *runtime.Scheme, r *RepositoryRegistry, ...) error
- type RepositoryPlugin
- func (r *RepositoryPlugin) AddComponentVersion(ctx context.Context, request v1.PostComponentVersionRequest[runtime.Typed], ...) error
- func (r *RepositoryPlugin) AddLocalResource(ctx context.Context, request v1.PostLocalResourceRequest[runtime.Typed], ...) (*descriptor.Resource, error)
- func (r *RepositoryPlugin) AddLocalSource(ctx context.Context, request v1.PostLocalSourceRequest[runtime.Typed], ...) (*descriptor.Source, error)
- func (r *RepositoryPlugin) CheckHealth(ctx context.Context, request v1.PostCheckHealthRequest[runtime.Typed], ...) error
- func (r *RepositoryPlugin) GetComponentVersion(ctx context.Context, request v1.GetComponentVersionRequest[runtime.Typed], ...) (*descriptor.Descriptor, error)
- func (r *RepositoryPlugin) GetIdentity(ctx context.Context, request *v1.GetIdentityRequest[runtime.Typed]) (*v1.GetIdentityResponse, error)
- func (r *RepositoryPlugin) GetLocalResource(ctx context.Context, request v1.GetLocalResourceRequest[runtime.Typed], ...) (v1.GetLocalResourceResponse, error)
- func (r *RepositoryPlugin) GetLocalSource(ctx context.Context, request v1.GetLocalSourceRequest[runtime.Typed], ...) (v1.GetLocalSourceResponse, error)
- func (r *RepositoryPlugin) ListComponentVersions(ctx context.Context, request v1.ListComponentVersionsRequest[runtime.Typed], ...) ([]string, error)
- func (r *RepositoryPlugin) Ping(ctx context.Context) error
- type RepositoryRegistry
- type TypeToUntypedPlugin
- func (r *TypeToUntypedPlugin[T]) AddComponentVersion(ctx context.Context, request v1.PostComponentVersionRequest[runtime.Typed], ...) error
- func (r *TypeToUntypedPlugin[T]) AddLocalResource(ctx context.Context, request v1.PostLocalResourceRequest[runtime.Typed], ...) (*descriptor.Resource, error)
- func (r *TypeToUntypedPlugin[T]) AddLocalSource(ctx context.Context, request v1.PostLocalSourceRequest[runtime.Typed], ...) (*descriptor.Source, error)
- func (r *TypeToUntypedPlugin[T]) CheckHealth(ctx context.Context, request v1.PostCheckHealthRequest[T], ...) error
- func (r *TypeToUntypedPlugin[T]) GetComponentVersion(ctx context.Context, request v1.GetComponentVersionRequest[runtime.Typed], ...) (*descriptor.Descriptor, error)
- func (r *TypeToUntypedPlugin[T]) GetIdentity(ctx context.Context, typ *v1.GetIdentityRequest[runtime.Typed]) (*v1.GetIdentityResponse, error)
- func (r *TypeToUntypedPlugin[T]) GetLocalResource(ctx context.Context, request v1.GetLocalResourceRequest[runtime.Typed], ...) (v1.GetLocalResourceResponse, error)
- func (r *TypeToUntypedPlugin[T]) GetLocalSource(ctx context.Context, request v1.GetLocalSourceRequest[runtime.Typed], ...) (v1.GetLocalSourceResponse, error)
- func (r *TypeToUntypedPlugin[T]) ListComponentVersions(ctx context.Context, request v1.ListComponentVersionsRequest[runtime.Typed], ...) ([]string, error)
- func (r *TypeToUntypedPlugin[T]) Ping(ctx context.Context) error
Constants ¶
const ( // UploadLocalResource defines the endpoint to upload a local resource to. UploadLocalResource = "/local-resource/upload" // DownloadLocalResource defines the endpoint to download a local resource. DownloadLocalResource = "/local-resource/download" // UploadLocalSource defines the endpoint to upload a local source to. UploadLocalSource = "/local-source/upload" // DownloadLocalSource defines the endpoint to download a local source. DownloadLocalSource = "/local-source/download" // UploadComponentVersion defines the endpoint to upload component versions to. UploadComponentVersion = "/component-version/upload" // DownloadComponentVersion defines the endpoint to download component versions. DownloadComponentVersion = "/component-version/download" // ListComponentVersions defines the endpoint to list component versions. ListComponentVersions = "/component-versions" // Identity defines the endpoint to retrieve credential consumer identity. Identity = "/identity" // CheckHealth defines the endpoint to check the health of a component version repository. CheckHealth = "/component-version/check-health" )
Endpoints
Variables ¶
This section is empty.
Functions ¶
func AddComponentVersionHandlerFunc ¶
func AddComponentVersionHandlerFunc[T runtime.Typed](f func(ctx context.Context, r v1.PostComponentVersionRequest[T], credentials map[string]string) error) http.HandlerFunc
AddComponentVersionHandlerFunc creates an HTTP handler for adding component versions. It handles authentication and request body parsing for the plugin implementation.
func AddLocalResourceHandlerFunc ¶
func AddLocalResourceHandlerFunc[T runtime.Typed](f func(ctx context.Context, request v1.PostLocalResourceRequest[T], credentials map[string]string) (*descriptor.Resource, error), scheme *runtime.Scheme) http.HandlerFunc
AddLocalResourceHandlerFunc creates an HTTP handler for adding local resources. It handles authentication, request body parsing, and resource conversion for the plugin implementation.
func AddLocalSourceHandlerFunc ¶
func AddLocalSourceHandlerFunc[T runtime.Typed](f func(ctx context.Context, request v1.PostLocalSourceRequest[T], credentials map[string]string) (*descriptor.Source, error), scheme *runtime.Scheme) http.HandlerFunc
AddLocalSourceHandlerFunc creates an HTTP handler for adding local sources. It handles authentication, request body parsing, and source conversion for the plugin implementation.
func GetComponentVersionHandlerFunc ¶
func GetComponentVersionHandlerFunc[T runtime.Typed](f func(ctx context.Context, request v1.GetComponentVersionRequest[T], credentials map[string]string) (*descriptor.Descriptor, error), scheme *runtime.Scheme, typ T) http.HandlerFunc
GetComponentVersionHandlerFunc is a wrapper around calling the interface method GetComponentVersion for the plugin. This is a convenience wrapper containing header and query parameter parsing logic that is not important to know for the plugin implementor.
func GetIdentityHandlerFunc ¶
func GetIdentityHandlerFunc[T runtime.Typed](f func(ctx context.Context, typ *v1.GetIdentityRequest[T]) (*v1.GetIdentityResponse, error), scheme *runtime.Scheme, proto T) http.HandlerFunc
GetIdentityHandlerFunc creates an HTTP handler for retrieving identity information. It handles request processing and response encoding for the plugin implementation.
func GetLocalResourceHandlerFunc ¶
func GetLocalResourceHandlerFunc[T runtime.Typed](f func(ctx context.Context, request v1.GetLocalResourceRequest[T], credentials map[string]string) (v1.GetLocalResourceResponse, error), scheme *runtime.Scheme, proto T) http.HandlerFunc
GetLocalResourceHandlerFunc creates an HTTP handler for retrieving local resources. It handles authentication, query parameter parsing, and response encoding for the plugin implementation.
func GetLocalSourceHandlerFunc ¶
func GetLocalSourceHandlerFunc[T runtime.Typed](f func(ctx context.Context, request v1.GetLocalSourceRequest[T], credentials map[string]string) (v1.GetLocalSourceResponse, error), scheme *runtime.Scheme, proto T) http.HandlerFunc
GetLocalSourceHandlerFunc creates an HTTP handler for retrieving local sources. It handles authentication, query parameter parsing, and response encoding for the plugin implementation.
func ListComponentVersionsHandlerFunc ¶
func ListComponentVersionsHandlerFunc[T runtime.Typed](f func(ctx context.Context, request v1.ListComponentVersionsRequest[T], credentials map[string]string) ([]string, error), scheme *runtime.Scheme, typ T) http.HandlerFunc
ListComponentVersionsHandlerFunc is a wrapper around calling the interface method ListComponentVersions for the plugin. This is a convenience wrapper containing header and query parameter parsing logic that is not important to know for the plugin implementor.
func RegisterComponentVersionRepository ¶
func RegisterComponentVersionRepository[T runtime.Typed]( proto T, handler v1.ReadWriteOCMRepositoryPluginContract[T], c *endpoints.EndpointBuilder, ) error
RegisterComponentVersionRepository takes a builder and a handler and based on the handler's contract type will construct a list of endpoint handlers that they will need. Once completed, MarshalJSON can be used to construct the supported endpoint list to give back to the plugin manager. This information is stored about the plugin and then used for later lookup. The type is also saved with the endpoint, meaning during lookup the right endpoint + type is used.
func RegisterInternalComponentVersionRepositoryPlugin ¶
func RegisterInternalComponentVersionRepositoryPlugin[T runtime.Typed]( scheme *runtime.Scheme, r *RepositoryRegistry, p repository.ComponentVersionRepositoryProvider, prototype T, ) error
RegisterInternalComponentVersionRepositoryPlugin can be called by actual implementations in the source. It will register any implementations directly for a given type and capability.
Types ¶
type RepositoryPlugin ¶
type RepositoryPlugin struct { ID string // contains filtered or unexported fields }
RepositoryPlugin implements the ReadWriteOCMRepositoryPluginContract for external plugin communication. It handles REST-based communication with external repository plugins, including request validation, credential management, and data format conversion.
func NewComponentVersionRepositoryPlugin ¶
func NewComponentVersionRepositoryPlugin(client *http.Client, id string, path string, config types.Config, loc string, jsonSchema []byte) *RepositoryPlugin
NewComponentVersionRepositoryPlugin creates a new component version repository plugin instance with the provided configuration. It initializes the plugin with an HTTP client, unique ID, path, configuration, location, and JSON schema.
func (*RepositoryPlugin) AddComponentVersion ¶
func (r *RepositoryPlugin) AddComponentVersion(ctx context.Context, request v1.PostComponentVersionRequest[runtime.Typed], credentials map[string]string) error
func (*RepositoryPlugin) AddLocalResource ¶
func (r *RepositoryPlugin) AddLocalResource(ctx context.Context, request v1.PostLocalResourceRequest[runtime.Typed], credentials map[string]string) (*descriptor.Resource, error)
func (*RepositoryPlugin) AddLocalSource ¶
func (r *RepositoryPlugin) AddLocalSource(ctx context.Context, request v1.PostLocalSourceRequest[runtime.Typed], credentials map[string]string) (*descriptor.Source, error)
func (*RepositoryPlugin) CheckHealth ¶
func (r *RepositoryPlugin) CheckHealth(ctx context.Context, request v1.PostCheckHealthRequest[runtime.Typed], credentials map[string]string) error
func (*RepositoryPlugin) GetComponentVersion ¶
func (r *RepositoryPlugin) GetComponentVersion(ctx context.Context, request v1.GetComponentVersionRequest[runtime.Typed], credentials map[string]string) (*descriptor.Descriptor, error)
func (*RepositoryPlugin) GetIdentity ¶
func (r *RepositoryPlugin) GetIdentity(ctx context.Context, request *v1.GetIdentityRequest[runtime.Typed]) (*v1.GetIdentityResponse, error)
func (*RepositoryPlugin) GetLocalResource ¶
func (r *RepositoryPlugin) GetLocalResource(ctx context.Context, request v1.GetLocalResourceRequest[runtime.Typed], credentials map[string]string) (v1.GetLocalResourceResponse, error)
func (*RepositoryPlugin) GetLocalSource ¶
func (r *RepositoryPlugin) GetLocalSource(ctx context.Context, request v1.GetLocalSourceRequest[runtime.Typed], credentials map[string]string) (v1.GetLocalSourceResponse, error)
func (*RepositoryPlugin) ListComponentVersions ¶
type RepositoryRegistry ¶
type RepositoryRegistry struct {
// contains filtered or unexported fields
}
RepositoryRegistry holds all plugins that implement capabilities corresponding to RepositoryPlugin operations.
func NewComponentVersionRepositoryRegistry ¶
func NewComponentVersionRepositoryRegistry(ctx context.Context) *RepositoryRegistry
NewComponentVersionRepositoryRegistry creates a new registry and initializes maps.
func (*RepositoryRegistry) AddPlugin ¶
AddPlugin takes a plugin discovered by the manager and adds it to the stored plugin registry. This function will return an error if the given capability + type already has a registered plugin. Multiple plugins for the same cap+typ is not allowed.
func (*RepositoryRegistry) GetPlugin ¶
func (r *RepositoryRegistry) GetPlugin(ctx context.Context, spec runtime.Typed) (repository.ComponentVersionRepositoryProvider, error)
GetPlugin retrieves a plugin for the given specification type. It first checks for internal plugins registered via RegisterInternalComponentVersionRepositoryPlugin, then falls back to external plugins if no internal plugin is found.
func (*RepositoryRegistry) Shutdown ¶
func (r *RepositoryRegistry) Shutdown(ctx context.Context) error
Shutdown will loop through all _STARTED_ plugins and will send an Interrupt signal to them. All plugins should handle interrupt signals gracefully. For Go, this is done automatically by the plugin SDK.
type TypeToUntypedPlugin ¶
TypeToUntypedPlugin is a wrapper that converts typed plugin contracts to untyped runtime.Typed contracts. It allows typed plugins to be used with the untyped plugin registry system by performing type assertions and delegating calls to the underlying typed plugin implementation.
func (*TypeToUntypedPlugin[T]) AddComponentVersion ¶
func (r *TypeToUntypedPlugin[T]) AddComponentVersion(ctx context.Context, request v1.PostComponentVersionRequest[runtime.Typed], credentials map[string]string) error
func (*TypeToUntypedPlugin[T]) AddLocalResource ¶
func (r *TypeToUntypedPlugin[T]) AddLocalResource(ctx context.Context, request v1.PostLocalResourceRequest[runtime.Typed], credentials map[string]string) (*descriptor.Resource, error)
func (*TypeToUntypedPlugin[T]) AddLocalSource ¶
func (r *TypeToUntypedPlugin[T]) AddLocalSource(ctx context.Context, request v1.PostLocalSourceRequest[runtime.Typed], credentials map[string]string) (*descriptor.Source, error)
func (*TypeToUntypedPlugin[T]) CheckHealth ¶
func (r *TypeToUntypedPlugin[T]) CheckHealth(ctx context.Context, request v1.PostCheckHealthRequest[T], credentials map[string]string) error
func (*TypeToUntypedPlugin[T]) GetComponentVersion ¶
func (r *TypeToUntypedPlugin[T]) GetComponentVersion(ctx context.Context, request v1.GetComponentVersionRequest[runtime.Typed], credentials map[string]string) (*descriptor.Descriptor, error)
func (*TypeToUntypedPlugin[T]) GetIdentity ¶
func (r *TypeToUntypedPlugin[T]) GetIdentity(ctx context.Context, typ *v1.GetIdentityRequest[runtime.Typed]) (*v1.GetIdentityResponse, error)
func (*TypeToUntypedPlugin[T]) GetLocalResource ¶
func (r *TypeToUntypedPlugin[T]) GetLocalResource(ctx context.Context, request v1.GetLocalResourceRequest[runtime.Typed], credentials map[string]string) (v1.GetLocalResourceResponse, error)
func (*TypeToUntypedPlugin[T]) GetLocalSource ¶
func (r *TypeToUntypedPlugin[T]) GetLocalSource(ctx context.Context, request v1.GetLocalSourceRequest[runtime.Typed], credentials map[string]string) (v1.GetLocalSourceResponse, error)