Skip to content

Commit

Permalink
feat: show password (#100)
Browse files Browse the repository at this point in the history
* feat: show password

* feat: explain error

* chore: update dependencies
  • Loading branch information
martabal authored Dec 30, 2024
1 parent bdbf77b commit 912ebb3
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ Docker compressed size is ~10 MB.
| `-e ENABLE_LABEL_WITH_HASH` | **[EXPERIMENTAL]** add the torrent hash to the `qbittorrent_torrent_*` metrics label | `false` |
| `-e EXPORTER_URL` | the URL shown in the logs when starting the exporter | `` |
| `-e EXPORTER_PATH` | the path where the metrics are exposed | `/metrics` |
| `-e DANGEROUS_SHOW_PASSWORD` | show the qBittorrent password in the logs when starting the exporter | `false` |

### Arguments

Expand Down
8 changes: 8 additions & 0 deletions src/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ type ExperimentalFeatures struct {
type Features struct {
EnableHighCardinality bool
EnableTracker bool
ShowPassword bool
}

func LoadEnv() {
Expand Down Expand Up @@ -76,6 +77,7 @@ func LoadEnv() {
labelWithHash := getEnv(defaultLabelWithHash)
exporterUrl := getEnv(defaultExporterURL)
exporterPath := getEnv(defaultExporterPath)
showPassword := getEnv(defaultExporterShowPassword)

exporterPort, errExporterPort := strconv.Atoi(exporterPortEnv)
if errExporterPort != nil {
Expand Down Expand Up @@ -114,6 +116,7 @@ func LoadEnv() {
Feature: Features{
EnableHighCardinality: envSetToTrue(enableHighCardinality),
EnableTracker: envSetToTrue(enableTracker),
ShowPassword: envSetToTrue(showPassword),
},
ExperimentalFeature: ExperimentalFeatures{
EnableLabelWithHash: envSetToTrue(labelWithHash),
Expand Down Expand Up @@ -152,6 +155,11 @@ func GetFeaturesEnabled() string {
features += "Trackers"
}

if Exporter.Feature.ShowPassword {
addComma()
features += "Show password"
}

if Exporter.ExperimentalFeature.EnableLabelWithHash {
addComma()
features += "Label with hash (experimental)"
Expand Down
6 changes: 6 additions & 0 deletions src/app/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ var defaultExporterPath = Env{
Help: "",
}

var defaultExporterShowPassword = Env{
Key: "DANGEROUS_SHOW_PASSWORD",
DefaultValue: "false",
Help: "",
}

func getEnv(env Env) string {
value, ok := os.LookupEnv(env.Key)
if !ok || value == "" {
Expand Down
2 changes: 1 addition & 1 deletion src/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ require (
github.com/prometheus/common v0.61.0 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
golang.org/x/sys v0.28.0 // indirect
google.golang.org/protobuf v1.36.0 // indirect
google.golang.org/protobuf v1.36.1 // indirect
)
4 changes: 2 additions & 2 deletions src/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOf
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
google.golang.org/protobuf v1.36.0 h1:mjIs9gYtt56AzC4ZaffQuh88TZurBGhIJMBZGSxNerQ=
google.golang.org/protobuf v1.36.0/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
google.golang.org/protobuf v1.36.1 h1:yBPeRvTftaleIgM3PZ/WBIZ7XM/eEYAaEyCwvyjq/gk=
google.golang.org/protobuf v1.36.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
6 changes: 5 additions & 1 deletion src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ func main() {
logger.Log.Debug(envFileMessage)
logger.Log.Info(fmt.Sprintf("qBittorrent URL: %s", app.QBittorrent.BaseUrl))
logger.Log.Info(fmt.Sprintf("username: %s", app.QBittorrent.Username))
logger.Log.Info(fmt.Sprintf("password: %s", app.GetPasswordMasked()))
password := app.GetPasswordMasked()
if app.Exporter.Feature.ShowPassword {
password = app.QBittorrent.Password
}
logger.Log.Info(fmt.Sprintf("password: %s", password))
logger.Log.Info(fmt.Sprintf("Features enabled: %s", app.GetFeaturesEnabled()))
logger.Log.Info("Started")

Expand Down
3 changes: 3 additions & 0 deletions src/qbit/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ func Auth() error {

if resp.StatusCode != http.StatusOK {
err := fmt.Errorf("Authentication failed, status code: %d", resp.StatusCode)
if resp.StatusCode == http.StatusForbidden && app.QBittorrent.Cookie == nil {
panic(fmt.Sprintf("%s. qBittorrent has probably banned your IP", err.Error()))
}
logger.Log.Error(err.Error())
return err
}
Expand Down
1 change: 1 addition & 0 deletions src/qbit/qbit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func TestApiRequest_Forbidden(t *testing.T) {
defer server.Close()

app.QBittorrent.BaseUrl = server.URL
app.QBittorrent.Cookie = &cookie
url := createUrl("/test")

_, reAuth, err := apiRequest(url, "GET", nil)
Expand Down

0 comments on commit 912ebb3

Please sign in to comment.