Skip to content

Commit

Permalink
fix: prepare gcp credentials
Browse files Browse the repository at this point in the history
  • Loading branch information
TanookiVerde committed Jul 22, 2024
1 parent 24b0740 commit c224639
Showing 1 changed file with 13 additions and 0 deletions.
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

0 comments on commit c224639

Please sign in to comment.