splunk / splunk/splunk-sdk-python
`SPLUNK_HOME` absolute-path check in `splunklib.ai.tools` fails on Windows
Personne n'a encore pris cette issue.
- Langage dominant
- Python
- Étoiles
- 743
- Forks
- 387
- Merge moyen
- 42 min
- PR mergées (30 j)
- 4
Description
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
- On a Windows host, set a valid absolute
SPLUNK_HOME, e.g.:set SPLUNK_HOME=C:\Program Files\Splunk - Run:
(or callfrom splunklib.ai.tools import locate_app locate_app()_splunk_home()directly, or invoke anything in the SDK that depends on it, such as an app built withsplunklib.ai.tools) - Observe:
even thoughRuntimeError: SPLUNK_HOME is not absoluteSPLUNK_HOMEis 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"whenSPLUNK_HOMEis 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.toolsand is deployed on Windows — the failure is unconditional and unrelated to app configuration, credentials, orSPLUNK_HOME's actual correctness.
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Commencez dans splunklib/ai/tools.py, au niveau de _splunk_home(), puis suivez locate_app() et les autres appelants qui en dépendent. Vérifiez le comportement des chemins absolus pour les lettres de lecteur Windows et les chemins UNC, ainsi que pour les chemins POSIX, et confirmez que les valeurs Windows SPLUNK_HOME valides ne lèvent plus d’erreur, tandis que les valeurs non valides continuent de le faire.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- python
- Domaine
- backend
- Type d'issue
- Bug
- Difficulté
- 2/5
- Temps estimé
- 1-3 heures
- Activité
- Calme
- Clarté
- Clairement spécifiée
- Accessibilité débutants
- 74/100