From 7443c5cbe5262ce92d33f561a9fa5e1c96fd7b56 Mon Sep 17 00:00:00 2001 From: Sanju Date: Wed, 16 Apr 2025 12:14:23 +0200 Subject: [PATCH 1/2] add add-base64-credentials-option --- docs/supported-sources/google_analytics.md | 7 ++++++- ingestr/src/sources.py | 17 ++++++++++++----- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/docs/supported-sources/google_analytics.md b/docs/supported-sources/google_analytics.md index 80799161d..2b8f13bfa 100644 --- a/docs/supported-sources/google_analytics.md +++ b/docs/supported-sources/google_analytics.md @@ -9,10 +9,15 @@ The URI format for Google Analytics is as follows: ```plaintext googleanalytics://?credentials_path=/path/to/service/account.json&property_id= ``` +Alternatively, you can use base64 encoded credentials: + +``` +googleanalytics://?credentials_base64=&property_id= +``` URI parameters: - `credentials_path`: The path to the service account JSON file. -- `property_id`: It is a unique number that identifies a particular property on Google Analytics. [Follow this guide](https://developers.google.com/analytics/devguides/reporting/data/v1/property-id#what_is_my_property_id) if you don't know your property ID. +- `property_id`: It is a unique number that identifies a particular property on Google Analytics. [Follow this guide](https://developers.google.com/analytics/devguides/reporting/data/v1/property-id#what_is_my_property_id) to know more about property ID. ## Setting up an Google Analytics Integration Google Analytics requires a few steps to set up an integration, please follow the guide dltHub [has built here](https://dlthub.com/docs/dlt-ecosystem/verified-sources/google_analytics#grab-google-service-account-credentials). Once you complete the guide, you should have an `.json` file and `project_id`. diff --git a/ingestr/src/sources.py b/ingestr/src/sources.py index e20e2ec75..17ccb1c4f 100644 --- a/ingestr/src/sources.py +++ b/ingestr/src/sources.py @@ -1398,13 +1398,20 @@ def dlt_source(self, uri: str, table: str, **kwargs): parse_uri = urlparse(uri) source_fields = parse_qs(parse_uri.query) cred_path = source_fields.get("credentials_path") + print(f"cred_path: {cred_path}") + cred_base64 = source_fields.get("credentials_base64") - if not cred_path: - raise ValueError("credentials_path is required to connect Google Analytics") - credentials = {} + if not cred_path and not cred_base64: + raise ValueError("credentials_path or credentials_base64 is required to connect Google Analytics") - with open(cred_path[0], "r") as f: - credentials = json.load(f) + credentials = {} + if cred_path: + with open(cred_path[0], "r") as f: + credentials = json.load(f) + elif cred_base64: + credentials = json.loads( + base64.b64decode(cred_base64[0]).decode("utf-8") + ) property_id = source_fields.get("property_id") if not property_id: From fd5f6a58ab273f3b482267add1adcb7de9be0e15 Mon Sep 17 00:00:00 2001 From: Sanju Date: Wed, 16 Apr 2025 12:17:30 +0200 Subject: [PATCH 2/2] remove log --- ingestr/src/sources.py | 1 - 1 file changed, 1 deletion(-) diff --git a/ingestr/src/sources.py b/ingestr/src/sources.py index 17ccb1c4f..824de5e43 100644 --- a/ingestr/src/sources.py +++ b/ingestr/src/sources.py @@ -1398,7 +1398,6 @@ def dlt_source(self, uri: str, table: str, **kwargs): parse_uri = urlparse(uri) source_fields = parse_qs(parse_uri.query) cred_path = source_fields.get("credentials_path") - print(f"cred_path: {cred_path}") cred_base64 = source_fields.get("credentials_base64") if not cred_path and not cred_base64: