Run executes the PluginExec action
(ctx context.Context, pluginName string, commandName string, config plugins.PluginExecConfig)
| 130 | |
| 131 | // Run executes the PluginExec action |
| 132 | func (action *PluginExec) Run(ctx context.Context, pluginName string, commandName string, config plugins.PluginExecConfig) (*PluginExecResult, error) { |
| 133 | action.cfg.Logger.Debug().Str("pluginName", pluginName).Str("command", commandName).Msg("Executing plugin command") |
| 134 | plugin, ok := action.manager.GetPlugin(pluginName) |
| 135 | if !ok { |
| 136 | return nil, fmt.Errorf("plugin '%s' not found", pluginName) |
| 137 | } |
| 138 | |
| 139 | result, err := plugin.Plugin.Exec(ctx, config) |
| 140 | if err != nil { |
| 141 | action.cfg.Logger.Error().Err(err).Str("pluginName", pluginName).Str("command", commandName).Msg("Plugin execution failed") |
| 142 | return nil, fmt.Errorf("plugin execution failed: %w", err) |
| 143 | } |
| 144 | |
| 145 | if result.Error != "" { |
| 146 | action.cfg.Logger.Error().Str("pluginName", pluginName).Str("command", commandName).Str("error", result.Error).Msg("Plugin returned error") |
| 147 | } |
| 148 | |
| 149 | action.cfg.Logger.Debug().Str("pluginName", pluginName).Str("command", commandName).Int("exitCode", result.ExitCode).Msg("Plugin command executed") |
| 150 | return &PluginExecResult{ |
| 151 | Output: result.Output, |
| 152 | Error: result.Error, |
| 153 | ExitCode: result.ExitCode, |
| 154 | }, nil |
| 155 | } |
| 156 | |
| 157 | // NewPluginInstall creates a new PluginInstall action |
| 158 | func NewPluginInstall(cfg *ActionsOpts, manager *plugins.Manager) *PluginInstall { |