Skip to content

Commit

Permalink
[refactor] Reading FailureMode from ENV
Browse files Browse the repository at this point in the history
Signed-off-by: dd di cesare <[email protected]>
  • Loading branch information
didierofrivia committed Nov 20, 2024
1 parent ebdce57 commit eed4ae2
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions pkg/wasm/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"encoding/json"
"errors"
"fmt"
"os"
"strings"

"github.com/kuadrant/policy-machinery/machinery"
Expand All @@ -30,10 +31,33 @@ func AuthServiceTimeout() string {
return env.GetString("AUTH_SERVICE_TIMEOUT", "200ms")
}

func AuthServiceFailureMode() FailureModeType {
return parseFailureModeValue("AUTH_SERVICE_FAILURE_MODE", FailureModeAllow)
}

func RatelimitServiceTimeout() string {
return env.GetString("RATELIMIT_SERVICE_TIMEOUT", "100ms")
}

func RatelimitServiceFailureMode() FailureModeType {
return parseFailureModeValue("RATELIMIT_SERVICE_FAILURE_MODE", FailureModeDeny)
}

func parseFailureModeValue(envVarName string, defaultValue FailureModeType) FailureModeType {
value := os.Getenv(envVarName)
if value == "" {
return defaultValue
}

switch value {
case string(FailureModeAllow), string(FailureModeDeny):
return FailureModeType(value)
default:
fmt.Printf("Warning: Invalid value '%s' for %s. Using default value '%s'.\n", value, envVarName, defaultValue)
return defaultValue
}
}

func ExtensionName(gatewayName string) string {
return fmt.Sprintf("kuadrant-%s", gatewayName)
}
Expand All @@ -44,13 +68,13 @@ func BuildConfigForActionSet(actionSets []ActionSet) Config {
AuthServiceName: {
Type: AuthServiceType,
Endpoint: kuadrant.KuadrantAuthClusterName,
FailureMode: FailureModeDeny,
FailureMode: AuthServiceFailureMode(),
Timeout: ptr.To(AuthServiceTimeout()),
},
RateLimitServiceName: {
Type: RateLimitServiceType,
Endpoint: kuadrant.KuadrantRateLimitClusterName,
FailureMode: FailureModeAllow,
FailureMode: RatelimitServiceFailureMode(),
Timeout: ptr.To(RatelimitServiceTimeout()),
},
},
Expand Down

0 comments on commit eed4ae2

Please sign in to comment.