Skip to content
This repository has been archived by the owner on Dec 26, 2024. It is now read-only.

Commit

Permalink
feat(autobrr): support basic auth (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
zze0s authored Jan 9, 2023
1 parent ddff1d0 commit c26f6be
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 8 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,17 @@ If you're trying to reach radarr or sonarr hosted on swizzin from some other loc
- 15
```
Same goes for autobrr if it's behind basic auth.
```yaml
autobrr:
host: http://localhost:7474
apikey: YOUR_API_KEY
basicAuth:
user: username
pass: password
```
### Tags
This works for both sonarr and radarr.
Expand Down
7 changes: 4 additions & 3 deletions internal/processor/radarr.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/autobrr/omegabrr/internal/domain"
"github.com/autobrr/omegabrr/pkg/autobrr"

"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"golift.io/starr"
Expand All @@ -18,14 +19,14 @@ func (s Service) radarr(ctx context.Context, cfg *domain.ArrConfig, dryRun bool,

l.Debug().Msgf("gathering titles...")

movieTitles, err := s.processRadarr(ctx, cfg, &l)
titles, err := s.processRadarr(ctx, cfg, &l)
if err != nil {
return err
}

l.Debug().Msgf("got %v filter titles", len(movieTitles))
l.Debug().Msgf("got %v filter titles", len(titles))

joinedTitles := strings.Join(movieTitles, ",")
joinedTitles := strings.Join(titles, ",")

l.Trace().Msgf("%v", joinedTitles)

Expand Down
7 changes: 7 additions & 0 deletions internal/processor/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ func (s Service) Process(dryRun bool) error {
}

a := autobrr.NewClient(s.cfg.Clients.Autobrr.Host, s.cfg.Clients.Autobrr.Apikey)
if s.cfg.Clients.Autobrr.BasicAuth != nil {
a.SetBasicAuth(s.cfg.Clients.Autobrr.BasicAuth.User, s.cfg.Clients.Autobrr.BasicAuth.Pass)
}

log.Debug().Msgf("starting filter processing...")

Expand Down Expand Up @@ -72,6 +75,10 @@ func (s Service) GetFilters(ctx context.Context) ([]autobrr.Filter, error) {
}

a := autobrr.NewClient(s.cfg.Clients.Autobrr.Host, s.cfg.Clients.Autobrr.Apikey)
if s.cfg.Clients.Autobrr.BasicAuth != nil {
a.SetBasicAuth(s.cfg.Clients.Autobrr.BasicAuth.User, s.cfg.Clients.Autobrr.BasicAuth.Pass)
}

filters, err := a.GetFilters(ctx)
if err != nil {
return nil, err
Expand Down
9 changes: 5 additions & 4 deletions internal/processor/sonarr.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/autobrr/omegabrr/internal/domain"
"github.com/autobrr/omegabrr/pkg/autobrr"

"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"golift.io/starr"
Expand All @@ -18,14 +19,14 @@ func (s Service) sonarr(ctx context.Context, cfg *domain.ArrConfig, dryRun bool,

l.Debug().Msgf("gathering titles...")

movieTitles, err := s.processSonarr(ctx, cfg, &l)
titles, err := s.processSonarr(ctx, cfg, &l)
if err != nil {
return err
}

l.Debug().Msgf("got %v filter titles", len(movieTitles))
l.Debug().Msgf("got %v filter titles", len(titles))

joinedTitles := strings.Join(movieTitles, ",")
joinedTitles := strings.Join(titles, ",")

l.Trace().Msgf("%v", joinedTitles)

Expand All @@ -41,7 +42,7 @@ func (s Service) sonarr(ctx context.Context, cfg *domain.ArrConfig, dryRun bool,
f := autobrr.UpdateFilter{MatchReleases: joinedTitles}

if err := brr.UpdateFilterByID(ctx, filterID, f); err != nil {
l.Error().Err(err).Msgf("something went wrong updating movie filter: %v", filterID)
l.Error().Err(err).Msgf("something went wrong updating tv filter: %v", filterID)
continue
}
}
Expand Down
17 changes: 16 additions & 1 deletion pkg/autobrr/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,24 @@ import (
"context"
"crypto/tls"
"encoding/json"
"github.com/rs/zerolog/log"
"io"
"net/http"
"net/http/httputil"
"strconv"
"time"

"github.com/rs/zerolog/log"

"github.com/pkg/errors"
)

type Client struct {
Host string
APIKey string

BasicUser string
BasicPass string

client *http.Client
}

Expand All @@ -44,6 +48,15 @@ func NewClient(host string, apikey string) *Client {
return c
}

func (c *Client) SetBasicAuth(user, pass string) {
if user != "" {
c.BasicUser = user
}
if pass != "" {
c.BasicPass = pass
}
}

func (c *Client) baseClient() {

}
Expand All @@ -61,6 +74,7 @@ func (c *Client) GetFilters(ctx context.Context) ([]Filter, error) {
return nil, err
}

req.SetBasicAuth(c.BasicUser, c.BasicPass)
req.Header.Add("X-API-Token", c.APIKey)

res, err := c.client.Do(req)
Expand Down Expand Up @@ -99,6 +113,7 @@ func (c *Client) UpdateFilterByID(ctx context.Context, filterID int, filter Upda
return err
}

req.SetBasicAuth(c.BasicUser, c.BasicPass)
req.Header.Add("X-API-Token", c.APIKey)

res, err := c.client.Do(req)
Expand Down

0 comments on commit c26f6be

Please sign in to comment.