Odstranil jsem hardcoded IP fallbacky z portálového Python kódu:
DEFAULT_APPFACTORY_HOST = "192.168.66.130" je pryč z config.py (line 10). DEFAULT_GITEA_URL = "http://192.168.66.130:3000" je pryč z auth.py (line 24). Doplněné chování: APPFACTORY_HOST se odvozuje přes helper: env APPFACTORY_HOST, potom APPFACTORY_PORTAL_PUBLIC_URL, potom request host. Gitea browser redirect používá jen explicitní veřejnou URL z GITEA_URL nebo GITEA_ROOT_URL. Server-side Gitea token/userinfo requesty používají GITEA_URL, potom GITEA_ROOT_URL, jinak interní Docker URL http://appfactory-gitea:3000. Gitea login tlačítko se zobrazí jen při kompletní konfiguraci: public URL, client id, client secret a redirect URI. Přímý Gitea login bez kompletní konfigurace vrací čitelnou chybu.
This commit is contained in:
+42
-1
@@ -8,7 +8,7 @@ APPFACTORY_ENV = "/opt/appfactory/config/appfactory.env"
|
||||
|
||||
DEFAULT_BACKUP_DIR = "/opt/appfactory/backups"
|
||||
DEFAULT_GITEA_ORG = "appfactory"
|
||||
DEFAULT_APPFACTORY_HOST = "192.168.66.130"
|
||||
INTERNAL_GITEA_URL = "http://appfactory-gitea:3000"
|
||||
|
||||
PORTAL_PREFIX = "/portal"
|
||||
|
||||
@@ -58,6 +58,47 @@ def get_google_redirect_uri() -> str:
|
||||
return ""
|
||||
|
||||
|
||||
def get_gitea_public_url() -> str:
|
||||
return (read_env_value("GITEA_URL", "") or read_env_value("GITEA_ROOT_URL", "")).rstrip("/")
|
||||
|
||||
|
||||
def get_gitea_server_url() -> str:
|
||||
return get_gitea_public_url() or INTERNAL_GITEA_URL
|
||||
|
||||
|
||||
def get_gitea_redirect_uri() -> str:
|
||||
redirect_uri = read_env_value("GITEA_OAUTH_REDIRECT_URI", "").strip()
|
||||
if redirect_uri:
|
||||
return redirect_uri
|
||||
|
||||
public_url = get_portal_public_url()
|
||||
if public_url:
|
||||
return f"{public_url}/auth/gitea/callback"
|
||||
|
||||
return ""
|
||||
|
||||
|
||||
def is_gitea_oauth_button_enabled() -> bool:
|
||||
return bool(
|
||||
get_gitea_public_url()
|
||||
and read_env_value("GITEA_OAUTH_CLIENT_ID", "")
|
||||
and read_env_value("GITEA_OAUTH_CLIENT_SECRET", "")
|
||||
and get_gitea_redirect_uri()
|
||||
)
|
||||
|
||||
|
||||
def get_appfactory_host(request_host: str = "") -> str:
|
||||
configured_host = read_env_value("APPFACTORY_HOST", "").strip()
|
||||
if configured_host:
|
||||
return configured_host
|
||||
|
||||
public_url = get_portal_public_url()
|
||||
if public_url:
|
||||
return public_url.split("://", 1)[-1].split("/", 1)[0].split(":", 1)[0]
|
||||
|
||||
return (request_host or "").split(":", 1)[0]
|
||||
|
||||
|
||||
def get_auth_domain_readiness() -> dict[str, bool]:
|
||||
google_enabled = read_env_bool("GOOGLE_OAUTH_ENABLED")
|
||||
google_client_id = read_env_value("GOOGLE_CLIENT_ID", "")
|
||||
|
||||
Reference in New Issue
Block a user