Skip to content

Commit 0aa3cf7

Browse files
authored
feat: add local clients for destination module (#34)
1 parent 7ad7d31 commit 0aa3cf7

15 files changed

+2369
-193
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,6 @@ test-results.*
3232

3333
# SonarQube Reports
3434
.sonar*
35+
36+
# Local Mode
37+
mocks/

mocks/certificates.json

Lines changed: 0 additions & 4 deletions
This file was deleted.

mocks/destination.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "sap-cloud-sdk"
3-
version = "0.5.0"
3+
version = "0.6.0"
44
description = "SAP Cloud SDK for Python"
55
readme = "README.md"
66
license = "Apache-2.0"

src/sap_cloud_sdk/destination/__init__.py

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222

2323
from __future__ import annotations
2424

25+
import logging
26+
import os
2527
from typing import Optional
2628

2729
from sap_cloud_sdk.destination._models import (
@@ -46,6 +48,14 @@
4648
from sap_cloud_sdk.destination.client import DestinationClient
4749
from sap_cloud_sdk.destination.fragment_client import FragmentClient
4850
from sap_cloud_sdk.destination.certificate_client import CertificateClient
51+
from sap_cloud_sdk.destination.local_client import LocalDevDestinationClient
52+
from sap_cloud_sdk.destination.local_fragment_client import LocalDevFragmentClient
53+
from sap_cloud_sdk.destination.local_certificate_client import LocalDevCertificateClient
54+
from sap_cloud_sdk.destination._local_client_base import (
55+
DESTINATION_MOCK_FILE,
56+
FRAGMENT_MOCK_FILE,
57+
CERTIFICATE_MOCK_FILE,
58+
)
4959
from sap_cloud_sdk.destination.exceptions import (
5060
DestinationError,
5161
ClientCreationError,
@@ -56,6 +66,17 @@
5666
)
5767

5868

69+
logger = logging.getLogger(__name__)
70+
71+
72+
def _mock_file(name: str) -> str:
73+
"""Return the absolute path to a mocks/<name> file relative to the repo root."""
74+
repo_root = os.path.abspath(
75+
os.path.join(os.path.dirname(__file__), "..", "..", "..")
76+
)
77+
return os.path.join(repo_root, "mocks", name)
78+
79+
5980
def create_client(
6081
*,
6182
instance: Optional[str] = None,
@@ -78,12 +99,19 @@ def create_client(
7899
Defaults to False.
79100
80101
Returns:
81-
DestinationClient or LocalDevDestinationProvider: Client implementing the Destination interface.
102+
DestinationClient or LocalDevDestinationClient: Client implementing the Destination interface.
82103
83104
Raises:
84105
ClientCreationError: If client creation fails due to configuration or initialization issues.
85106
"""
86107
try:
108+
if os.path.isfile(_mock_file(DESTINATION_MOCK_FILE)):
109+
logger.warning(
110+
"Local mock mode active: using LocalDevDestinationClient backed by mocks/destination.json. "
111+
"This is intended for local development only and must not be used in production."
112+
)
113+
return LocalDevDestinationClient()
114+
87115
# Cloud mode via secret resolver or explicit config
88116
binding = config or load_from_env_or_mount(instance)
89117
tp = TokenProvider(binding)
@@ -118,6 +146,13 @@ def create_fragment_client(
118146
ClientCreationError: If client creation fails due to configuration or initialization issues.
119147
"""
120148
try:
149+
if os.path.isfile(_mock_file(FRAGMENT_MOCK_FILE)):
150+
logger.warning(
151+
"Local mock mode active: using LocalDevFragmentClient backed by mocks/fragments.json. "
152+
"This is intended for local development only and must not be used in production."
153+
)
154+
return LocalDevFragmentClient()
155+
121156
# Use provided config or load from environment/mount (cloud mode)
122157
binding = config or load_from_env_or_mount(instance)
123158
tp = TokenProvider(binding)
@@ -152,6 +187,13 @@ def create_certificate_client(
152187
ClientCreationError: If client creation fails due to configuration or initialization issues.
153188
"""
154189
try:
190+
if os.path.isfile(_mock_file(CERTIFICATE_MOCK_FILE)):
191+
logger.warning(
192+
"Local mock mode active: using LocalDevCertificateClient backed by mocks/certificates.json. "
193+
"This is intended for local development only and must not be used in production."
194+
)
195+
return LocalDevCertificateClient()
196+
155197
# Use provided config or load from environment/mount (cloud mode)
156198
binding = config or load_from_env_or_mount(instance)
157199
tp = TokenProvider(binding)

0 commit comments

Comments
 (0)