fix env variables exposure
This commit is contained in:
@@ -35,11 +35,5 @@ SEARXNG_URL: str = _agent_settings.searxng_url
|
|||||||
SEARXNG_USERNAME: str = _agent_settings.searxng_username
|
SEARXNG_USERNAME: str = _agent_settings.searxng_username
|
||||||
SEARXNG_PASSWORD: str = _agent_settings.searxng_password
|
SEARXNG_PASSWORD: str = _agent_settings.searxng_password
|
||||||
|
|
||||||
import os
|
|
||||||
os.environ["GITEA_SERVER_URL"] = GITEA_URL
|
|
||||||
os.environ["GITEA_SERVER_TOKEN"] = GITEA_TOKEN
|
|
||||||
os.environ["SEARXNG_URL"] = SEARXNG_URL
|
|
||||||
os.environ["SEARXNG_USERNAME"] = SEARXNG_USERNAME
|
|
||||||
os.environ["SEARXNG_PASSWORD"] = SEARXNG_PASSWORD
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -132,6 +132,15 @@ class CodingTools:
|
|||||||
|
|
||||||
return commands
|
return commands
|
||||||
|
|
||||||
|
def _get_subprocess_env(self) -> dict[str, str]:
|
||||||
|
from gitea.config import GITEA_URL, GITEA_TOKEN
|
||||||
|
env = os.environ.copy()
|
||||||
|
if GITEA_URL:
|
||||||
|
env["GITEA_SERVER_URL"] = GITEA_URL
|
||||||
|
if GITEA_TOKEN:
|
||||||
|
env["GITEA_SERVER_TOKEN"] = GITEA_TOKEN
|
||||||
|
return env
|
||||||
|
|
||||||
def run_verification(self) -> tuple[bool, str]:
|
def run_verification(self) -> tuple[bool, str]:
|
||||||
commands = self._parse_verification_commands()
|
commands = self._parse_verification_commands()
|
||||||
if not commands:
|
if not commands:
|
||||||
@@ -143,7 +152,8 @@ class CodingTools:
|
|||||||
try:
|
try:
|
||||||
res = subprocess.run(
|
res = subprocess.run(
|
||||||
cmd, shell=True, cwd=self.repo_path,
|
cmd, shell=True, cwd=self.repo_path,
|
||||||
capture_output=True, text=True, timeout=120
|
capture_output=True, text=True, timeout=120,
|
||||||
|
env=self._get_subprocess_env()
|
||||||
)
|
)
|
||||||
if res.returncode != 0:
|
if res.returncode != 0:
|
||||||
log_output.append(
|
log_output.append(
|
||||||
@@ -213,6 +223,7 @@ class CodingTools:
|
|||||||
stderr=subprocess.PIPE,
|
stderr=subprocess.PIPE,
|
||||||
text=True,
|
text=True,
|
||||||
cwd=self.repo_path,
|
cwd=self.repo_path,
|
||||||
|
env=self._get_subprocess_env(),
|
||||||
)
|
)
|
||||||
stdout: str
|
stdout: str
|
||||||
stderr: str
|
stderr: str
|
||||||
|
|||||||
@@ -140,6 +140,12 @@ class TestFormatResults:
|
|||||||
|
|
||||||
|
|
||||||
class TestSearchSearxng:
|
class TestSearchSearxng:
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def mock_searxng_url(self) -> "Generator[None, None, None]":
|
||||||
|
from typing import Generator
|
||||||
|
with patch("gitea.tools.research_tools._SEARXNG_URL", "http://localhost"):
|
||||||
|
yield
|
||||||
|
|
||||||
def _make_searxng_response(self, results: list[dict]) -> MagicMock:
|
def _make_searxng_response(self, results: list[dict]) -> MagicMock:
|
||||||
mock_resp = MagicMock()
|
mock_resp = MagicMock()
|
||||||
mock_resp.json.return_value = {"results": results}
|
mock_resp.json.return_value = {"results": results}
|
||||||
|
|||||||
Reference in New Issue
Block a user