Skip to content
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

fix: prepare gcp credentials #154

Merged
merged 1 commit into from
Jul 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions api/app/datalake.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import uuid
import glob
from typing import Optional
import base64

import pandas as pd
import basedosdados as bd
Expand Down Expand Up @@ -32,6 +33,16 @@ def __init__(

self._base_path = os.path.join(os.getcwd(), "/files")

def _prepare_gcp_credential(self) -> None:
base64_credential = os.environ["GCP_JSON_CREDENTIAL"]

with open("/tmp/credentials.json", "wb") as f:
f.write(base64.b64decode(base64_credential))

os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "/tmp/credentials.json"
return


def _split_dataframe_per_day(
self,
df: pd.DataFrame,
Expand Down Expand Up @@ -79,6 +90,8 @@ def _upload_file(
table_id: str,
source_format: str = "parquet"
) -> None:
self._prepare_gcp_credential()

tb = bd.Table(dataset_id=dataset_id, table_id=table_id)
table_staging = f"{tb.table_full_name['staging']}"

Expand Down
Loading