Skip to content

Commit

Permalink
Fix URL formatting in GitRepository when using provider-specific gi…
Browse files Browse the repository at this point in the history
…t credentials blocks (#11282)
  • Loading branch information
desertaxle authored Nov 29, 2023
1 parent 6e43187 commit 6351297
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
14 changes: 12 additions & 2 deletions src/prefect/runner/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,18 @@
from anyio import run_process

from prefect._internal.concurrency.api import create_call, from_async
from prefect._internal.pydantic import HAS_PYDANTIC_V2
from prefect.blocks.core import Block, BlockNotSavedError
from prefect.blocks.system import Secret
from prefect.filesystems import ReadableDeploymentStorage, WritableDeploymentStorage
from prefect.logging.loggers import get_logger
from prefect.utilities.collections import visit_collection

if HAS_PYDANTIC_V2:
from pydantic.v1 import SecretStr
else:
from pydantic import SecretStr


@runtime_checkable
class RunnerStorage(Protocol):
Expand Down Expand Up @@ -156,8 +162,12 @@ def _repository_url_with_credentials(self) -> str:
if isinstance(self._credentials, Block)
else deepcopy(self._credentials)
)
if isinstance(credentials.get("access_token"), Secret):
credentials["access_token"] = credentials["access_token"].get()

for k, v in credentials.items():
if isinstance(v, Secret):
credentials[k] = v.get()
elif isinstance(v, SecretStr):
credentials[k] = v.get_secret_value()

formatted_credentials = _format_token_from_credentials(
urlparse(self._url).netloc, credentials
Expand Down
13 changes: 9 additions & 4 deletions tests/runner/test_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
from textwrap import dedent
from typing import Optional

import pytest

from prefect._internal.pydantic import HAS_PYDANTIC_V2
from prefect.blocks.core import Block, BlockNotSavedError
from prefect.blocks.system import Secret
from prefect.deployments.steps.core import run_step
Expand All @@ -19,6 +18,12 @@
)
from prefect.testing.utilities import AsyncMock, MagicMock

if HAS_PYDANTIC_V2:
from pydantic.v1 import SecretStr
else:
from pydantic import SecretStr
import pytest


class TestCreateStorageFromUrl:
@pytest.mark.parametrize(
Expand Down Expand Up @@ -72,9 +77,9 @@ def mock_run_process(monkeypatch):


class MockCredentials(Block):
token: Optional[str] = None
token: Optional[SecretStr] = None
username: Optional[str] = None
password: Optional[str] = None
password: Optional[SecretStr] = None


class TestGitRepository:
Expand Down

0 comments on commit 6351297

Please sign in to comment.