in pkg/client/sonar/sonar.go [187:232]
func (sc Client) InstallPlugins(plugins []string) error {
installedPlugins, err := sc.GetInstalledPlugins()
if err != nil {
return fmt.Errorf("failed to get list of installed plugins: %w", err)
}
log.Info("List of installed plugins", "plugins", installedPlugins)
needReboot := false
for _, plugin := range plugins {
if helper.CheckPluginInstalled(installedPlugins, plugin) {
continue
}
needReboot = true
resp, errPost := sc.resty.R().
SetBody(fmt.Sprintf("key=%s", plugin)).
SetHeader(contentTypeField, "application/x-www-form-urlencoded").
Post("/plugins/install")
if errPost != nil {
return fmt.Errorf("failed to send plugin installation request for %s: %w", plugin, errPost)
}
if resp.IsError() {
return fmt.Errorf("failed to install plugin %s, response: %s", plugin, resp.Status())
}
log.Info(fmt.Sprintf("Plugin %s has been installed", plugin))
}
if needReboot {
if err = sc.Reboot(); err != nil {
return err
}
if err = sc.WaitForStatusIsUp(retryCount, timeOut*time.Second); err != nil {
return err
}
}
log.Info("Plugins have been installed")
return nil
}