Phase 2: Docker and OIDC auth
This commit is contained in:
@@ -2,8 +2,11 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
import posixpath
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def apply_remote_path_prefix(path: str, prefix: str) -> str:
|
||||
"""Apply an optional fallback prefix for Jellyfin->SSH path handoff."""
|
||||
@@ -14,10 +17,16 @@ def apply_remote_path_prefix(path: str, prefix: str) -> str:
|
||||
return path
|
||||
normalized_prefix = normalized_prefix.rstrip("/")
|
||||
if path == normalized_prefix or path.startswith(normalized_prefix + "/"):
|
||||
return posixpath.normpath(path)
|
||||
resolved = posixpath.normpath(path)
|
||||
logger.debug("Path prefix already applied path=%s prefix=%s resolved=%s", path, normalized_prefix, resolved)
|
||||
return resolved
|
||||
if path.startswith("/"):
|
||||
return posixpath.normpath(normalized_prefix + path)
|
||||
return posixpath.normpath(posixpath.join(normalized_prefix, path))
|
||||
resolved = posixpath.normpath(normalized_prefix + path)
|
||||
logger.debug("Applied path prefix path=%s prefix=%s resolved=%s", path, normalized_prefix, resolved)
|
||||
return resolved
|
||||
resolved = posixpath.normpath(posixpath.join(normalized_prefix, path))
|
||||
logger.debug("Joined path prefix path=%s prefix=%s resolved=%s", path, normalized_prefix, resolved)
|
||||
return resolved
|
||||
|
||||
|
||||
def map_path_to_media_root(path: str, media_root: str) -> str:
|
||||
@@ -39,6 +48,7 @@ def map_path_to_media_root(path: str, media_root: str) -> str:
|
||||
|
||||
path_absolute = "/" + "/".join(raw_parts)
|
||||
if path_absolute == normalized_root or path_absolute.startswith(normalized_root + "/"):
|
||||
logger.debug("Path already under media root path=%s media_root=%s", path, normalized_root)
|
||||
return path_absolute
|
||||
|
||||
root_anchor = posixpath.basename(normalized_root)
|
||||
@@ -48,7 +58,9 @@ def map_path_to_media_root(path: str, media_root: str) -> str:
|
||||
if root_anchor in raw_parts:
|
||||
anchor_index = raw_parts.index(root_anchor)
|
||||
remainder_parts = raw_parts[anchor_index + 1:]
|
||||
return posixpath.join(normalized_root, *remainder_parts) if remainder_parts else normalized_root
|
||||
resolved = posixpath.join(normalized_root, *remainder_parts) if remainder_parts else normalized_root
|
||||
logger.debug("Mapped path to media root path=%s media_root=%s resolved=%s", path, normalized_root, resolved)
|
||||
return resolved
|
||||
|
||||
return path
|
||||
|
||||
@@ -64,5 +76,8 @@ def resolve_remote_media_path(path: str, media_root: str, fallback_prefix: str)
|
||||
return path
|
||||
mapped = map_path_to_media_root(path, media_root)
|
||||
if mapped and mapped != path:
|
||||
logger.debug("Resolved media path via media root original=%s resolved=%s", path, mapped)
|
||||
return mapped
|
||||
return apply_remote_path_prefix(mapped or path, fallback_prefix)
|
||||
resolved = apply_remote_path_prefix(mapped or path, fallback_prefix)
|
||||
logger.debug("Resolved media path via fallback original=%s resolved=%s", path, resolved)
|
||||
return resolved
|
||||
|
||||
Reference in New Issue
Block a user