LoadPlugins loads all plugins from the plugins directory.
(ctx context.Context)
| 51 | |
| 52 | // LoadPlugins loads all plugins from the plugins directory. |
| 53 | func (m *Manager) LoadPlugins(ctx context.Context) error { |
| 54 | pluginsDir := GetPluginsDir("chainloop") |
| 55 | |
| 56 | if err := os.MkdirAll(pluginsDir, 0755); err != nil { |
| 57 | return fmt.Errorf("failed to create plugins directory: %w", err) |
| 58 | } |
| 59 | |
| 60 | plugins, err := plugin.Discover("*", pluginsDir) |
| 61 | if err != nil { |
| 62 | return fmt.Errorf("failed to discover plugins: %w", err) |
| 63 | } |
| 64 | |
| 65 | for _, plugin := range plugins { |
| 66 | // Load the plugin - if there is an error just skip it - we can think of a better strategy later |
| 67 | if err := m.loadPlugin(ctx, plugin); err != nil { |
| 68 | m.logger.Error().Msgf("failed to load plugin: %s", plugin) |
| 69 | m.logger.Debug().Err(err).Msgf("plugin loading failure reason: %s", plugin) |
| 70 | continue |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | return nil |
| 75 | } |
| 76 | |
| 77 | // loadPlugin loads a single plugin. |
| 78 | func (m *Manager) loadPlugin(ctx context.Context, path string) error { |
no test coverage detected