maleo-foundation 0.1.82__py3-none-any.whl → 0.1.83__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- maleo_foundation/managers/client/google/base.py +14 -13
- maleo_foundation/managers/client/google/secret.py +42 -14
- maleo_foundation/managers/client/google/storage.py +6 -2
- maleo_foundation/managers/service.py +53 -64
- maleo_foundation/utils/loaders/__init__.py +6 -4
- maleo_foundation/utils/loaders/credential/__init__.py +5 -0
- maleo_foundation/utils/loaders/credential/google.py +25 -0
- maleo_foundation/utils/loaders/key/__init__.py +1 -1
- maleo_foundation/utils/loaders/yaml.py +1 -1
- maleo_foundation/utils/logging.py +7 -13
- {maleo_foundation-0.1.82.dist-info → maleo_foundation-0.1.83.dist-info}/METADATA +1 -1
- {maleo_foundation-0.1.82.dist-info → maleo_foundation-0.1.83.dist-info}/RECORD +14 -12
- {maleo_foundation-0.1.82.dist-info → maleo_foundation-0.1.83.dist-info}/WHEEL +1 -1
- {maleo_foundation-0.1.82.dist-info → maleo_foundation-0.1.83.dist-info}/top_level.txt +0 -0
@@ -1,8 +1,9 @@
|
|
1
|
-
import
|
2
|
-
from
|
3
|
-
from
|
1
|
+
from google.oauth2.service_account import Credentials
|
2
|
+
from pathlib import Path
|
3
|
+
from typing import Optional, Union
|
4
4
|
from maleo_foundation.types import BaseTypes
|
5
5
|
from maleo_foundation.managers.client.base import ClientManager
|
6
|
+
from maleo_foundation.utils.loaders.credential.google import GoogleCredentialsLoader
|
6
7
|
from maleo_foundation.utils.logging import SimpleConfig
|
7
8
|
|
8
9
|
class GoogleClientManager(ClientManager):
|
@@ -12,22 +13,22 @@ class GoogleClientManager(ClientManager):
|
|
12
13
|
name:str,
|
13
14
|
log_config:SimpleConfig,
|
14
15
|
service_key:BaseTypes.OptionalString=None,
|
15
|
-
|
16
|
+
credentials:Optional[Credentials]=None,
|
17
|
+
credentials_path:Optional[Union[Path, str]]=None
|
16
18
|
) -> None:
|
17
19
|
super().__init__(key, name, log_config, service_key)
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
raise ValueError(f"Failed to initialize credentials: {str(e)}")
|
20
|
+
if (credentials is not None and credentials_path is not None) or (credentials is None and credentials_path is None):
|
21
|
+
raise ValueError("Only either 'credentials' or 'credentials_path' can be passed as parameter")
|
22
|
+
|
23
|
+
if credentials is not None:
|
24
|
+
self._credentials = credentials
|
25
|
+
else:
|
26
|
+
self._credentials = GoogleCredentialsLoader(credentials_path)
|
26
27
|
|
27
28
|
self._project_id = self._credentials.project_id
|
28
29
|
|
29
30
|
@property
|
30
|
-
def credentials(self) ->
|
31
|
+
def credentials(self) -> Credentials:
|
31
32
|
return self._credentials
|
32
33
|
|
33
34
|
@property
|
@@ -1,7 +1,9 @@
|
|
1
1
|
from google.api_core import retry
|
2
2
|
from google.api_core.exceptions import NotFound
|
3
3
|
from google.cloud import secretmanager
|
4
|
-
from
|
4
|
+
from google.oauth2.service_account import Credentials
|
5
|
+
from pathlib import Path
|
6
|
+
from typing import Optional, Union
|
5
7
|
from maleo_foundation.types import BaseTypes
|
6
8
|
from maleo_foundation.utils.logging import SimpleConfig
|
7
9
|
from .base import GoogleClientManager
|
@@ -11,11 +13,12 @@ class GoogleSecretManager(GoogleClientManager):
|
|
11
13
|
self,
|
12
14
|
log_config:SimpleConfig,
|
13
15
|
service_key:BaseTypes.OptionalString=None,
|
14
|
-
|
16
|
+
credentials:Optional[Credentials]=None,
|
17
|
+
credentials_path:Optional[Union[Path, str]]=None
|
15
18
|
) -> None:
|
16
19
|
key = "google-secret-manager"
|
17
20
|
name = "GoogleSecretManager"
|
18
|
-
super().__init__(key, name, log_config, service_key, credentials_path)
|
21
|
+
super().__init__(key, name, log_config, service_key, credentials, credentials_path)
|
19
22
|
self._client = secretmanager.SecretManagerServiceClient(credentials=self._credentials)
|
20
23
|
self._logger.info("Client manager initialized successfully")
|
21
24
|
|
@@ -30,34 +33,58 @@ class GoogleSecretManager(GoogleClientManager):
|
|
30
33
|
self._logger.info("Client manager disposed successfully")
|
31
34
|
|
32
35
|
@retry.Retry(predicate=retry.if_exception_type(Exception), timeout=5)
|
33
|
-
def get(self, name:str, version:str = "latest") ->
|
36
|
+
def get(self, name:str, version:str = "latest") -> str:
|
37
|
+
#* Check if secret exists
|
38
|
+
secret_name = f"projects/{self._project_id}/secrets/{name}"
|
34
39
|
try:
|
35
|
-
|
36
|
-
|
40
|
+
request = secretmanager.GetSecretRequest(name=secret_name)
|
41
|
+
self._client.get_secret(request=request)
|
42
|
+
except NotFound:
|
43
|
+
self._logger.error("Secret '%s' did not exist", name, exc_info=True)
|
44
|
+
raise
|
45
|
+
except Exception:
|
46
|
+
self._logger.error("Exception raised while checking secret '%s' existence", name, exc_info=True)
|
47
|
+
raise
|
48
|
+
|
49
|
+
#* Check if secret's version exists
|
50
|
+
secret_version_name = f"{secret_name}/versions/{version}"
|
51
|
+
try:
|
52
|
+
request = secretmanager.GetSecretVersionRequest(name=secret_version_name)
|
53
|
+
self._client.get_secret_version(request=request)
|
54
|
+
except NotFound:
|
55
|
+
self._logger.error("Secret '%s' with version '%s' did not exist", name, version, exc_info=True)
|
56
|
+
raise
|
57
|
+
except Exception:
|
58
|
+
self._logger.error("Exception raised while checking secret '%s' with version '%s' existence", name, version, exc_info=True)
|
59
|
+
raise
|
60
|
+
|
61
|
+
#* Access secret's version
|
62
|
+
try:
|
63
|
+
request = secretmanager.AccessSecretVersionRequest(name=secret_version_name)
|
37
64
|
response = self._client.access_secret_version(request=request)
|
38
65
|
self._logger.info("Successfully retrieved secret '%s' with version '%s'", name, version)
|
39
66
|
return response.payload.data.decode()
|
40
67
|
except Exception:
|
41
|
-
self._logger.error("Exception occured
|
42
|
-
|
68
|
+
self._logger.error("Exception occured while retrieving secret '%s' with version '%s'", name, version, exc_info=True)
|
69
|
+
raise
|
43
70
|
|
44
71
|
@retry.Retry(predicate=retry.if_exception_type(Exception), timeout=5)
|
45
|
-
def create(self, name:str, data:str) ->
|
72
|
+
def create(self, name:str, data:str) -> str:
|
46
73
|
parent = f"projects/{self._project_id}"
|
47
74
|
secret_path = f"{parent}/secrets/{name}"
|
48
75
|
try:
|
49
76
|
#* Check if the secret already exists
|
50
77
|
request = secretmanager.GetSecretRequest(name=secret_path)
|
51
78
|
self._client.get_secret(request=request)
|
52
|
-
|
53
79
|
except NotFound:
|
54
80
|
#* Secret does not exist, create it first
|
55
81
|
try:
|
56
82
|
secret = secretmanager.Secret(name=name, replication={"automatic": {}})
|
57
83
|
request = secretmanager.CreateSecretRequest(parent=parent, secret_id=name, secret=secret)
|
58
84
|
self._client.create_secret(request=request)
|
59
|
-
except Exception
|
60
|
-
|
85
|
+
except Exception:
|
86
|
+
self._logger.error("Exception occured while creating secret '%s'", name)
|
87
|
+
raise
|
61
88
|
|
62
89
|
#* Add a new secret version
|
63
90
|
try:
|
@@ -65,5 +92,6 @@ class GoogleSecretManager(GoogleClientManager):
|
|
65
92
|
request = secretmanager.AddSecretVersionRequest(parent=secret_path, payload=payload)
|
66
93
|
response = self._client.add_secret_version(request=request)
|
67
94
|
return data
|
68
|
-
except Exception
|
69
|
-
|
95
|
+
except Exception:
|
96
|
+
self._logger.error("Exception occured while adding secret '%s' version", name)
|
97
|
+
raise
|
@@ -1,6 +1,9 @@
|
|
1
1
|
import os
|
2
2
|
from datetime import timedelta
|
3
3
|
from google.cloud.storage import Bucket, Client
|
4
|
+
from google.oauth2.service_account import Credentials
|
5
|
+
from pathlib import Path
|
6
|
+
from typing import Optional, Union
|
4
7
|
from maleo_foundation.types import BaseTypes
|
5
8
|
from maleo_foundation.utils.logging import SimpleConfig
|
6
9
|
from .base import GoogleClientManager
|
@@ -10,12 +13,13 @@ class GoogleCloudStorage(GoogleClientManager):
|
|
10
13
|
self,
|
11
14
|
log_config:SimpleConfig,
|
12
15
|
service_key:BaseTypes.OptionalString=None,
|
13
|
-
|
16
|
+
credentials:Optional[Credentials]=None,
|
17
|
+
credentials_path:Optional[Union[Path, str]]=None,
|
14
18
|
bucket_name:BaseTypes.OptionalString = None
|
15
19
|
) -> None:
|
16
20
|
key = "google-cloud-storage"
|
17
21
|
name = "GoogleCloudStorage"
|
18
|
-
super().__init__(key, name, log_config, service_key, credentials_path)
|
22
|
+
super().__init__(key, name, log_config, service_key, credentials, credentials_path)
|
19
23
|
self._client = Client(credentials=self._credentials)
|
20
24
|
self._bucket_name = bucket_name or os.getenv("GCS_BUCKET_NAME")
|
21
25
|
if self._bucket_name is None:
|
@@ -1,9 +1,11 @@
|
|
1
1
|
from fastapi import FastAPI, APIRouter
|
2
2
|
from fastapi.exceptions import RequestValidationError
|
3
|
-
from
|
4
|
-
from
|
3
|
+
from google.oauth2.service_account import Credentials
|
4
|
+
from pathlib import Path
|
5
5
|
from pydantic_settings import BaseSettings
|
6
6
|
from pydantic import BaseModel, Field
|
7
|
+
from starlette.exceptions import HTTPException
|
8
|
+
from starlette.types import Lifespan, AppType
|
7
9
|
from sqlalchemy import MetaData
|
8
10
|
from typing import Optional
|
9
11
|
from maleo_foundation.client.manager import MaleoFoundationClientManager
|
@@ -16,43 +18,21 @@ from maleo_foundation.managers.client.google.secret import GoogleSecretManager
|
|
16
18
|
from maleo_foundation.managers.client.google.storage import GoogleCloudStorage
|
17
19
|
from maleo_foundation.managers.middleware import MiddlewareConfigurations, BaseMiddlewareConfigurations, CORSMiddlewareConfigurations, GeneralMiddlewareConfigurations, MiddlewareLoggers, MiddlewareManager
|
18
20
|
from maleo_foundation.utils.exceptions import BaseExceptions
|
19
|
-
from maleo_foundation.utils.loaders.json import JSONLoader
|
20
21
|
from maleo_foundation.utils.loaders.yaml import YAMLLoader
|
21
22
|
from maleo_foundation.utils.logging import SimpleConfig, ServiceLogger, MiddlewareLogger
|
22
23
|
from maleo_foundation.utils.mergers import BaseMergers
|
23
24
|
|
24
25
|
class Settings(BaseSettings):
|
25
26
|
ENVIRONMENT:BaseEnums.EnvironmentType = Field(..., description="Environment")
|
27
|
+
SERVICE_KEY:str = Field(..., description="Service's key")
|
26
28
|
GOOGLE_CREDENTIALS_PATH:str = Field("credentials/maleo-google-service-account.json", description="Internal credential's file path")
|
27
|
-
INTERNAL_CREDENTIALS_PATH:str = Field("credentials/maleo-internal-service-account.json", description="Internal credential's file path")
|
28
29
|
STATIC_CONFIGURATIONS_PATH:str = Field("configs/static.yaml", description="Maleo's static configurations path")
|
29
30
|
RUNTIME_CONFIGURATIONS_PATH:str = Field("configs/runtime.yaml", description="Service's runtime configurations path")
|
30
31
|
|
31
|
-
class
|
32
|
-
type:str = Field(..., description="Credentials type")
|
33
|
-
project_id:str = Field(..., description="Google project ID")
|
34
|
-
private_key_id:str = Field(..., description="Private key ID")
|
35
|
-
private_key:str = Field(..., description="Private key")
|
36
|
-
client_email:str = Field(..., description="Client email")
|
37
|
-
client_id:str = Field(..., description="Client ID")
|
38
|
-
auth_uri:str = Field(..., description="Authorization URI")
|
39
|
-
token_uri:str = Field(..., description="Token URI")
|
40
|
-
auth_provider_x509_cert_url:str = Field(..., description="Authorization provider x509 certificate URL")
|
41
|
-
client_x509_cert_url:str = Field(..., description="Client x509 certificate URL")
|
42
|
-
universe_domain:str = Field(..., description="Universe domains")
|
43
|
-
|
44
|
-
class InternalCredentials(BaseModel):
|
45
|
-
system_role:str = Field(..., description="System role")
|
32
|
+
class MaleoCredentials(BaseModel):
|
46
33
|
username:str = Field(..., description="Username")
|
47
34
|
email:str = Field(..., description="Email")
|
48
|
-
|
49
|
-
|
50
|
-
class Credentials(BaseModel):
|
51
|
-
google:GoogleCredentials = Field(..., description="Google's credentials")
|
52
|
-
internal:InternalCredentials = Field(..., description="Internal's credentials")
|
53
|
-
|
54
|
-
class Config:
|
55
|
-
arbitrary_types_allowed=True
|
35
|
+
password:str = Field(..., description="Password")
|
56
36
|
|
57
37
|
class MiddlewareRuntimeConfigurations(BaseModel):
|
58
38
|
base:BaseMiddlewareConfigurations = Field(..., description="Base middleware's configurations")
|
@@ -166,16 +146,14 @@ class ServiceManager:
|
|
166
146
|
#* Disable google cloud logging if environment is local
|
167
147
|
if self._settings.ENVIRONMENT == "local":
|
168
148
|
self._log_config.google_cloud_logging = None
|
169
|
-
self.
|
170
|
-
self._load_configs()
|
149
|
+
self._load_google_credentials()
|
171
150
|
self._initialize_secret_manager()
|
172
|
-
|
173
|
-
|
174
|
-
self.
|
175
|
-
self._initialize_keys()
|
151
|
+
self._load_maleo_credentials()
|
152
|
+
self._load_configs()
|
153
|
+
self._load_keys()
|
176
154
|
self._initialize_loggers()
|
177
155
|
self._initialize_db()
|
178
|
-
self._initialize_clients(
|
156
|
+
self._initialize_clients()
|
179
157
|
|
180
158
|
@property
|
181
159
|
def log_config(self) -> SimpleConfig:
|
@@ -185,44 +163,54 @@ class ServiceManager:
|
|
185
163
|
def settings(self) -> Settings:
|
186
164
|
return self._settings
|
187
165
|
|
188
|
-
def
|
189
|
-
|
190
|
-
data = JSONLoader.load(self._settings.GOOGLE_CREDENTIALS_PATH)
|
191
|
-
google = GoogleCredentials.model_validate(data)
|
192
|
-
#* Load internal credentials
|
193
|
-
data = JSONLoader.load(self._settings.INTERNAL_CREDENTIALS_PATH)
|
194
|
-
internal = InternalCredentials.model_validate(data)
|
195
|
-
self._credentials = Credentials(google=google, internal=internal)
|
166
|
+
def _load_google_credentials(self) -> None:
|
167
|
+
self._google_credentials = Credentials.from_service_account_file(self._settings.GOOGLE_CREDENTIALS_PATH)
|
196
168
|
|
197
169
|
@property
|
198
|
-
def
|
199
|
-
return self.
|
200
|
-
|
201
|
-
def _load_configs(self) -> None:
|
202
|
-
static_configurations = YAMLLoader.load(self._settings.STATIC_CONFIGURATIONS_PATH)
|
203
|
-
self._static_configs = StaticConfigurations.model_validate(static_configurations)
|
204
|
-
runtime_configurations = YAMLLoader.load(self._settings.RUNTIME_CONFIGURATIONS_PATH)
|
205
|
-
self._runtime_configs = RuntimeConfigurations.model_validate(runtime_configurations)
|
170
|
+
def google_credentials(self) -> None:
|
171
|
+
return self._google_credentials
|
206
172
|
|
207
173
|
def _initialize_secret_manager(self) -> None:
|
208
|
-
self._secret_manager = GoogleSecretManager(log_config=self._log_config, service_key=self.
|
174
|
+
self._secret_manager = GoogleSecretManager(log_config=self._log_config, service_key=self._settings.SERVICE_KEY, credentials=self._google_credentials)
|
209
175
|
|
210
176
|
@property
|
211
177
|
def secret_manager(self) -> None:
|
212
178
|
return self._secret_manager
|
213
179
|
|
214
|
-
def
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
180
|
+
def _load_maleo_credentials(self) -> None:
|
181
|
+
email = self._secret_manager.get("maleo-service-account-email")
|
182
|
+
username = self._secret_manager.get("maleo-service-account-username")
|
183
|
+
password = self._secret_manager.get("maleo-service-account-password")
|
184
|
+
self._maleo_credentials = MaleoCredentials(username=username, email=email, password=password)
|
185
|
+
|
186
|
+
@property
|
187
|
+
def maleo_credentials(self) -> Credentials:
|
188
|
+
return self._maleo_credentials
|
189
|
+
|
190
|
+
def _load_configs(self) -> None:
|
191
|
+
static_configurations_path = Path(self._settings.STATIC_CONFIGURATIONS_PATH)
|
192
|
+
if static_configurations_path.exists() and static_configurations_path.is_file():
|
193
|
+
static_configurations = YAMLLoader.load(self._settings.STATIC_CONFIGURATIONS_PATH)
|
194
|
+
else:
|
195
|
+
static_configurations = self._secret_manager.get(f"maleo-static-config-{self._settings.ENVIRONMENT}")
|
196
|
+
static_configs = StaticConfigurations.model_validate(static_configurations)
|
197
|
+
runtime_configurations_path = Path(self._settings.RUNTIME_CONFIGURATIONS_PATH)
|
198
|
+
if runtime_configurations_path.exists() and runtime_configurations_path.is_file():
|
199
|
+
runtime_configurations = YAMLLoader.load(self._settings.RUNTIME_CONFIGURATIONS_PATH)
|
200
|
+
else:
|
201
|
+
runtime_configurations = self._secret_manager.get(f"{self._settings.SERVICE_KEY}-runtime-config-{self._settings.ENVIRONMENT}")
|
202
|
+
runtime_configs = RuntimeConfigurations.model_validate(runtime_configurations)
|
203
|
+
password = self._secret_manager.get(name=f"maleo-db-password-{self._settings.ENVIRONMENT}")
|
204
|
+
host = self._secret_manager.get(name=f"maleo-db-host-{self._settings.ENVIRONMENT}")
|
205
|
+
database = DatabaseConfigurations(password=password, host=host, database=runtime_configs.database)
|
206
|
+
merged_configs = BaseMergers.deep_merge(static_configs.model_dump(), runtime_configs.model_dump(exclude={"database"}), {"database": database.model_dump()})
|
219
207
|
self._configs = Configurations.model_validate(merged_configs)
|
220
208
|
|
221
209
|
@property
|
222
210
|
def configs(self) -> Configurations:
|
223
211
|
return self._configs
|
224
212
|
|
225
|
-
def
|
213
|
+
def _load_keys(self) -> None:
|
226
214
|
password = self._secret_manager.get(name="maleo-key-password")
|
227
215
|
private = self._secret_manager.get(name="maleo-private-key")
|
228
216
|
public = self._secret_manager.get(name="maleo-public-key")
|
@@ -253,11 +241,12 @@ class ServiceManager:
|
|
253
241
|
def database(self) -> DatabaseManager:
|
254
242
|
return self._database
|
255
243
|
|
256
|
-
def _initialize_clients(self
|
244
|
+
def _initialize_clients(self) -> None:
|
257
245
|
secret = self._secret_manager
|
258
|
-
|
246
|
+
environment = BaseEnums.EnvironmentType.STAGING if self._settings.ENVIRONMENT == BaseEnums.EnvironmentType.LOCAL else self._settings.ENVIRONMENT
|
247
|
+
storage = GoogleCloudStorage(log_config=self._log_config, service_key=self._settings.SERVICE_KEY, bucket_name=f"maleo-suite-{environment}", credentials=self._google_credentials)
|
259
248
|
self._google_clients = GoogleClientManagers(secret=secret, storage=storage)
|
260
|
-
foundation = MaleoFoundationClientManager(log_config=self._log_config, service_key=self.
|
249
|
+
foundation = MaleoFoundationClientManager(log_config=self._log_config, service_key=self._settings.SERVICE_KEY)
|
261
250
|
self._maleo_clients = MaleoClientManagers(foundation=foundation)
|
262
251
|
self._clients = ClientManagers(google=self._google_clients, maleo=self._maleo_clients)
|
263
252
|
|
@@ -276,10 +265,10 @@ class ServiceManager:
|
|
276
265
|
@property
|
277
266
|
def token(self) -> str:
|
278
267
|
payload = MaleoFoundationTokenGeneralTransfers.BaseEncodePayload(
|
279
|
-
sr=
|
280
|
-
u_u=self.
|
281
|
-
u_e=self.
|
282
|
-
u_ut=
|
268
|
+
sr="administrator",
|
269
|
+
u_u=self._maleo_credentials.username,
|
270
|
+
u_e=self._maleo_credentials.email,
|
271
|
+
u_ut="service"
|
283
272
|
)
|
284
273
|
parameters = MaleoFoundationTokenParametersTransfers.Encode(key=self._keys.private, password=self._keys.password, payload=payload)
|
285
274
|
result = self._clients.maleo.foundation.services.token.encode(parameters=parameters)
|
@@ -1,9 +1,11 @@
|
|
1
1
|
from __future__ import annotations
|
2
|
+
from .credential import CredentialLoaders
|
2
3
|
from .json import JSONLoader
|
3
|
-
from .key import
|
4
|
+
from .key import KeyLoaders
|
4
5
|
from .yaml import YAMLLoader
|
5
6
|
|
6
7
|
class BaseLoaders:
|
7
|
-
|
8
|
-
|
9
|
-
|
8
|
+
Credential = CredentialLoaders
|
9
|
+
JSON = JSONLoader
|
10
|
+
Key = KeyLoaders
|
11
|
+
YAML = YAMLLoader
|
@@ -0,0 +1,25 @@
|
|
1
|
+
import os
|
2
|
+
from google.auth import default
|
3
|
+
from google.oauth2.service_account import Credentials
|
4
|
+
from pathlib import Path
|
5
|
+
from typing import Optional, Type, Union
|
6
|
+
|
7
|
+
class GoogleCredentialsLoader:
|
8
|
+
@staticmethod
|
9
|
+
def load(credentials_path:Optional[Union[Path, str]] = None) -> Credentials:
|
10
|
+
if not isinstance(credentials_path, (Path, Type[None], str)):
|
11
|
+
raise TypeError("Google credentials type can only be 'Path', 'str', or 'None'")
|
12
|
+
if credentials_path is None:
|
13
|
+
credentials_path = os.getenv("GOOGLE_CREDENTIALS_PATH")
|
14
|
+
else:
|
15
|
+
credentials_path = credentials_path
|
16
|
+
try:
|
17
|
+
if credentials_path is not None:
|
18
|
+
credentials_path = Path(credentials_path)
|
19
|
+
if credentials_path.exists() or credentials_path.is_file():
|
20
|
+
credentials = Credentials.from_service_account_file(filename=str(credentials_path))
|
21
|
+
else:
|
22
|
+
credentials, _ = default()
|
23
|
+
return credentials
|
24
|
+
except Exception as e:
|
25
|
+
raise ValueError(f"Failed to initialize credentials: {str(e)}")
|
@@ -7,7 +7,7 @@ class YAMLLoader:
|
|
7
7
|
def load(path:Union[Path, str]) -> Dict:
|
8
8
|
file_path = Path(path)
|
9
9
|
|
10
|
-
if not file_path.is_file():
|
10
|
+
if not file_path.exists() or not file_path.is_file():
|
11
11
|
raise FileNotFoundError(f"File not found: {file_path}")
|
12
12
|
|
13
13
|
with file_path.open("r") as f:
|
@@ -1,30 +1,24 @@
|
|
1
1
|
import logging
|
2
2
|
import os
|
3
3
|
from datetime import datetime
|
4
|
-
from google.auth import default
|
5
4
|
from google.cloud.logging import Client
|
6
5
|
from google.cloud.logging.handlers import CloudLoggingHandler
|
7
|
-
from google.oauth2 import
|
6
|
+
from google.oauth2.service_account import Credentials
|
7
|
+
from pathlib import Path
|
8
8
|
from pydantic import BaseModel, Field
|
9
|
-
from typing import Optional
|
9
|
+
from typing import Optional, Union
|
10
10
|
from maleo_foundation.enums import BaseEnums
|
11
11
|
from maleo_foundation.types import BaseTypes
|
12
|
+
from maleo_foundation.utils.loaders.credential.google import GoogleCredentialsLoader
|
12
13
|
|
13
14
|
class GoogleCloudLogging:
|
14
|
-
def __init__(self,
|
15
|
-
|
16
|
-
try:
|
17
|
-
if google_credentials_path is not None:
|
18
|
-
self._credentials = service_account.Credentials.from_service_account_file(filename=google_credentials_path)
|
19
|
-
else:
|
20
|
-
self._credentials, _ = default()
|
21
|
-
except Exception as e:
|
22
|
-
raise ValueError(f"Failed to initialize credentials: {str(e)}")
|
15
|
+
def __init__(self, credentials_path:Optional[Union[Path, str]] = None) -> None:
|
16
|
+
self._credentials = GoogleCredentialsLoader.load(credentials_path=credentials_path)
|
23
17
|
self._client = Client(credentials=self._credentials)
|
24
18
|
self._client.setup_logging()
|
25
19
|
|
26
20
|
@property
|
27
|
-
def credentials(self) ->
|
21
|
+
def credentials(self) -> Credentials:
|
28
22
|
return self._credentials
|
29
23
|
|
30
24
|
@property
|
@@ -32,14 +32,14 @@ maleo_foundation/expanded_types/encryption/rsa.py,sha256=MuhB_DGrjnsl4t96W4pKuCt
|
|
32
32
|
maleo_foundation/managers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
33
33
|
maleo_foundation/managers/db.py,sha256=Pn5EZ-c1Hy6-BihN7KokHJWmBIt3Ty96fZ0zF-srtF4,5208
|
34
34
|
maleo_foundation/managers/middleware.py,sha256=ODIQU1Hpu-Xempjjo_VRbVtxiD5oi74mNuoWuDawRh0,4250
|
35
|
-
maleo_foundation/managers/service.py,sha256=
|
35
|
+
maleo_foundation/managers/service.py,sha256=l5YoDj5mT4B6XtAP4LDF9h93VUkKVQGrgWIZ7nsaklE,16420
|
36
36
|
maleo_foundation/managers/client/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
37
37
|
maleo_foundation/managers/client/base.py,sha256=5z9l2GN4QASF0-Lft8o5QQ3SRPXqeNZNT1S1CgaE764,4384
|
38
38
|
maleo_foundation/managers/client/maleo.py,sha256=iCM47TLL-RSQ2FkTmHVPdsb2JCd1LebMx6OJvIr4vCQ,2035
|
39
39
|
maleo_foundation/managers/client/google/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
40
|
-
maleo_foundation/managers/client/google/base.py,sha256=
|
41
|
-
maleo_foundation/managers/client/google/secret.py,sha256=
|
42
|
-
maleo_foundation/managers/client/google/storage.py,sha256=
|
40
|
+
maleo_foundation/managers/client/google/base.py,sha256=eIdd6C2BFIu4EyZ1j017VZaJn_nSTPGFftBwQmVAUDA,1366
|
41
|
+
maleo_foundation/managers/client/google/secret.py,sha256=Ski1CHYeA8vjSk2Oc2Pf4CfFrzT_RcA6NEZwza7gM7Y,4464
|
42
|
+
maleo_foundation/managers/client/google/storage.py,sha256=JFqXd9QgusT75KAWyWdin8V6BbbKcbBCrmWDpqg6i3Q,2530
|
43
43
|
maleo_foundation/middlewares/authentication.py,sha256=qg4BwJ72aHOKyo19II37bafQaV5OFvff173aKRCp54o,3359
|
44
44
|
maleo_foundation/middlewares/base.py,sha256=g4cg9gIUveK9zbjhwQtkdefhuoSlv9BUWVCFaSlOClw,13303
|
45
45
|
maleo_foundation/middlewares/cors.py,sha256=9uvBvY2N6Vxa9RP_YtESxcWo6Doi6uS0lzAG9iLY7Uc,2288
|
@@ -95,17 +95,19 @@ maleo_foundation/utils/__init__.py,sha256=SRPEVoqjZoO6W8rtF_Ti8VIangg6Auwm6eHbZM
|
|
95
95
|
maleo_foundation/utils/controller.py,sha256=ECzPzpw36zBAjKcWcDbUAhIJGbc6UpeypdUUX6ipXBg,6396
|
96
96
|
maleo_foundation/utils/exceptions.py,sha256=hstsXST24mbJLuDtAfcdC0FxMgH3IkG97A026CvaX-w,4034
|
97
97
|
maleo_foundation/utils/extractor.py,sha256=SZXVYDHWGaA-Dd1BUydwF2HHdZqexEielS4CjL0Ceng,814
|
98
|
-
maleo_foundation/utils/logging.py,sha256=
|
98
|
+
maleo_foundation/utils/logging.py,sha256=W5Fhk_xAXVqSujaY8mv3hRH4wlQSpUn4ReuMoiKcQa4,7759
|
99
99
|
maleo_foundation/utils/mergers.py,sha256=DniUu3Ot4qkYH_YSw4uD1cn9cfirum4S_Opp8fMkQwA,702
|
100
100
|
maleo_foundation/utils/query.py,sha256=ODQ3adOYQNj5E2cRW9ytbjBz56nEDcnfq8mQ6YZbCCM,4375
|
101
101
|
maleo_foundation/utils/formatter/__init__.py,sha256=iKf5YCbEdg1qKnFHyKqqcQbqAqEeRUf8mhI3v3dQoj8,78
|
102
102
|
maleo_foundation/utils/formatter/case.py,sha256=TmvvlfzGdC_omMTB5vAa40TZBxQ3hnr-SYeo0M52Rlg,1352
|
103
|
-
maleo_foundation/utils/loaders/__init__.py,sha256=
|
103
|
+
maleo_foundation/utils/loaders/__init__.py,sha256=P_3ycGfeDXFjAi8bE4iLWHxBveqUIdpHgGv-klRWM3s,282
|
104
104
|
maleo_foundation/utils/loaders/json.py,sha256=NsXLq3VZSgzmEf99tV1VtrmiudWdQ8Pzh_hI4Rm0cM8,397
|
105
|
-
maleo_foundation/utils/loaders/yaml.py,sha256=
|
106
|
-
maleo_foundation/utils/loaders/
|
105
|
+
maleo_foundation/utils/loaders/yaml.py,sha256=L438PTWFnE0St_T4-7f_3TV4apfh0LhYkIdODCuYuDw,388
|
106
|
+
maleo_foundation/utils/loaders/credential/__init__.py,sha256=qopTKvcMVoTFwyRijeg7rejnG4I684FjUwh70tvhtVM,141
|
107
|
+
maleo_foundation/utils/loaders/credential/google.py,sha256=ZWdgdTasDDYBbBLaVrlnXAv8tN2MaOUNEgmcywENrSk,1116
|
108
|
+
maleo_foundation/utils/loaders/key/__init__.py,sha256=hVygcC2ImHc_aVrSrOmyedR8tMUZokWUKCKOSh5ctbo,106
|
107
109
|
maleo_foundation/utils/loaders/key/rsa.py,sha256=gDhyX6iTFtHiluuhFCozaZ3pOLKU2Y9TlrNMK_GVyGU,3796
|
108
|
-
maleo_foundation-0.1.
|
109
|
-
maleo_foundation-0.1.
|
110
|
-
maleo_foundation-0.1.
|
111
|
-
maleo_foundation-0.1.
|
110
|
+
maleo_foundation-0.1.83.dist-info/METADATA,sha256=zm7d1DKfe-eaDzlirlZmgBlJnXaLxRYQ9odBFHOfZdM,3419
|
111
|
+
maleo_foundation-0.1.83.dist-info/WHEEL,sha256=DnLRTWE75wApRYVsjgc6wsVswC54sMSJhAEd4xhDpBk,91
|
112
|
+
maleo_foundation-0.1.83.dist-info/top_level.txt,sha256=_iBos3F_bhEOdjOnzeiEYSrCucasc810xXtLBXI8cQc,17
|
113
|
+
maleo_foundation-0.1.83.dist-info/RECORD,,
|
File without changes
|