2222
2323from __future__ import annotations
2424
25+ import logging
26+ import os
2527from typing import Optional
2628
2729from sap_cloud_sdk .destination ._models import (
4648from sap_cloud_sdk .destination .client import DestinationClient
4749from sap_cloud_sdk .destination .fragment_client import FragmentClient
4850from 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+ )
4959from sap_cloud_sdk .destination .exceptions import (
5060 DestinationError ,
5161 ClientCreationError ,
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+
5980def 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