Skip to content

Commit

Permalink
Merge branch 'main' into feat/exec-connection-template
Browse files Browse the repository at this point in the history
  • Loading branch information
moshloop authored Nov 11, 2024
2 parents 00bcb15 + c9a0a6d commit 9f1b6a8
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 15 deletions.
16 changes: 11 additions & 5 deletions auth/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
"errors"
"fmt"
"log/slog"
"strings"
"time"

"github.com/flanksource/commons/collections"
"github.com/flanksource/commons/hash"
"github.com/flanksource/commons/logger"
"github.com/flanksource/duty/context"
Expand Down Expand Up @@ -47,9 +47,9 @@ var (
var skipAuthPaths = []string{
"/health",
"/metrics",
"/kratos/*",
"/canary/webhook/*",
"/playbook/webhook/:webhook_path", // Playbook webhooks handle the authentication themselves
"/kratos/",
"/canary/webhook/",
"/playbook/webhook/", // Playbook webhooks handle the authentication themselves
}

func Middleware(ctx context.Context, e *echo.Echo) error {
Expand Down Expand Up @@ -109,8 +109,14 @@ func Middleware(ctx context.Context, e *echo.Echo) error {
return nil
}

// TODO: Use regex supported path matching
func canSkipAuth(c echo.Context) bool {
return collections.Contains(skipAuthPaths, c.Path())
for _, p := range skipAuthPaths {
if strings.HasPrefix(c.Path(), p) {
return true
}
}
return false
}

func mapIDsToRoles(ctx context.Context, session *client.Session, person models.Person) error {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ require (
github.com/containrrr/shoutrrr v0.8.0
github.com/fergusstrange/embedded-postgres v1.25.0 // indirect
github.com/flanksource/commons v1.31.2
github.com/flanksource/duty v1.0.747
github.com/flanksource/duty v1.0.750
github.com/flanksource/gomplate/v3 v3.24.39
github.com/flanksource/kopper v1.0.10
github.com/gomarkdown/markdown v0.0.0-20240419095408-642f0ee99ae2
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -924,8 +924,8 @@ github.com/flanksource/artifacts v1.0.14 h1:Vv70bccsae0MwGaf/uSPp34J5V1/PyKfct9z
github.com/flanksource/artifacts v1.0.14/go.mod h1:qHVCnQu5k50aWNJ5UhpcAKEl7pAzqUrFFKGSm147G70=
github.com/flanksource/commons v1.31.2 h1:VBhmhmvk6PjhJYuaK8LL+7700E3zPCY03VV/K1BxH64=
github.com/flanksource/commons v1.31.2/go.mod h1:X2txnbNGY6fKQuKLmc7x92FMYjB2MuaqNJOR6vEWDMs=
github.com/flanksource/duty v1.0.747 h1:N5wXyGTndV4cLxfSg51QuFTnWhv9I2Uepcxu2m6rft8=
github.com/flanksource/duty v1.0.747/go.mod h1:sZY2NytdenrkqXoMD6Gn2C8xH6dm5HsqOeE0p74Z2VE=
github.com/flanksource/duty v1.0.750 h1:07nyNLefAZOmZOgdb4yJuPG96K2/hZj60oAF5OEPFtc=
github.com/flanksource/duty v1.0.750/go.mod h1:sZY2NytdenrkqXoMD6Gn2C8xH6dm5HsqOeE0p74Z2VE=
github.com/flanksource/gomplate/v3 v3.20.4/go.mod h1:27BNWhzzSjDed1z8YShO6W+z6G9oZXuxfNFGd/iGSdc=
github.com/flanksource/gomplate/v3 v3.24.39 h1:O763lnNIcTELSMYeIO0dNDfcb3LoZvzU1fr62I4Yxqg=
github.com/flanksource/gomplate/v3 v3.24.39/go.mod h1:0wY/+UPvd7CxmiTBNmzZdWIEOUZAsRkpGY1j5R711O8=
Expand Down
7 changes: 1 addition & 6 deletions notification/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,12 +335,7 @@ func isHealthReportable(events []string, previousHealth, currentHealth models.He
return false
}

if previousHealth == currentHealth {
return true
}

healthDegraded := models.WorseHealth(previousHealth, currentHealth) == currentHealth
return healthDegraded
return previousHealth == currentHealth
}

// GetEnvForEvent gets the environment variables for the given event
Expand Down
9 changes: 8 additions & 1 deletion notification/events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestIsHealthReportable(t *testing.T) {
events: []string{"config.warning", "config.healthy"},
previousHealth: models.HealthHealthy,
currentHealth: models.HealthWarning,
expected: true,
expected: false,
},
{
name: "health changed and got better",
Expand All @@ -35,6 +35,13 @@ func TestIsHealthReportable(t *testing.T) {
currentHealth: models.HealthUnhealthy,
expected: false,
},
{
name: "health unchanged",
events: []string{"config.warning", "config.healthy"},
previousHealth: models.HealthHealthy,
currentHealth: models.HealthHealthy,
expected: true,
},
}

for _, tt := range tests {
Expand Down

0 comments on commit 9f1b6a8

Please sign in to comment.