|
| 1 | +from typing import Literal, cast |
| 2 | + |
1 | 3 | from shared.config import get_config
|
2 |
| -from shared.rollouts.features import USE_MINIO, USE_NEW_MINIO |
3 |
| -from shared.storage.aws import AWSStorageService |
| 4 | +from shared.rollouts.features import NEW_MINIO |
4 | 5 | from shared.storage.base import BaseStorageService
|
5 |
| -from shared.storage.fallback import StorageWithFallbackService |
6 |
| -from shared.storage.gcp import GCPStorageService |
7 | 6 | from shared.storage.minio import MinioStorageService
|
8 |
| -from shared.storage.new_minio import NewMinioStorageService |
9 |
| - |
10 |
| -_storage_service_cache: dict[str, BaseStorageService] = {} |
11 | 7 |
|
12 | 8 |
|
13 | 9 | def get_appropriate_storage_service(
|
14 | 10 | repoid: int | None = None,
|
15 | 11 | force_minio=False,
|
16 | 12 | ) -> BaseStorageService:
|
17 |
| - chosen_storage: str = get_config("services", "chosen_storage", default="minio") # type: ignore |
18 |
| - if force_minio: |
19 |
| - chosen_storage = "minio" |
20 |
| - |
| 13 | + minio_config = get_config("services", "minio", default={}) |
21 | 14 | if repoid:
|
22 |
| - if USE_MINIO.check_value(repoid, default=False): |
23 |
| - chosen_storage = "minio" |
24 |
| - |
25 |
| - if USE_NEW_MINIO.check_value(repoid, default=False): |
26 |
| - chosen_storage = "new_minio" |
27 |
| - |
28 |
| - if chosen_storage not in _storage_service_cache: |
29 |
| - _storage_service_cache[chosen_storage] = ( |
30 |
| - _get_appropriate_storage_service_given_storage(chosen_storage) |
| 15 | + new_minio_mode = cast( |
| 16 | + Literal["read", "write"] | None, |
| 17 | + NEW_MINIO.check_value(repoid, default=None), # type: ignore |
| 18 | + ) |
| 19 | + return MinioStorageService( |
| 20 | + minio_config, |
| 21 | + new_mode=new_minio_mode, |
31 | 22 | )
|
32 |
| - |
33 |
| - return _storage_service_cache[chosen_storage] |
34 |
| - |
35 |
| - |
36 |
| -def _get_appropriate_storage_service_given_storage( |
37 |
| - chosen_storage: str, |
38 |
| -) -> BaseStorageService: |
39 |
| - if chosen_storage == "gcp": |
40 |
| - gcp_config = get_config("services", "gcp", default={}) |
41 |
| - return GCPStorageService(gcp_config) |
42 |
| - elif chosen_storage == "aws": |
43 |
| - aws_config = get_config("services", "aws", default={}) |
44 |
| - return AWSStorageService(aws_config) |
45 |
| - elif chosen_storage == "gcp_with_fallback": |
46 |
| - gcp_config = get_config("services", "gcp", default={}) |
47 |
| - gcp_service = GCPStorageService(gcp_config) |
48 |
| - aws_config = get_config("services", "aws", default={}) |
49 |
| - aws_service = AWSStorageService(aws_config) |
50 |
| - return StorageWithFallbackService(gcp_service, aws_service) |
51 |
| - elif chosen_storage == "new_minio": |
52 |
| - minio_config = get_config("services", "minio", default={}) |
53 |
| - return NewMinioStorageService(minio_config) |
54 | 23 | else:
|
55 |
| - minio_config = get_config("services", "minio", default={}) |
56 | 24 | return MinioStorageService(minio_config)
|
0 commit comments