Skip to content

Commit

Permalink
Prevent FIREWHALE_RELOAD_INTERVAL from being negative
Browse files Browse the repository at this point in the history
  • Loading branch information
celsiusnarhwal committed Jul 17, 2024
1 parent 1cc3982 commit 92a20b7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,13 @@ Firewhale supports all versions of the Docker API that are also supported by Doc

Some aspects of Firewhale can be configured via environment variables.

| **Environment Variable** | **Description** | **Default** |
|------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------|
| `FIREWHALE_PORT` | The port on which Firewhale should listen. Firewhale will be accessible at `http://firewhale:${FIREWHALE_PORT}`. Must be an integer between 0 and 65535 and different than `FIREWHALE_CADDY_API_PORT`. | 2375 |
| `FIREWHALE_CADDY_API_PORT` | The port on which Caddy's [admin API](https://caddyserver.com/docs/api) should listen. The Caddy API will be accessible at `localhost:${FIREWHALE_CADDY_API_PORT}` within Firewhale's container. Must be an integer between 0 and 65535 and different than `FIREWHALE_PORT`. | 2019 |
| `FIREWHALE_HTTP_STATUS_CODE` | The [HTTP status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status) Firewhale should respond with when it receives a request it has not been configured to allow. Must be an integer between 100 and 599. | 403 |
| `FIREWHALE_RELOAD_INTERVAL` | The interval at which Firewhale will query Docker for any changes to your services' labels and update its rules accordingly. Must be in the format of a [Go duration string](https://pkg.go.dev/time#ParseDuration), except you can also use `d` for day, `w` for week, `mm` for month, and `y` for year.[^1] | `30s` |
| `FIREWHALE_LABEL_PREFIX` | The prefix with which Firewhale labels should begin. Socket access will be configurable using the `${LABEL_PREFIX}.read` and `${LABEL_PREFIX}.write` labels. | `firewhale` |
| **Environment Variable** | **Description** | **Default** |
|------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------|
| `FIREWHALE_PORT` | The port on which Firewhale should listen. Firewhale will be accessible at `http://firewhale:${FIREWHALE_PORT}`. Must be an integer between 0 and 65535 and different than `FIREWHALE_CADDY_API_PORT`. | 2375 |
| `FIREWHALE_CADDY_API_PORT` | The port on which Caddy's [admin API](https://caddyserver.com/docs/api) should listen. The Caddy API will be accessible at `localhost:${FIREWHALE_CADDY_API_PORT}` within Firewhale's container. Must be an integer between 0 and 65535 and different than `FIREWHALE_PORT`. | 2019 |
| `FIREWHALE_HTTP_STATUS_CODE` | The [HTTP status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status) Firewhale should respond with when it receives a request it has not been configured to allow. Must be an integer between 100 and 599. | 403 |
| `FIREWHALE_RELOAD_INTERVAL` | The interval at which Firewhale will query Docker for any changes to your services' labels and update its rules accordingly. Must be in the format of a [Go duration string](https://pkg.go.dev/time#ParseDuration) (except you can also use `d` for day, `w` for week, `mm` for month, and `y` for year[^1]) that represents a non-negative value in seconds. | `30s` |
| `FIREWHALE_LABEL_PREFIX` | The prefix with which Firewhale labels should begin. Socket access will be configurable using the `${LABEL_PREFIX}.read` and `${LABEL_PREFIX}.write` labels. | `firewhale` |

## Considerations

Expand Down
5 changes: 4 additions & 1 deletion firewhale/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,16 @@ def validate_ports(self):
@field_validator("reload_interval")
def validate_reload_interval(cls, v):
try:
durationpy.from_str(v)
interval = durationpy.from_str(v)
except ValueError:
raise ValueError(
"FIREWHALE_RELOAD_INTERVAL must be in the format of a Go duration string. "
"https://pkg.go.dev/time#ParseDuration"
) from None

if interval.total_seconds() < 0:
raise ValueError(f"FIREWHALE_RELOAD_INTERVAL may not be negative ({v} = {interval.total_seconds()}).")

return v

@property
Expand Down

0 comments on commit 92a20b7

Please sign in to comment.