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

lazy import for upload providers #342

Merged
merged 1 commit into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
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
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
Loading