这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 5 additions & 11 deletions internal/display/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,12 @@ func GetPluginResource(ctx context.Context, name string) (*PluginResource, error

pluginManager := plugin_manager.New()

basicInfo, err := plugin.List(ctx, config.GlobalConfig.PluginVersions, &name)
desc, err := pluginManager.Describe(ctx, name)
if err != nil {
return nil, fmt.Errorf("unable to obtain plugin list: %w", err)
}

if len(basicInfo) == 0 {
return nil, fmt.Errorf("plugin %s not found", name)
return nil, fmt.Errorf("unable to obtain plugin details: %w", err)
}

p := basicInfo[0]

desc, err := pluginManager.Describe(ctx, p.Name)
installedInfo, err := plugin.Get(ctx, config.GlobalConfig.PluginVersions, desc.Name)
if err != nil {
return nil, fmt.Errorf("unable to obtain plugin details: %w", err)
}
Expand All @@ -96,8 +90,8 @@ func GetPluginResource(ctx context.Context, name string) (*PluginResource, error
slices.Sort(tables)

pr := &PluginResource{
Name: p.Name,
Version: p.Version.String(),
Name: desc.Name,
Version: installedInfo.Version.String(),
Sources: sources,
Tables: tables,
}
Expand Down
38 changes: 33 additions & 5 deletions internal/plugin/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ func Install(ctx context.Context, plugin plugin.ResolvedPluginVersion, sub chan
return image, err
}

// PluginListItem is a struct representing an item in the list of plugins
type PluginListItem struct {
// PluginNameVersion is a struct representing an item in the list of plugins
type PluginNameVersion struct {
Name string
Version *plugin.PluginVersionString
}

// List returns all installed plugins
func List(ctx context.Context, pluginVersions map[string]*versionfile.InstalledVersion, fileNameFilter *string) ([]PluginListItem, error) {
var items []PluginListItem
func List(ctx context.Context, pluginVersions map[string]*versionfile.InstalledVersion, fileNameFilter *string) ([]PluginNameVersion, error) {
var items []PluginNameVersion
filter := "**/*.plugin"
if fileNameFilter != nil {
filter = fmt.Sprintf("**/*%s.plugin", *fileNameFilter)
Expand All @@ -82,7 +82,7 @@ func List(ctx context.Context, pluginVersions map[string]*versionfile.InstalledV
return nil, err
}
// for local plugin
item := PluginListItem{
item := PluginNameVersion{
Name: fullPluginName,
Version: plugin.LocalPluginVersionString(),
}
Expand All @@ -103,6 +103,34 @@ func List(ctx context.Context, pluginVersions map[string]*versionfile.InstalledV
return items, nil
}

// Get returns one installed plugin
func Get(_ context.Context, pluginVersions map[string]*versionfile.InstalledVersion, imageRef string) (*PluginNameVersion, error) {
pluginBinary := filepaths.PluginInstallDir(imageRef)

parent := filepath.Dir(pluginBinary)
fullPluginName, err := filepath.Rel(filepaths.EnsurePluginDir(), parent)
if err != nil {
return nil, err
}
// for local plugin
item := PluginNameVersion{
Name: fullPluginName,
Version: plugin.LocalPluginVersionString(),
}
// check if this plugin is recorded in plugin versions
installation := pluginVersions[fullPluginName]

// if not a local plugin, get the semver version
if !detectLocalPlugin(installation, pluginBinary) {
item.Version, err = plugin.NewPluginVersionString(installation.Version)
if err != nil {
return nil, fmt.Errorf("could not evaluate plugin version %s: %w", installation.Version, err)
}
}

return &item, nil
}

// detectLocalPlugin returns true if the modTime of the `pluginBinary` is after the installation date as recorded in the installation data
// this may happen when a plugin is installed from the registry, but is then compiled from source
func detectLocalPlugin(installation *versionfile.InstalledVersion, pluginBinary string) bool {
Expand Down
1 change: 1 addition & 0 deletions internal/plugin_manager/describe_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
)

type PluginDescribeResponse struct {
Name string `json:"name"`
TableSchemas schema.SchemaMap `json:"tables"`
Sources row_source.SourceMetadataMap `json:"sources"`
}
Expand Down
5 changes: 4 additions & 1 deletion internal/plugin_manager/plugin_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,11 @@ func (p *PluginManager) Describe(ctx context.Context, pluginName string) (*Plugi
return nil, fmt.Errorf("error starting describeion for plugin %s: %w", pluginClient.Name, err)
}

res := DescribeResponseFromProto(describeResponse)
res.Name = pluginDef.Plugin

// just return - the observer is responsible for waiting for completion
return DescribeResponseFromProto(describeResponse), nil
return res, nil
}

func (p *PluginManager) Close() {
Expand Down
Loading