Skip to content

Commit

Permalink
Merge pull request #968 from GitGuardian/agateau/post-release-fixes
Browse files Browse the repository at this point in the history
Post-release fixes
  • Loading branch information
agateau-gg committed Sep 25, 2024
2 parents 589aa14 + 6ef1006 commit 50b56bb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
12 changes: 7 additions & 5 deletions scripts/hmsl/hashicorp_vault.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
ROOT_TOKEN = "my_vault_token"
RESTRICTED_TOKEN = "restricted_token"

READY_TRIES = 20


logger = logging.getLogger(__name__)
logging.basicConfig(
Expand All @@ -29,8 +31,7 @@ def wait_for_server_to_be_ready() -> None:
If timeout elapsed, a RuntimeError is raised.
"""
tries = 0
while tries < 10:
for tries in range(READY_TRIES):
check_cmd_ret = subprocess.run(
[
"docker",
Expand All @@ -46,11 +47,12 @@ def wait_for_server_to_be_ready() -> None:

if "(healthy)" in json_status["Status"]:
logger.debug("Server is healthy")
return True
return

logger.debug("Server not healthy yet, waiting...")
logger.debug(
"Server not healthy yet, waiting... (%d / %d)", tries + 1, READY_TRIES
)
time.sleep(0.500)
tries += 1

raise RuntimeError("Hashicorp Vault server is not ready")

Expand Down
10 changes: 4 additions & 6 deletions tests/functional/secret/test_scan_prereceive.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import logging
import os
from pathlib import Path
from subprocess import CalledProcessError
from unittest.mock import patch

import pytest

Expand Down Expand Up @@ -106,7 +104,7 @@ def test_scan_prereceive_push_force(tmp_path: Path) -> None:


def test_scan_prereceive_timeout(
tmp_path: Path, slow_gitguardian_api: str, caplog
tmp_path: Path, monkeypatch, slow_gitguardian_api: str, caplog
) -> None:
# GIVEN a remote repository
remote_repo = Repository.create(tmp_path / "remote", bare=True)
Expand All @@ -128,9 +126,9 @@ def test_scan_prereceive_timeout(

# WHEN I try to push
# THEN the hook timeouts and allows the push
with patch.dict(
os.environ, {**os.environ, "GITGUARDIAN_API_URL": slow_gitguardian_api}
), caplog.at_level(logging.WARNING):
with caplog.at_level(logging.WARNING):
monkeypatch.setenv("GITGUARDIAN_API_URL", slow_gitguardian_api)
monkeypatch.delenv("GITGUARDIAN_INSTANCE", raising=False)
local_repo.push()

# AND the error message contains timeout message
Expand Down

0 comments on commit 50b56bb

Please sign in to comment.