-
Notifications
You must be signed in to change notification settings - Fork 354
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
+457
−0
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
e701593
feat(fdc): Added unit tests for Data Connect client factory and _Data…
mk2023 d1f6af4
Testing ConnectorConfig, client function, and service
mk2023 83fc0db
refactor(dataconnect): Addressed code review feedback and standardize…
mk2023 5f677e5
feat(dataconnect): Implemented foundational Data Connect client and s…
mk2023 82fe3f4
chore(dataconnect): Standardized test suite formatting to achieve 10.…
mk2023 f2b87ec
refactor(dataconnect): Addressed code review feedback and optimized t…
mk2023 572194e
chore(fdc): Updated documentation and moved integration tests
mk2023 dcda193
refactor(fdc): Returned TestDataConnectServiceIntegration to tests/te…
mk2023 66885ad
test(fdc): Renamed integration test class to TestDataConnectServiceWo…
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,124 @@ | ||
| # Copyright 2026 Google Inc. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| """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' | ||
|
|
||
| @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") | ||
|
mk2023 marked this conversation as resolved.
|
||
|
|
||
|
|
||
| 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 | ||
|
mk2023 marked this conversation as resolved.
|
||
| 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. | ||
|
|
||
| This function does not make any RPC calls. | ||
|
|
||
| Args: | ||
| config: A ConnectorConfig instance specifying the service ID, location, | ||
| and connector name. | ||
| app: An App instance (optional). Defaults to the default Firebase App. | ||
|
|
||
| Returns: | ||
| DataConnect: A handle to the specified DataConnect client instance. | ||
|
|
||
| Raises: | ||
| ValueError: If config argument is not an instance of ConnectorConfig, or if | ||
| app is an invalid instance of App. | ||
| """ | ||
|
|
||
| if not isinstance(config, ConnectorConfig): | ||
| raise ValueError("Config must be of type firebase_admin.dataconnect.ConnectorConfig") | ||
|
|
||
| # 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.