Skip to content

Commit

Permalink
Merge pull request #19 from kube-hetzner/as/fix/creds-required
Browse files Browse the repository at this point in the history
fix!: required credentials and updated README
  • Loading branch information
aleksasiriski authored Nov 27, 2024
2 parents 3159af9 + beab139 commit 72bdf0a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 13 deletions.
17 changes: 11 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,17 @@ The proxy is highly configurable using the following environment variables:

| Environment Variable | Default Value | Description |
| -------------------- | -------------------------------------- | -------------------------------------------------------------------- |
| `PORT_PROXY` | `31280` | The port on which the proxy server listens for traffic. |
| `PORT_PROBES` | `31281` | The port on which the probe server (health and readiness) listens. |
| `SHUTDOWN_TIMEOUT` | `5` | The timeout duration in seconds for graceful shutdown of the server. |
| `READINESS_URL` | `https://cloudflare.com/cdn-cgi/trace` | The URL to check for network readiness (internet connection check). |
| `USERNAME` | `proxy` | The username for Basic Authentication on the proxy. |
| `PASSWORD` | `secret` | The password for Basic Authentication on the proxy. |
| `DEBUG` | `false` | Enables debug mode if set to `true`. |
| `PORT_PROXY` | `31280` | The port on which the proxy server listens for traffic. |
| `PORT_PROBES` | `31281` | The port on which the probe server (health and readiness) listens. |
| `SHUTDOWN_TIMEOUT` | `5s` | The timeout duration (in seconds) for graceful shutdown of the server. |
| `READINESS_URL` | `https://cloudflare.com/cdn-cgi/trace`| The URL to check for network readiness (internet connection check). |
| `USERNAME` | *required* | The username for Basic Authentication on the proxy. Must be set. |
| `PASSWORD` | *required* | The password for Basic Authentication on the proxy. Must be set. |

### Notes
- **Mandatory Variables:** Both `USERNAME` and `PASSWORD` are required for the proxy to run. If either is not set, the application will exit with an error.
- **Shutdown Timeout Format:** Ensure `SHUTDOWN_TIMEOUT` is provided in seconds (e.g., `5s`).

## Usage

Expand Down
12 changes: 8 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ const (
portProbesDefault = "31281"
shutdownTimeoutDefault = 5 * time.Second
readinessURLDefault = "https://cloudflare.com/cdn-cgi/trace"
usernameDefault = "proxy"
passwordDefault = "secret"
)

func main() {
Expand All @@ -57,8 +55,14 @@ func main() {
portProbes := getEnv("PORT_PROBES", portProbesDefault)
shutdownTimeoutS := getEnv("SHUTDOWN_TIMEOUT", shutdownTimeoutDefault.String())
readinessURL := getEnv("READINESS_URL", readinessURLDefault)
username := getEnv("USERNAME", usernameDefault)
password := getEnv("PASSWORD", passwordDefault)
username := getEnv("USERNAME")
password := getEnv("PASSWORD")

// Check if the username and password are set
if username == "" || password == "" {
slog.Error("Username and password must be set")
os.Exit(1)
}

// Parse the debug value
debug, err := strconv.ParseBool(debugS)
Expand Down
7 changes: 4 additions & 3 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ import (
"os"
)

func getEnv(key, defaultValue string) string {
// Gets environment variable with optional default value
func getEnv(key string, defaultValue ...string) string {
value := os.Getenv(key)
if value == "" {
return defaultValue
if value == "" && len(defaultValue) != 0 {
return defaultValue[0]
}
return value
}

0 comments on commit 72bdf0a

Please sign in to comment.