You've already forked tarr
fix: be compliant with golanci linter
All checks were successful
All checks were successful
This commit is contained in:
@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
@ -26,7 +27,9 @@ autharr /etc/lidarr/config.xml`,
|
||||
}
|
||||
rootCmd.Flags().Bool("watch", false, "Listens for changes to the configuration and writes the token continuously to the output")
|
||||
|
||||
rootCmd.Execute()
|
||||
if err := rootCmd.Execute(); err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
}
|
||||
|
||||
func runE(cmd *cobra.Command, args []string) error {
|
||||
@ -84,10 +87,16 @@ func runWatch(cmd *cobra.Command, args []string) error {
|
||||
select {
|
||||
case <-cmd.Context().Done():
|
||||
return nil
|
||||
case err := <-errorChannel:
|
||||
logrus.WithError(err).Errorln("Received from config watcher")
|
||||
case err, open := <-errorChannel:
|
||||
if !open {
|
||||
return fmt.Errorf("error channel has been closed")
|
||||
}
|
||||
logrus.WithError(err).Errorln("received from config watcher")
|
||||
case <-timer.C:
|
||||
writeConfig(cachedConfig, dest)
|
||||
err = writeConfig(cachedConfig, dest)
|
||||
if err != nil {
|
||||
logrus.WithError(err).Errorln("failed to write config")
|
||||
}
|
||||
case config := <-configChannel:
|
||||
cachedConfig = config
|
||||
timer.Reset(waitFor)
|
||||
@ -105,18 +114,23 @@ func writeConfig(config *domain.Config, dest string) error {
|
||||
case len(dest) > 0:
|
||||
dirname := filepath.Dir(dest)
|
||||
|
||||
// #nosec G301
|
||||
err := os.MkdirAll(dirname, 0755)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// #nosec G304
|
||||
f, err := os.Create(dest)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer func() { _ = f.Close() }()
|
||||
|
||||
f.WriteString(config.API.Token)
|
||||
_, err = f.WriteString(config.API.Token)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -3,6 +3,7 @@ package main
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"git.cryptic.systems/volker.raschek/tarr/pkg/config"
|
||||
@ -95,7 +96,10 @@ healarr sonarr https://sonarr.example.com:8443 --api-token my-token`,
|
||||
rootCmd.PersistentFlags().Bool("insecure", false, "Trust insecure TLS certificates")
|
||||
rootCmd.PersistentFlags().Duration("timeout", time.Minute, "Timeout")
|
||||
|
||||
rootCmd.Execute()
|
||||
err := rootCmd.Execute()
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
}
|
||||
|
||||
func runBazarrE(cmd *cobra.Command, args []string) error {
|
||||
@ -152,7 +156,7 @@ func runE(cmd *cobra.Command, args []string, queryKey string) error {
|
||||
|
||||
switch {
|
||||
case len(apiToken) <= 0 && len(configPath) <= 0:
|
||||
return fmt.Errorf("At least --api-token oder --config must be defined")
|
||||
return fmt.Errorf("at least --api-token oder --config must be defined")
|
||||
case len(apiToken) > 0 && len(configPath) <= 0:
|
||||
err = health.NewReadinessProbe(args[0]).
|
||||
QueryAdd(queryKey, apiToken).
|
||||
@ -175,7 +179,7 @@ func runE(cmd *cobra.Command, args []string, queryKey string) error {
|
||||
return err
|
||||
}
|
||||
default:
|
||||
return fmt.Errorf("Neither --api-token nor --config can be used at the same time.")
|
||||
return fmt.Errorf("neither --api-token nor --config can be used at the same time")
|
||||
}
|
||||
|
||||
return nil
|
||||
|
Reference in New Issue
Block a user