-
Notifications
You must be signed in to change notification settings - Fork 353
feat(dataconnect): Implemented Data Connect service client and comprehensive test suite #955
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mk2023
wants to merge
5
commits into
wine
Choose a base branch
from
prosecco
base: wine
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+431
−0
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
950f37d
feat(fdc): Added unit tests for Data Connect client factory and _Data…
mk2023 23ca2b0
Testing ConnectorConfig, client function, and service
mk2023 84e097e
refactor(dataconnect): Addressed code review feedback and standardize…
mk2023 4febd16
feat(dataconnect): Implemented foundational Data Connect client and s…
mk2023 aa61847
chore(dataconnect): Standardized test suite formatting to achieve 10.…
mk2023 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| """Firebase Data Connect module. | ||
|
|
||
| This module contains utilities for accessing Firebase Data Connect services associated with | ||
| Firebase apps. | ||
| """ | ||
|
|
||
| from dataclasses import dataclass | ||
| from typing import Dict, Optional | ||
|
|
||
| from firebase_admin import _utils, App | ||
|
|
||
| __all__ = ['ConnectorConfig', 'DataConnect', 'client'] | ||
|
|
||
| _DATA_CONNECT_ATTRIBUTE = '_data_connect_service' | ||
|
|
||
| @dataclass(frozen=True) | ||
| class ConnectorConfig: | ||
| """A configuration object for DataConnect. | ||
|
|
||
| Attributes: | ||
| service_id: A string representing the Google Cloud project ID of the service. | ||
| location: A string representing the region of the service. | ||
| connector: A string representing the name of the connector. | ||
| """ | ||
|
|
||
| service_id: str | ||
| location: str | ||
| connector: str | ||
|
|
||
| def __post_init__(self): | ||
| if not isinstance(self.service_id, str): | ||
| raise ValueError("service_id must be a string") | ||
| if not self.service_id: | ||
| raise ValueError("service_id cannot be empty") | ||
| if not isinstance(self.location, str): | ||
| raise ValueError("location must be a string") | ||
| if not self.location: | ||
| raise ValueError("location cannot be empty") | ||
| if not isinstance(self.connector, str): | ||
| raise ValueError("connector must be a string") | ||
| if not self.connector: | ||
| raise ValueError("connector cannot be empty") | ||
|
|
||
|
|
||
| class DataConnect: | ||
|
mk2023 marked this conversation as resolved.
|
||
| """Represents a Firebase Data Connect client instance. | ||
| This client provides access to the Firebase Data Connect service | ||
| for a specific Firebase app and connector configuration. | ||
|
|
||
| Attributes: | ||
| app: The Firebase App instance for this client. | ||
| config: The ConnectorConfig object specifying the service ID, location, and connector name. | ||
| """ | ||
| def __init__(self, app: App, config: ConnectorConfig) -> None: | ||
| """Initializes a DataConnect client instance. """ | ||
| self._app: App = app | ||
| self._config = config | ||
|
mk2023 marked this conversation as resolved.
|
||
|
|
||
| @property | ||
| def app(self) -> App: | ||
| return self._app | ||
|
|
||
| @property | ||
| def config(self) -> ConnectorConfig: | ||
| return self._config | ||
|
|
||
|
|
||
| class _DataConnectService: | ||
| """Service that maintains a collection of DataConnect clients.""" | ||
|
|
||
| def __init__(self, app: App) -> None: | ||
| self._app: App = app | ||
| self._clients: Dict[ConnectorConfig, DataConnect] = {} | ||
|
|
||
| def get_client(self, config: ConnectorConfig) -> DataConnect: | ||
| """Creates a client based on the ConnectorConfig. These clients are cached.""" | ||
| if not isinstance(config, ConnectorConfig): | ||
| raise ValueError("Config must be of type firebase_admin.dataconnect.ConnectorConfig") | ||
| if config not in self._clients: | ||
| self._clients[config] = DataConnect(app=self._app, config=config) | ||
| return self._clients[config] | ||
|
|
||
|
|
||
| def client(config: ConnectorConfig, app: Optional[App] = None) -> DataConnect: | ||
| """Returns a DataConnect client for the specified configuration.""" | ||
| if not isinstance(config, ConnectorConfig): | ||
| raise ValueError("Config must be of type firebase_admin.dataconnect.ConnectorConfig") | ||
|
|
||
| if app is not None and not isinstance(app, App): | ||
| raise ValueError("App must be of type firebase_admin.App") | ||
|
|
||
| # must check whether app has a _DataConnectService attached to it yet | ||
| dc_service = _utils.get_app_service(app, _DATA_CONNECT_ATTRIBUTE, _DataConnectService) | ||
|
|
||
| return dc_service.get_client(config) | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.