Skip to content

Commit

Permalink
Merge pull request #334 from rafsaf/google-creds-problem
Browse files Browse the repository at this point in the history
fix problem with google credentials
  • Loading branch information
rafsaf authored Oct 26, 2024
2 parents a9b5ccf + d0d240e commit 533fd73
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
20 changes: 10 additions & 10 deletions ogion/upload_providers/google_cloud_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
# GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt)

import base64
import json
import logging
import os
from pathlib import Path
from typing import override

import google.cloud.storage as cloud_storage
from google.auth.credentials import AnonymousCredentials
from google.oauth2 import service_account

from ogion import config, core
from ogion.models.upload_provider_models import GCSProviderModel
Expand All @@ -24,16 +26,14 @@ def __init__(self, target_provider: GCSProviderModel) -> None:
service_account_bytes = base64.b64decode(
target_provider.service_account_base64.get_secret_value()
)
sa_path = config.CONST_CONFIG_FOLDER_PATH / "google_auth.json"
with open(sa_path, "wb") as f:
f.write(service_account_bytes)
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = str(sa_path)

self.storage_client = cloud_storage.Client(
credentials=AnonymousCredentials() # type: ignore[no-untyped-call]
if os.environ.get("STORAGE_EMULATOR_HOST")
else None # pragma: no cover
)

if os.environ.get("STORAGE_EMULATOR_HOST"):
creds = AnonymousCredentials() # type: ignore[no-untyped-call]
else: # pragma: no cover
sa = json.loads(service_account_bytes.decode())
creds = service_account.Credentials.from_service_account_info(sa) # type: ignore[no-untyped-call]

self.storage_client = cloud_storage.Client(credentials=creds)
self.bucket = self.storage_client.bucket(target_provider.bucket_name)
self.bucket_upload_path = target_provider.bucket_upload_path
self.chunk_size_bytes = target_provider.chunk_size_mb * 1024 * 1024
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description = "A tool for performing scheduled database backups and transferring
license = "GNU GPLv3"
name = "ogion"
package-mode = false
version = "7.0"
version = "7.1"

[tool.poetry.dependencies]
python = "^3.13"
Expand Down

0 comments on commit 533fd73

Please sign in to comment.