Skip to content

Commit

Permalink
lazy import for upload providers (#342)
Browse files Browse the repository at this point in the history
Signed-off-by: Rafał Safin <[email protected]>
Co-authored-by: Rafał Safin <[email protected]>
  • Loading branch information
rafsaf and Rafał Safin authored Dec 6, 2024
1 parent f420d69 commit 810c614
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
4 changes: 2 additions & 2 deletions ogion/upload_providers/azure.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
from pathlib import Path
from typing import override

from azure.storage.blob import BlobServiceClient

from ogion import config, core
from ogion.models.upload_provider_models import AzureProviderModel
from ogion.upload_providers.base_provider import BaseUploadProvider
Expand All @@ -18,6 +16,8 @@ class UploadProviderAzure(BaseUploadProvider):
"""Azure blob storage for storing backups"""

def __init__(self, target_provider: AzureProviderModel) -> None:
from azure.storage.blob import BlobServiceClient

self.container_name = target_provider.container_name

blob_service_client = BlobServiceClient.from_connection_string(
Expand Down
8 changes: 4 additions & 4 deletions ogion/upload_providers/google_cloud_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@
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
from ogion.upload_providers.base_provider import BaseUploadProvider
Expand All @@ -23,6 +19,10 @@ class UploadProviderGCS(BaseUploadProvider):
"""GCS bucket for storing backups"""

def __init__(self, target_provider: GCSProviderModel) -> None:
import google.cloud.storage as cloud_storage
from google.auth.credentials import AnonymousCredentials
from google.oauth2 import service_account

service_account_bytes = base64.b64decode(
target_provider.service_account_base64.get_secret_value()
)
Expand Down
7 changes: 4 additions & 3 deletions ogion/upload_providers/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
from pathlib import Path
from typing import override

from minio import Minio
from minio.deleteobjects import DeleteObject

from ogion import config, core
from ogion.models.upload_provider_models import S3ProviderModel
from ogion.upload_providers.base_provider import BaseUploadProvider
Expand All @@ -19,6 +16,8 @@ class UploadProviderS3(BaseUploadProvider):
"""S3 compatibile storage bucket for storing backups"""

def __init__(self, target_provider: S3ProviderModel) -> None:
from minio import Minio

self.bucket_upload_path = target_provider.bucket_upload_path
self.max_bandwidth = target_provider.max_bandwidth

Expand Down Expand Up @@ -82,6 +81,8 @@ def download_backup(self, path: str) -> Path:
def clean(
self, backup_file: Path, max_backups: int, min_retention_days: int
) -> None:
from minio.deleteobjects import DeleteObject

for backup_path in backup_file.parent.iterdir():
core.remove_path(backup_path)
log.info("removed %s from local disk", backup_path)
Expand Down

0 comments on commit 810c614

Please sign in to comment.