1
0
Fork 0

Refactor plugins system

This commit is contained in:
Harold Ozouf 2025-09-16 16:16:07 +02:00 committed by GitHub
parent ffd01fc88a
commit fed86bd816
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 828 additions and 261 deletions

View file

@ -13,13 +13,13 @@ import (
const localGoPath = "./plugins-local/"
// SetupRemotePlugins setup remote plugins environment.
func SetupRemotePlugins(client *Client, plugins map[string]Descriptor) error {
func SetupRemotePlugins(manager *Manager, plugins map[string]Descriptor) error {
err := checkRemotePluginsConfiguration(plugins)
if err != nil {
return fmt.Errorf("invalid configuration: %w", err)
}
err = client.CleanArchives(plugins)
err = manager.CleanArchives(plugins)
if err != nil {
return fmt.Errorf("unable to clean archives: %w", err)
}
@ -27,35 +27,20 @@ func SetupRemotePlugins(client *Client, plugins map[string]Descriptor) error {
ctx := context.Background()
for pAlias, desc := range plugins {
log.Ctx(ctx).Debug().Msgf("Loading of plugin: %s: %s@%s", pAlias, desc.ModuleName, desc.Version)
log.Ctx(ctx).Debug().Msgf("Installing plugin: %s: %s@%s", pAlias, desc.ModuleName, desc.Version)
hash, err := client.Download(ctx, desc.ModuleName, desc.Version)
if err != nil {
_ = client.ResetAll()
return fmt.Errorf("unable to download plugin %s: %w", desc.ModuleName, err)
}
err = client.Check(ctx, desc.ModuleName, desc.Version, hash)
if err != nil {
_ = client.ResetAll()
return fmt.Errorf("unable to check archive integrity of the plugin %s: %w", desc.ModuleName, err)
if err = manager.InstallPlugin(ctx, desc); err != nil {
_ = manager.ResetAll()
return fmt.Errorf("unable to install plugin %s: %w", pAlias, err)
}
}
err = client.WriteState(plugins)
err = manager.WriteState(plugins)
if err != nil {
_ = client.ResetAll()
_ = manager.ResetAll()
return fmt.Errorf("unable to write plugins state: %w", err)
}
for _, desc := range plugins {
err = client.Unzip(desc.ModuleName, desc.Version)
if err != nil {
_ = client.ResetAll()
return fmt.Errorf("unable to unzip archive: %w", err)
}
}
return nil
}