refactor: simplify build paths func and better slice handling

This commit is contained in:
Stavros
2026-02-16 23:19:26 +02:00
parent 20ed66623b
commit 6f4424dd08
2 changed files with 15 additions and 20 deletions

View File

@@ -17,11 +17,11 @@ TINYAUTH_SERVER_ADDRESS=0.0.0.0
# The path to the Unix socket.
TINYAUTH_SERVER_SOCKETPATH=
# List of allowed IPs or CIDR ranges.
TINYAUTH_AUTH_IP_ALLOW=[]
TINYAUTH_AUTH_IP_ALLOW=
# List of blocked IPs or CIDR ranges.
TINYAUTH_AUTH_IP_BLOCK=[]
TINYAUTH_AUTH_IP_BLOCK=
# Comma-separated list of users (username:hashed_password).
TINYAUTH_AUTH_USERS=[]
TINYAUTH_AUTH_USERS=
# Path to the users file.
TINYAUTH_AUTH_USERSFILE=
# Enable secure cookies.
@@ -35,7 +35,7 @@ TINYAUTH_AUTH_LOGINTIMEOUT=300
# Maximum login retries.
TINYAUTH_AUTH_LOGINMAXRETRIES=3
# Comma-separated list of trusted proxy addresses.
TINYAUTH_AUTH_TRUSTEDPROXIES=[]
TINYAUTH_AUTH_TRUSTEDPROXIES=
# The domain of the app.
TINYAUTH_APPS_[NAME]_CONFIG_DOMAIN=
# Comma-separated list of allowed users.
@@ -47,13 +47,13 @@ TINYAUTH_APPS_[NAME]_OAUTH_WHITELIST=
# Comma-separated list of required OAuth groups.
TINYAUTH_APPS_[NAME]_OAUTH_GROUPS=
# List of allowed IPs or CIDR ranges.
TINYAUTH_APPS_[NAME]_IP_ALLOW=[]
TINYAUTH_APPS_[NAME]_IP_ALLOW=
# List of blocked IPs or CIDR ranges.
TINYAUTH_APPS_[NAME]_IP_BLOCK=[]
TINYAUTH_APPS_[NAME]_IP_BLOCK=
# List of IPs or CIDR ranges that bypass authentication.
TINYAUTH_APPS_[NAME]_IP_BYPASS=[]
TINYAUTH_APPS_[NAME]_IP_BYPASS=
# Custom headers to add to the response.
TINYAUTH_APPS_[NAME]_RESPONSE_HEADERS=[]
TINYAUTH_APPS_[NAME]_RESPONSE_HEADERS=
# Basic auth username.
TINYAUTH_APPS_[NAME]_RESPONSE_BASICAUTH_USERNAME=
# Basic auth password.
@@ -67,7 +67,7 @@ TINYAUTH_APPS_[NAME]_PATH_BLOCK=
# Comma-separated list of required LDAP groups.
TINYAUTH_APPS_[NAME]_LDAP_GROUPS=
# Comma-separated list of allowed OAuth domains.
TINYAUTH_OAUTH_WHITELIST=[]
TINYAUTH_OAUTH_WHITELIST=
# The OAuth provider to use for automatic redirection.
TINYAUTH_OAUTH_AUTOREDIRECT=
# OAuth client ID.
@@ -77,7 +77,7 @@ TINYAUTH_OAUTH_PROVIDERS_[NAME]_CLIENTSECRET=
# Path to the file containing the OAuth client secret.
TINYAUTH_OAUTH_PROVIDERS_[NAME]_CLIENTSECRETFILE=
# OAuth scopes.
TINYAUTH_OAUTH_PROVIDERS_[NAME]_SCOPES=[]
TINYAUTH_OAUTH_PROVIDERS_[NAME]_SCOPES=
# OAuth redirect URL.
TINYAUTH_OAUTH_PROVIDERS_[NAME]_REDIRECTURL=
# OAuth authorization URL.
@@ -103,7 +103,7 @@ TINYAUTH_OIDC_CLIENTS_[NAME]_CLIENTSECRET=
# Path to the file containing the OIDC client secret.
TINYAUTH_OIDC_CLIENTS_[NAME]_CLIENTSECRETFILE=
# List of trusted redirect URIs.
TINYAUTH_OIDC_CLIENTS_[NAME]_TRUSTEDREDIRECTURIS=[]
TINYAUTH_OIDC_CLIENTS_[NAME]_TRUSTEDREDIRECTURIS=
# Client name in UI.
TINYAUTH_OIDC_CLIENTS_[NAME]_NAME=
# The title of the UI.

View File

@@ -31,11 +31,13 @@ func generateExampleEnv() {
err := os.Remove(".env.example")
if err != nil {
slog.Error("failed to remove example env file", "error", err)
os.Exit(1)
}
err = os.WriteFile(".env.example", compiled, 0644)
if err != nil {
slog.Error("failed to write example env file", "error", err)
os.Exit(1)
}
}
@@ -48,20 +50,13 @@ func buildPaths(parent reflect.Type, parentValue reflect.Value, parentPath strin
case reflect.Struct:
childPath := parentPath + strings.ToUpper(field.Name) + "_"
buildPaths(fieldType, fieldValue, childPath, paths)
case reflect.Bool:
buildPath(field, fieldValue, parentPath, paths)
case reflect.String:
buildPath(field, fieldValue, parentPath, paths)
case reflect.Slice:
buildPath(field, fieldValue, parentPath, paths)
case reflect.Int:
buildPath(field, fieldValue, parentPath, paths)
case reflect.Map:
buildMapPaths(field, parentPath, paths)
case reflect.Bool, reflect.String, reflect.Slice, reflect.Int:
buildPath(field, fieldValue, parentPath, paths)
default:
slog.Info("unknown type", "type", fieldType.Kind())
}
}
}