-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Firestore Storage class for configs (#11)
* Implemented a new Firestore storage class for storing configs. * Make env vars optional --------- Co-authored-by: Guilherme Parpinelli <[email protected]>
- Loading branch information
1 parent
a8e1a96
commit 304ba78
Showing
8 changed files
with
552 additions
and
13 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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,35 @@ | ||
import json | ||
from typing import Any | ||
|
||
import firebase_admin | ||
from firebase_admin import credentials, firestore | ||
|
||
from nalgonda.persistence.agency_config_storage_interface import AgencyConfigStorageInterface | ||
from nalgonda.settings import settings | ||
|
||
# Initialize FireStore | ||
if settings.google_credentials: | ||
cred_json = json.loads(settings.google_credentials) | ||
cred = credentials.Certificate(cred_json) | ||
firebase_admin.initialize_app(cred) | ||
|
||
|
||
class AgencyConfigFirestoreStorage(AgencyConfigStorageInterface): | ||
def __init__(self, agency_id: str): | ||
self.db = firestore.client() | ||
self.agency_id = agency_id | ||
self.collection_name = "agency_configs" | ||
self.document = self.db.collection(self.collection_name).document(agency_id) | ||
|
||
def __enter__(self): | ||
return self | ||
|
||
def __exit__(self, exc_type, exc_val, exc_tb): | ||
# No special action needed on exiting the context. | ||
pass | ||
|
||
def load(self): | ||
return self.document.get().to_dict() | ||
|
||
def save(self, data: dict[str, Any]): | ||
self.document.set(data) |
This file contains 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
This file contains 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
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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