Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,6 @@ test-results.*

# SonarQube Reports
.sonar*

# Local Mode
mocks/
4 changes: 0 additions & 4 deletions mocks/certificates.json

This file was deleted.

1 change: 0 additions & 1 deletion mocks/destination.json

This file was deleted.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "sap-cloud-sdk"
version = "0.5.0"
version = "0.6.0"
description = "SAP Cloud SDK for Python"
readme = "README.md"
license = "Apache-2.0"
Expand Down
44 changes: 43 additions & 1 deletion src/sap_cloud_sdk/destination/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

from __future__ import annotations

import logging
import os
from typing import Optional

from sap_cloud_sdk.destination._models import (
Expand All @@ -46,6 +48,14 @@
from sap_cloud_sdk.destination.client import DestinationClient
from sap_cloud_sdk.destination.fragment_client import FragmentClient
from sap_cloud_sdk.destination.certificate_client import CertificateClient
from sap_cloud_sdk.destination.local_client import LocalDevDestinationClient
from sap_cloud_sdk.destination.local_fragment_client import LocalDevFragmentClient
from sap_cloud_sdk.destination.local_certificate_client import LocalDevCertificateClient
from sap_cloud_sdk.destination._local_client_base import (
DESTINATION_MOCK_FILE,
FRAGMENT_MOCK_FILE,
CERTIFICATE_MOCK_FILE,
)
from sap_cloud_sdk.destination.exceptions import (
DestinationError,
ClientCreationError,
Expand All @@ -56,6 +66,17 @@
)


logger = logging.getLogger(__name__)


def _mock_file(name: str) -> str:
"""Return the absolute path to a mocks/<name> file relative to the repo root."""
repo_root = os.path.abspath(
os.path.join(os.path.dirname(__file__), "..", "..", "..")
)
return os.path.join(repo_root, "mocks", name)


def create_client(
*,
instance: Optional[str] = None,
Expand All @@ -78,12 +99,19 @@ def create_client(
Defaults to False.

Returns:
DestinationClient or LocalDevDestinationProvider: Client implementing the Destination interface.
DestinationClient or LocalDevDestinationClient: Client implementing the Destination interface.

Raises:
ClientCreationError: If client creation fails due to configuration or initialization issues.
"""
try:
if os.path.isfile(_mock_file(DESTINATION_MOCK_FILE)):
logger.warning(
"Local mock mode active: using LocalDevDestinationClient backed by mocks/destination.json. "
"This is intended for local development only and must not be used in production."
)
return LocalDevDestinationClient()

# Cloud mode via secret resolver or explicit config
binding = config or load_from_env_or_mount(instance)
tp = TokenProvider(binding)
Expand Down Expand Up @@ -118,6 +146,13 @@ def create_fragment_client(
ClientCreationError: If client creation fails due to configuration or initialization issues.
"""
try:
if os.path.isfile(_mock_file(FRAGMENT_MOCK_FILE)):
logger.warning(
"Local mock mode active: using LocalDevFragmentClient backed by mocks/fragments.json. "
"This is intended for local development only and must not be used in production."
)
return LocalDevFragmentClient()

# Use provided config or load from environment/mount (cloud mode)
binding = config or load_from_env_or_mount(instance)
tp = TokenProvider(binding)
Expand Down Expand Up @@ -152,6 +187,13 @@ def create_certificate_client(
ClientCreationError: If client creation fails due to configuration or initialization issues.
"""
try:
if os.path.isfile(_mock_file(CERTIFICATE_MOCK_FILE)):
logger.warning(
"Local mock mode active: using LocalDevCertificateClient backed by mocks/certificates.json. "
"This is intended for local development only and must not be used in production."
)
return LocalDevCertificateClient()

# Use provided config or load from environment/mount (cloud mode)
binding = config or load_from_env_or_mount(instance)
tp = TokenProvider(binding)
Expand Down
Loading
Loading