splunk / splunk/splunk-sdk-python

`SPLUNK_HOME` absolute-path check in `splunklib.ai.tools` fails on Windows

Abierto Apto para principiantes
#831 1 comentario 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Lenguaje dominante
Python
Estrellas
743
Forks
387
Merge medio
42 min
PR fusionados (30 d)
4

Descripción

Describe the bug

_splunk_home() in splunklib/ai/tools.py validates that SPLUNK_HOME is an absolute path via splunk_home.startswith("/"). This check is POSIX-only. On Windows, SPLUNK_HOME is a drive-letter path (e.g. C:\Program Files\Splunk), which never starts with / even though it is a valid absolute path. As a result, _splunk_home() — and anything built on it, such as locate_app() — unconditionally raises RuntimeError("SPLUNK_HOME is not absolute") on Windows, regardless of the actual value of SPLUNK_HOME. This makes the splunklib.ai.tools module entirely unusable on Windows.

To Reproduce

  1. On a Windows host, set a valid absolute SPLUNK_HOME, e.g.:
    set SPLUNK_HOME=C:\Program Files\Splunk
    
  2. Run:
    from splunklib.ai.tools import locate_app
    locate_app()
    
    (or call _splunk_home() directly, or invoke anything in the SDK that depends on it, such as an app built with splunklib.ai.tools)
  3. Observe:
    RuntimeError: SPLUNK_HOME is not absolute
    
    even though SPLUNK_HOME is a correctly-formed absolute Windows path.

Expected behavior

_splunk_home() should recognize Windows absolute paths (drive-letter paths, UNC paths) as valid — e.g. by using os.path.isabs(splunk_home) instead of splunk_home.startswith("/"). Any SDK functionality depending on SPLUNK_HOME should work identically on Windows and POSIX systems given a correct value.

Logs or Screenshots

RuntimeError: SPLUNK_HOME is not absolute

Raised from:

def _splunk_home() -> str:
    splunk_home = os.environ.get("SPLUNK_HOME", "/opt/splunk")
    if not splunk_home.startswith("/"):
        raise RuntimeError("SPLUNK_HOME is not absolute")
    return splunk_home

Splunk (please complete the following information):

  • Version: 10.4.2
  • OS: Windows Server 2022 (build 20348)
  • Deployment: single-instance

SDK (please complete the following information):

  • Version: 3.0.0
  • Language Runtime Version: Python 3.13.11
  • OS: Windows Server 2022 (build 20348)

Additional context

  • The default fallback value ("/opt/splunk" when SPLUNK_HOME is unset) is also POSIX-only and would need a Windows-aware equivalent, or the fallback should be removed in favor of requiring an explicit value.
  • This affects any app that vendors or depends on splunklib.ai.tools and is deployed on Windows — the failure is unconditional and unrelated to app configuration, credentials, or SPLUNK_HOME's actual correctness.

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Empieza en splunklib/ai/tools.py, en _splunk_home(), y luego sigue locate_app() y otros llamadores que dependen de él. Verifica el comportamiento de las rutas absolutas para letras de unidad de Windows y rutas UNC, así como para rutas POSIX, y confirma que los valores válidos de Windows SPLUNK_HOME ya no provocan errores, mientras que los valores no válidos siguen haciéndolo.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
python
Área
backend
Tipo de issue
Error
Dificultad
2/5
Tiempo estimado
1-3 horas
Estado de actividad
Tranquilo
Claridad
Bien especificado
Aptitud para principiantes
74/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.