feat(clients): add whisparr (#218)

* feat(clients): add whisparr

* feat: add client connection test
This commit is contained in:
Ludvig Lundgren 2022-04-06 10:40:44 +02:00 committed by GitHub
parent 2f358473f3
commit 9d0ab6ea52
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 338 additions and 3 deletions

View file

@ -1,6 +1,8 @@
package download_client
import (
"github.com/autobrr/autobrr/pkg/whisparr"
"github.com/pkg/errors"
"time"
"github.com/autobrr/autobrr/internal/domain"
@ -29,9 +31,12 @@ func (s *service) testConnection(client domain.DownloadClient) error {
case domain.DownloadClientTypeLidarr:
return s.testLidarrConnection(client)
}
return nil
case domain.DownloadClientTypeWhisparr:
return s.testWhisparrConnection(client)
default:
return errors.New("unsupported client")
}
}
func (s *service) testQbittorrentConnection(client domain.DownloadClient) error {
@ -159,3 +164,23 @@ func (s *service) testLidarrConnection(client domain.DownloadClient) error {
return nil
}
func (s *service) testWhisparrConnection(client domain.DownloadClient) error {
r := whisparr.New(whisparr.Config{
Hostname: client.Host,
APIKey: client.Settings.APIKey,
BasicAuth: client.Settings.Basic.Auth,
Username: client.Settings.Basic.Username,
Password: client.Settings.Basic.Password,
})
_, err := r.Test()
if err != nil {
log.Error().Err(err).Msgf("whisparr: connection test failed: %v", client.Host)
return err
}
log.Debug().Msgf("test client connection for whisparr: success")
return nil
}