Skip to content

feat: add local clients for destination module#34

Merged
NicoleMGomes merged 7 commits intomainfrom
feature/local-destinations
Apr 8, 2026
Merged

feat: add local clients for destination module#34
NicoleMGomes merged 7 commits intomainfrom
feature/local-destinations

Conversation

@NicoleMGomes
Copy link
Copy Markdown
Contributor

@NicoleMGomes NicoleMGomes commented Mar 31, 2026

Description

Adds local development mode for the destination module. When a mocks/<resource>.json file is present at the repo root, the factory functions (create_client(), create_fragment_client(), create_certificate_client()) automatically return file-backed local clients that implement the same interface as the cloud clients — no credentials or network access required. Removing the mock file reverts to cloud mode with no code changes.

A shared abstract base class (LocalDevClientBase) handles JSON file I/O, thread-safe writes, and access-strategy resolution (SUBSCRIBER_ONLY, PROVIDER_ONLY, SUBSCRIBER_FIRST, PROVIDER_FIRST) for all three local clients. A WARNING-level log is emitted whenever a local client is returned so developers are aware they are not hitting the real service. mocks/ is added to .gitignore to prevent accidental commits of mock files that may contain sensitive data.

Related Issue

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Code refactoring
  • Dependency update

How to Test

  1. Clone the repo and install dependencies: uv sync --dev
  2. Create the mock files to activate local mode:
    mkdir -p mocks
    echo '{"subaccount":[],"instance":[]}' > mocks/destination.json
    echo '{"subaccount":[],"instance":[]}' > mocks/fragments.json
    echo '{"subaccount":[],"instance":[]}' > mocks/certificates.json
  3. Run the smoke scripts:
    uv run python main_destination.py
    uv run python main_certificate.py
    uv run python main_fragment.py
  4. Expected result: each script prints Client type: LocalDev<Resource>Client and completes the full create → get → update → list → delete cycle without errors or network calls.
  5. Remove the mock files and confirm create_client() falls back to cloud mode (requires CLOUD_SDK_CFG_* env vars or /etc/secrets/appfnd mount).
  6. Run unit tests: uv run pytest tests/destination/unit/ -v

Checklist

  • I have read the Contributing Guidelines
  • I have verified that my changes solve the issue
  • I have added/updated automated tests to cover my changes
  • All tests pass locally
  • I have verified that my code follows the Code Guidelines
  • I have updated documentation (if applicable)
  • I have added type hints for all public APIs
  • My code does not contain sensitive information (credentials, tokens, etc.)
  • I have followed Conventional Commits for commit messages

Breaking Changes

None. Local mode is additive — the factory functions behave exactly as before when no mock files are present.

Additional Notes

  • Mock file format: {"subaccount": [...], "instance": [...]}. Subaccount entries without a "tenant" field are provider entries; entries with "tenant" are subscriber-specific.
  • The detection is based on file presence at <repo_root>/mocks/<resource>.json. This makes local mode opt-in at the filesystem level with no environment variable or code change required to toggle it.
  • mocks/ is gitignored to avoid accidental commits — mock files may contain local URLs, certificate content, or other sensitive data.
  • New unit tests cover all four access strategies, both scopes (instance / subaccount), conflict (409) and not-found (404) error cases, and the factory auto-detection logic in test_init.py.

@NicoleMGomes NicoleMGomes changed the title Add local clients for destination module feat: add local clients for destination module Mar 31, 2026
@NicoleMGomes NicoleMGomes force-pushed the feature/local-destinations branch from f958422 to fcaa14a Compare April 1, 2026 12:00
@NicoleMGomes NicoleMGomes marked this pull request as ready for review April 1, 2026 18:03
@NicoleMGomes NicoleMGomes requested a review from a team as a code owner April 1, 2026 18:03
Copy link
Copy Markdown
Contributor

@LucasAlvesSoares LucasAlvesSoares left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

img

@NicoleMGomes NicoleMGomes force-pushed the feature/local-destinations branch from 911a503 to 108a8fc Compare April 8, 2026 18:25
@NicoleMGomes NicoleMGomes merged commit 0aa3cf7 into main Apr 8, 2026
10 checks passed
@NicoleMGomes NicoleMGomes deleted the feature/local-destinations branch April 8, 2026 21:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants