Skip to content

Commit 2861f92

Browse files
committed
fix: derive bouncer Valid status from revoked field (CrowdSec >= v1.7.x)
CrowdSec v1.7.x replaced the "valid" JSON field with "revoked: false" in the bouncers list API response. The manager still reads "valid", which no longer exists, causing all bouncers to show as "disconnected". This fix reads the "revoked" field and derives Valid = !Revoked. Falls back to treating the bouncer as valid if neither field is present. Fixes #47
1 parent 8c92c4f commit 2861f92

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

internal/api/handlers/health_diagnostics.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,22 @@ func parseBouncersJSON(bouncerOutput string, computeStatus bool) ([]models.Bounc
4949
bouncer.Version = version
5050
}
5151

52+
// CrowdSec >= v1.7.x replaced "valid: true" with "revoked: false".
53+
// Read the revoked field; if present, derive Valid from it.
54+
if revoked, err := jsonparser.GetBoolean(value, "revoked"); err == nil {
55+
bouncer.Revoked = revoked
56+
bouncer.Valid = !revoked
57+
}
58+
// If neither "valid" nor "revoked" was found (edge case),
59+
// treat the bouncer as valid — it exists in the list, so it was not deleted.
60+
if !bouncer.Valid {
61+
if _, validErr := jsonparser.GetBoolean(value, "valid"); validErr != nil {
62+
if _, revokedErr := jsonparser.GetBoolean(value, "revoked"); revokedErr != nil {
63+
bouncer.Valid = true
64+
}
65+
}
66+
}
67+
5268
if computeStatus {
5369
if !bouncer.Valid {
5470
bouncer.Status = "disconnected"

internal/models/models.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ func (d *DecisionRaw) Normalize() Decision {
149149
type Bouncer struct {
150150
Name string `json:"name"`
151151
IPAddress string `json:"ip_address"`
152+
Revoked bool `json:"revoked"`
152153
Valid bool `json:"valid"`
153154
LastPull time.Time `json:"last_pull"`
154155
Type string `json:"type"`

0 commit comments

Comments
 (0)