Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ The behavior of the gateway is configurable via a number of environment variable
- `json`: events are run through [`slog.JSONHandler`](https://pkg.go.dev/log/slog#JSONHandler).
- LOG_LEVEL: This environment variable controls how noisy logs are. The supported values correspond to the [`slog.Level` values](https://pkg.go.dev/log/slog@master#Level).
- TARGET_REWRITES: This environment variable contains a JSON document instructing the gateway to rewrite the target URL found in an encapsulated request to some specified scheme and host.
- KEY_ROTATION_INTERVAL: This environment variable sets the number of days before renewing the gateway private and public key pair. The default value is 0, meaning that they will never expire.

### Target URL rewrites

Expand Down
1 change: 1 addition & 0 deletions gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type gatewayResource struct {
encapsulationHandlers map[string]EncapsulationHandler
debugResponse bool
metricsFactory MetricsFactory
keyRotationInteval uint8
}

const (
Expand Down
2 changes: 1 addition & 1 deletion handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ type MetadataEncapsulationHandler struct {
gateway ohttp.Gateway
}

// Handle attempts to decapsulate the incoming encapsulated request and, if successful, foramts
// Handle attempts to decapsulate the incoming encapsulated request and, if successful, formats
// metadata from the request context, and then encapsulates and returns the result.
func (h MetadataEncapsulationHandler) Handle(outerRequest *http.Request, encapsulatedReq ohttp.EncapsulatedRequest, metrics Metrics) (ohttp.EncapsulatedResponse, error) {
if !h.gateway.MatchesConfig(encapsulatedReq) {
Expand Down
6 changes: 6 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ const (
logFormatEnvironmentVariable = "LOG_FORMAT"
targetRewritesVariables = "TARGET_REWRITES"
prometheusConfigVariable = "PROMETHEUS_CONFIG"
configKeyRotationInterval = "KEY_ROTATION_INTERVAL"

// Values for LOG_FORMAT environment variable
logFormatDefault = "default"
Expand Down Expand Up @@ -335,6 +336,10 @@ func main() {
metadataEndpoint := getStringEnv(metadataEndpointEnvVariable, defaultMetadataEndpoint)
healthEndpoint := getStringEnv(healthEndpointEnvVariable, defaultHealthEndpoint)

// Interval in days for the renewing of the public and private key pair of the gateway.
// If 0, it never expire.
keyRotationInterval := uint8(getUintEnv(configKeyRotationInterval, 0))

// Install configuration endpoints
handlers := make(map[string]EncapsulationHandler)
handlers[gatewayEndpoint] = targetHandler // Content-specific handler
Expand All @@ -346,6 +351,7 @@ func main() {
encapsulationHandlers: handlers,
debugResponse: debugResponse,
metricsFactory: metricsFactory,
keyRotationInteval: keyRotationInterval,
}

endpoints := make(map[string]string)
Expand Down