data-sourcerer 0.1.0__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.
- data_sourcerer-0.1.0.dist-info/METADATA +52 -0
- data_sourcerer-0.1.0.dist-info/RECORD +95 -0
- data_sourcerer-0.1.0.dist-info/WHEEL +5 -0
- data_sourcerer-0.1.0.dist-info/entry_points.txt +2 -0
- data_sourcerer-0.1.0.dist-info/licenses/LICENSE +21 -0
- data_sourcerer-0.1.0.dist-info/top_level.txt +1 -0
- sourcerer/__init__.py +15 -0
- sourcerer/domain/__init__.py +13 -0
- sourcerer/domain/access_credentials/__init__.py +7 -0
- sourcerer/domain/access_credentials/entities.py +53 -0
- sourcerer/domain/access_credentials/exceptions.py +17 -0
- sourcerer/domain/access_credentials/repositories.py +84 -0
- sourcerer/domain/access_credentials/services.py +91 -0
- sourcerer/domain/file_system/__init__.py +7 -0
- sourcerer/domain/file_system/entities.py +70 -0
- sourcerer/domain/file_system/exceptions.py +17 -0
- sourcerer/domain/file_system/services.py +64 -0
- sourcerer/domain/shared/__init__.py +6 -0
- sourcerer/domain/shared/entities.py +18 -0
- sourcerer/domain/storage_provider/__init__.py +7 -0
- sourcerer/domain/storage_provider/entities.py +86 -0
- sourcerer/domain/storage_provider/exceptions.py +17 -0
- sourcerer/domain/storage_provider/services.py +130 -0
- sourcerer/infrastructure/__init__.py +13 -0
- sourcerer/infrastructure/access_credentials/__init__.py +7 -0
- sourcerer/infrastructure/access_credentials/exceptions.py +16 -0
- sourcerer/infrastructure/access_credentials/registry.py +120 -0
- sourcerer/infrastructure/access_credentials/repositories.py +119 -0
- sourcerer/infrastructure/access_credentials/services.py +396 -0
- sourcerer/infrastructure/db/__init__.py +6 -0
- sourcerer/infrastructure/db/config.py +73 -0
- sourcerer/infrastructure/db/models.py +47 -0
- sourcerer/infrastructure/file_system/__init__.py +7 -0
- sourcerer/infrastructure/file_system/exceptions.py +89 -0
- sourcerer/infrastructure/file_system/services.py +147 -0
- sourcerer/infrastructure/storage_provider/__init__.py +7 -0
- sourcerer/infrastructure/storage_provider/exceptions.py +78 -0
- sourcerer/infrastructure/storage_provider/registry.py +84 -0
- sourcerer/infrastructure/storage_provider/services.py +509 -0
- sourcerer/infrastructure/utils.py +106 -0
- sourcerer/presentation/__init__.py +12 -0
- sourcerer/presentation/app.py +36 -0
- sourcerer/presentation/di_container.py +46 -0
- sourcerer/presentation/screens/__init__.py +0 -0
- sourcerer/presentation/screens/critical_error/__init__.py +0 -0
- sourcerer/presentation/screens/critical_error/main.py +78 -0
- sourcerer/presentation/screens/critical_error/styles.tcss +41 -0
- sourcerer/presentation/screens/file_system_finder/main.py +248 -0
- sourcerer/presentation/screens/file_system_finder/styles.tcss +44 -0
- sourcerer/presentation/screens/file_system_finder/widgets/__init__.py +0 -0
- sourcerer/presentation/screens/file_system_finder/widgets/file_system_navigator.py +810 -0
- sourcerer/presentation/screens/main/__init__.py +0 -0
- sourcerer/presentation/screens/main/main.py +469 -0
- sourcerer/presentation/screens/main/messages/__init__.py +0 -0
- sourcerer/presentation/screens/main/messages/delete_request.py +12 -0
- sourcerer/presentation/screens/main/messages/download_request.py +12 -0
- sourcerer/presentation/screens/main/messages/preview_request.py +10 -0
- sourcerer/presentation/screens/main/messages/resizing_rule.py +21 -0
- sourcerer/presentation/screens/main/messages/select_storage_item.py +11 -0
- sourcerer/presentation/screens/main/messages/uncheck_files_request.py +8 -0
- sourcerer/presentation/screens/main/messages/upload_request.py +10 -0
- sourcerer/presentation/screens/main/mixins/__init__.py +0 -0
- sourcerer/presentation/screens/main/mixins/resize_containers_watcher_mixin.py +144 -0
- sourcerer/presentation/screens/main/styles.tcss +32 -0
- sourcerer/presentation/screens/main/widgets/__init__.py +0 -0
- sourcerer/presentation/screens/main/widgets/gradient.py +45 -0
- sourcerer/presentation/screens/main/widgets/resizing_rule.py +67 -0
- sourcerer/presentation/screens/main/widgets/storage_content.py +691 -0
- sourcerer/presentation/screens/main/widgets/storage_list_sidebar.py +143 -0
- sourcerer/presentation/screens/preview_content/__init__.py +0 -0
- sourcerer/presentation/screens/preview_content/main.py +59 -0
- sourcerer/presentation/screens/preview_content/styles.tcss +26 -0
- sourcerer/presentation/screens/provider_creds_list/__init__.py +0 -0
- sourcerer/presentation/screens/provider_creds_list/main.py +164 -0
- sourcerer/presentation/screens/provider_creds_list/styles.tcss +65 -0
- sourcerer/presentation/screens/provider_creds_registration/__init__.py +0 -0
- sourcerer/presentation/screens/provider_creds_registration/main.py +264 -0
- sourcerer/presentation/screens/provider_creds_registration/styles.tcss +42 -0
- sourcerer/presentation/screens/question/__init__.py +0 -0
- sourcerer/presentation/screens/question/main.py +31 -0
- sourcerer/presentation/screens/question/styles.tcss +33 -0
- sourcerer/presentation/screens/shared/__init__.py +0 -0
- sourcerer/presentation/screens/shared/containers.py +13 -0
- sourcerer/presentation/screens/shared/widgets/__init__.py +0 -0
- sourcerer/presentation/screens/shared/widgets/button.py +54 -0
- sourcerer/presentation/screens/shared/widgets/labeled_input.py +80 -0
- sourcerer/presentation/screens/storage_action_progress/__init__.py +0 -0
- sourcerer/presentation/screens/storage_action_progress/main.py +476 -0
- sourcerer/presentation/screens/storage_action_progress/styles.tcss +43 -0
- sourcerer/presentation/settings.py +31 -0
- sourcerer/presentation/themes/__init__.py +0 -0
- sourcerer/presentation/themes/github_dark.py +21 -0
- sourcerer/presentation/utils.py +69 -0
- sourcerer/settings.py +72 -0
- sourcerer/utils.py +32 -0
@@ -0,0 +1,396 @@
|
|
1
|
+
"""
|
2
|
+
Implementation of access credential services.
|
3
|
+
|
4
|
+
This module provides concrete implementations of the BaseAccessCredentialsService
|
5
|
+
interface for various cloud providers and authentication methods.
|
6
|
+
"""
|
7
|
+
|
8
|
+
import json
|
9
|
+
from abc import ABC
|
10
|
+
|
11
|
+
import boto3
|
12
|
+
from dependency_injector.wiring import Provide
|
13
|
+
from google.cloud import storage
|
14
|
+
|
15
|
+
from sourcerer.domain.access_credentials.entities import Credentials, Boto3Credentials
|
16
|
+
from sourcerer.domain.access_credentials.repositories import BaseCredentialsRepository
|
17
|
+
from sourcerer.domain.access_credentials.services import (
|
18
|
+
BaseAccessCredentialsService,
|
19
|
+
AuthField,
|
20
|
+
)
|
21
|
+
from sourcerer.domain.shared.entities import StorageProvider
|
22
|
+
from sourcerer.infrastructure.access_credentials.exceptions import CredentialsAuthError
|
23
|
+
from sourcerer.infrastructure.access_credentials.registry import (
|
24
|
+
access_credentials_method,
|
25
|
+
AccessCredentialsMethod,
|
26
|
+
)
|
27
|
+
from sourcerer.infrastructure.utils import generate_uuid
|
28
|
+
from sourcerer.presentation.di_container import DiContainer
|
29
|
+
|
30
|
+
|
31
|
+
class CredentialsService:
|
32
|
+
"""
|
33
|
+
Service for managing credentials.
|
34
|
+
|
35
|
+
This class provides methods for listing, retrieving, activating,
|
36
|
+
and deactivating credentials.
|
37
|
+
"""
|
38
|
+
|
39
|
+
def __init__(
|
40
|
+
self,
|
41
|
+
credentials_repo: BaseCredentialsRepository = Provide[
|
42
|
+
DiContainer.credentials_repository
|
43
|
+
],
|
44
|
+
):
|
45
|
+
"""
|
46
|
+
Initialize the service with a credentials repository.
|
47
|
+
|
48
|
+
Args:
|
49
|
+
credentials_repo (BaseCredentialsRepository): Repository for storing credentials
|
50
|
+
"""
|
51
|
+
self.credentials_repo = credentials_repo
|
52
|
+
|
53
|
+
def list(self, active_only=False):
|
54
|
+
"""
|
55
|
+
List credentials.
|
56
|
+
|
57
|
+
Args:
|
58
|
+
active_only (bool, optional): If True, return only active credentials.
|
59
|
+
Defaults to False.
|
60
|
+
|
61
|
+
Returns:
|
62
|
+
List[Credentials]: List of credentials objects
|
63
|
+
"""
|
64
|
+
return self.credentials_repo.list(active_only)
|
65
|
+
|
66
|
+
def get(self, uuid):
|
67
|
+
"""
|
68
|
+
Get credentials by UUID.
|
69
|
+
|
70
|
+
Args:
|
71
|
+
uuid (str): Unique identifier for the credentials
|
72
|
+
|
73
|
+
Returns:
|
74
|
+
Credentials: The credentials object
|
75
|
+
"""
|
76
|
+
return self.credentials_repo.get(uuid)
|
77
|
+
|
78
|
+
def activate(self, uuid):
|
79
|
+
"""
|
80
|
+
Activate credentials by UUID.
|
81
|
+
|
82
|
+
Args:
|
83
|
+
uuid (str): Unique identifier for the credentials to activate
|
84
|
+
"""
|
85
|
+
self.credentials_repo.activate(uuid)
|
86
|
+
|
87
|
+
def deactivate(self, uuid):
|
88
|
+
"""
|
89
|
+
Deactivate credentials by UUID.
|
90
|
+
|
91
|
+
Args:
|
92
|
+
uuid (str): Unique identifier for the credentials to deactivate
|
93
|
+
"""
|
94
|
+
self.credentials_repo.deactivate(uuid)
|
95
|
+
|
96
|
+
|
97
|
+
class AccessCredentialsService(BaseAccessCredentialsService, ABC):
|
98
|
+
"""
|
99
|
+
Base class for access credentials services.
|
100
|
+
|
101
|
+
This abstract class serves as a base for provider-specific
|
102
|
+
access credential service implementations.
|
103
|
+
"""
|
104
|
+
|
105
|
+
def __init__(
|
106
|
+
self,
|
107
|
+
credentials_repo: BaseCredentialsRepository = Provide[
|
108
|
+
DiContainer.credentials_repository
|
109
|
+
],
|
110
|
+
):
|
111
|
+
"""
|
112
|
+
Initialize the service with a credentials repository.
|
113
|
+
|
114
|
+
Args:
|
115
|
+
credentials_repo (BaseCredentialsRepository): Repository for storing credentials
|
116
|
+
"""
|
117
|
+
super().__init__(credentials_repo)
|
118
|
+
|
119
|
+
|
120
|
+
class S3AccessCredentialsService(AccessCredentialsService, ABC):
|
121
|
+
"""
|
122
|
+
Base class for AWS S3 access credentials services.
|
123
|
+
|
124
|
+
This abstract class serves as a base for S3-specific
|
125
|
+
access credential service implementations.
|
126
|
+
"""
|
127
|
+
|
128
|
+
|
129
|
+
@access_credentials_method(AccessCredentialsMethod(StorageProvider.S3, "key_pair"))
|
130
|
+
class S3AccessKeySecretKeyPair(S3AccessCredentialsService):
|
131
|
+
"""
|
132
|
+
AWS S3 access credentials service using access key and secret key.
|
133
|
+
|
134
|
+
This class provides methods for storing, retrieving, and authenticating
|
135
|
+
with AWS S3 using access key and secret key credentials.
|
136
|
+
"""
|
137
|
+
|
138
|
+
def store(self, name, credentials: dict):
|
139
|
+
"""
|
140
|
+
Store AWS access key credentials.
|
141
|
+
|
142
|
+
Args:
|
143
|
+
name (str): Name identifier for the credentials
|
144
|
+
credentials (dict): Dictionary containing AWS credential information
|
145
|
+
"""
|
146
|
+
self.credentials_repo.create(
|
147
|
+
Credentials(
|
148
|
+
uuid=generate_uuid(),
|
149
|
+
name=name,
|
150
|
+
provider=StorageProvider.S3,
|
151
|
+
credentials_type="key_pair",
|
152
|
+
credentials=json.dumps(credentials),
|
153
|
+
active=True,
|
154
|
+
)
|
155
|
+
)
|
156
|
+
|
157
|
+
def extract(self, uuid: str):
|
158
|
+
"""
|
159
|
+
Extract credentials by UUID.
|
160
|
+
|
161
|
+
Args:
|
162
|
+
uuid (str): UUID of the credentials to extract
|
163
|
+
|
164
|
+
Returns:
|
165
|
+
Credentials: The credentials object
|
166
|
+
"""
|
167
|
+
return self.credentials_repo.get(uuid)
|
168
|
+
|
169
|
+
def authenticate(self, credentials: str): # type: ignore
|
170
|
+
"""
|
171
|
+
Authenticate using stored credentials.
|
172
|
+
|
173
|
+
Args:
|
174
|
+
credentials (str): JSON string containing credential information
|
175
|
+
|
176
|
+
Returns:
|
177
|
+
boto3.Session: Authenticated boto3 session
|
178
|
+
"""
|
179
|
+
credentials: dict = json.loads(credentials)
|
180
|
+
|
181
|
+
session_args = {
|
182
|
+
"aws_access_key_id": credentials.get("aws_access_key_id"),
|
183
|
+
"aws_secret_access_key": credentials.get("aws_secret_access_key"),
|
184
|
+
}
|
185
|
+
|
186
|
+
if region := credentials.get("region"):
|
187
|
+
session_args["region_name"] = region
|
188
|
+
|
189
|
+
session = boto3.Session(**session_args)
|
190
|
+
|
191
|
+
return Boto3Credentials(
|
192
|
+
session=session,
|
193
|
+
endpoint_url=credentials.get("endpoint_url", None),
|
194
|
+
signature_version=credentials.get("signature_version", None),
|
195
|
+
)
|
196
|
+
|
197
|
+
@classmethod
|
198
|
+
def auth_fields(cls):
|
199
|
+
"""
|
200
|
+
Get list of authentication fields.
|
201
|
+
|
202
|
+
Returns:
|
203
|
+
List[AuthField]: List of authentication field definitions
|
204
|
+
"""
|
205
|
+
return [
|
206
|
+
AuthField("aws_access_key_id", "AWS Access Key Id", True),
|
207
|
+
AuthField("aws_secret_access_key", "AWS Secret Access Key", True),
|
208
|
+
AuthField("region", "Region", False),
|
209
|
+
AuthField("endpoint_url", "Endpoint Url", False),
|
210
|
+
]
|
211
|
+
|
212
|
+
|
213
|
+
@access_credentials_method(AccessCredentialsMethod(StorageProvider.S3, "profile_name"))
|
214
|
+
class S3ProfileName(S3AccessCredentialsService):
|
215
|
+
"""
|
216
|
+
AWS S3 access credentials service using profile name.
|
217
|
+
|
218
|
+
This class provides methods for storing, retrieving, and authenticating
|
219
|
+
with AWS S3 using a named profile from AWS configuration.
|
220
|
+
"""
|
221
|
+
|
222
|
+
def store(self, name, credentials: dict):
|
223
|
+
"""
|
224
|
+
Store AWS profile name credentials.
|
225
|
+
|
226
|
+
Args:
|
227
|
+
name (str): Name identifier for the credentials
|
228
|
+
credentials (dict): Dictionary containing profile name information
|
229
|
+
"""
|
230
|
+
self.credentials_repo.create(
|
231
|
+
Credentials(
|
232
|
+
uuid=generate_uuid(),
|
233
|
+
name=name,
|
234
|
+
provider=StorageProvider.S3,
|
235
|
+
credentials_type="profile_name",
|
236
|
+
credentials=json.dumps(credentials),
|
237
|
+
active=True,
|
238
|
+
)
|
239
|
+
)
|
240
|
+
|
241
|
+
def extract(self, uuid: str):
|
242
|
+
"""
|
243
|
+
Extract credentials by UUID.
|
244
|
+
|
245
|
+
Args:
|
246
|
+
uuid (str): UUID of the credentials to extract
|
247
|
+
|
248
|
+
Returns:
|
249
|
+
Credentials: The credentials object
|
250
|
+
"""
|
251
|
+
return self.credentials_repo.get(uuid)
|
252
|
+
|
253
|
+
def authenticate(self, credentials: str): # type: ignore
|
254
|
+
"""
|
255
|
+
Authenticate using stored profile name.
|
256
|
+
|
257
|
+
Args:
|
258
|
+
credentials (str): Dictionary containing profile name information
|
259
|
+
|
260
|
+
Returns:
|
261
|
+
boto3.Session: Authenticated boto3 session
|
262
|
+
"""
|
263
|
+
credentials: dict = json.loads(credentials)
|
264
|
+
session = boto3.Session(profile_name=credentials.get("profile_name"))
|
265
|
+
return Boto3Credentials(
|
266
|
+
session=session,
|
267
|
+
endpoint_url=credentials.get("endpoint_url"),
|
268
|
+
)
|
269
|
+
|
270
|
+
@classmethod
|
271
|
+
def auth_fields(cls):
|
272
|
+
"""
|
273
|
+
Get list of authentication fields.
|
274
|
+
|
275
|
+
Returns:
|
276
|
+
List[AuthField]: List of authentication field definitions
|
277
|
+
"""
|
278
|
+
return [
|
279
|
+
AuthField("profile_name", "Profile Name", True),
|
280
|
+
AuthField("endpoint_url", "Endpoint Url", False),
|
281
|
+
]
|
282
|
+
|
283
|
+
|
284
|
+
@access_credentials_method(
|
285
|
+
AccessCredentialsMethod(StorageProvider.GoogleCloudStorage, "Service account")
|
286
|
+
)
|
287
|
+
class GCPCredentialsService(AccessCredentialsService):
|
288
|
+
"""
|
289
|
+
Google Cloud Platform test credentials service.
|
290
|
+
|
291
|
+
This class provides methods for storing, retrieving, and authenticating
|
292
|
+
with GCP using test credentials.
|
293
|
+
"""
|
294
|
+
|
295
|
+
def store(self, name, credentials: dict):
|
296
|
+
"""
|
297
|
+
Store GCP test credentials.
|
298
|
+
|
299
|
+
Args:
|
300
|
+
name (str): Name identifier for the credentials
|
301
|
+
credentials (dict): Dictionary containing GCP credential information
|
302
|
+
"""
|
303
|
+
self.credentials_repo.create(
|
304
|
+
Credentials(
|
305
|
+
uuid=generate_uuid(),
|
306
|
+
name=name,
|
307
|
+
provider=StorageProvider.GoogleCloudStorage,
|
308
|
+
credentials_type="Service account",
|
309
|
+
credentials=json.dumps(credentials),
|
310
|
+
active=True,
|
311
|
+
)
|
312
|
+
)
|
313
|
+
|
314
|
+
def extract(self, uuid):
|
315
|
+
"""
|
316
|
+
Extract credentials by UUID.
|
317
|
+
|
318
|
+
Args:
|
319
|
+
uuid (str): UUID of the credentials to extract
|
320
|
+
|
321
|
+
Returns:
|
322
|
+
Credentials: The credentials object
|
323
|
+
"""
|
324
|
+
return self.credentials_repo.get(uuid)
|
325
|
+
|
326
|
+
def authenticate(self, credentials: str): # type: ignore
|
327
|
+
"""
|
328
|
+
Authenticate with Google Cloud Platform using service account credentials.
|
329
|
+
|
330
|
+
This method parses the stored credentials JSON string, extracts the service account
|
331
|
+
information, and creates a Google Cloud Storage client authenticated with those
|
332
|
+
credentials.
|
333
|
+
|
334
|
+
Args:
|
335
|
+
credentials (str): JSON string containing the service account credentials
|
336
|
+
|
337
|
+
Returns:
|
338
|
+
storage.Client: Authenticated Google Cloud Storage client
|
339
|
+
|
340
|
+
Raises:
|
341
|
+
ValueError: If the credentials are missing required fields
|
342
|
+
json.JSONDecodeError: If the credentials are not valid JSON
|
343
|
+
Exception: If authentication fails for any other reason
|
344
|
+
"""
|
345
|
+
try:
|
346
|
+
# Parse the outer JSON structure
|
347
|
+
parsed_credentials = json.loads(credentials)
|
348
|
+
|
349
|
+
# Extract the service account JSON string
|
350
|
+
service_acc_json = parsed_credentials.get("service_acc")
|
351
|
+
if not service_acc_json:
|
352
|
+
raise ValueError("Missing 'service_acc' field in credentials")
|
353
|
+
|
354
|
+
# Parse the service account JSON
|
355
|
+
try:
|
356
|
+
service_acc_info = json.loads(service_acc_json)
|
357
|
+
except json.JSONDecodeError as e:
|
358
|
+
raise ValueError("Invalid service account JSON format") from e
|
359
|
+
|
360
|
+
# Validate required fields for service account
|
361
|
+
required_fields = [
|
362
|
+
"type",
|
363
|
+
"project_id",
|
364
|
+
"private_key_id",
|
365
|
+
"private_key",
|
366
|
+
"client_email",
|
367
|
+
]
|
368
|
+
missing_fields = [
|
369
|
+
field for field in required_fields if field not in service_acc_info
|
370
|
+
]
|
371
|
+
if missing_fields:
|
372
|
+
raise ValueError(
|
373
|
+
f"Service account missing required fields: {', '.join(missing_fields)}"
|
374
|
+
)
|
375
|
+
|
376
|
+
# Create and return the authenticated client
|
377
|
+
return storage.Client.from_service_account_info(service_acc_info)
|
378
|
+
|
379
|
+
except json.JSONDecodeError as e:
|
380
|
+
raise CredentialsAuthError(f"Invalid credentials format: {str(e)}") from e
|
381
|
+
except Exception as e:
|
382
|
+
raise CredentialsAuthError(
|
383
|
+
f"Failed to authenticate with GCP: {str(e)}"
|
384
|
+
) from e
|
385
|
+
|
386
|
+
@classmethod
|
387
|
+
def auth_fields(cls):
|
388
|
+
"""
|
389
|
+
Get list of authentication fields.
|
390
|
+
|
391
|
+
Returns:
|
392
|
+
List[AuthField]: List of authentication field definitions
|
393
|
+
"""
|
394
|
+
return [
|
395
|
+
AuthField("service_acc", "Service acc", True, True),
|
396
|
+
]
|
@@ -0,0 +1,73 @@
|
|
1
|
+
"""
|
2
|
+
Database configuration and session management.
|
3
|
+
|
4
|
+
This module provides classes and utilities for configuring and
|
5
|
+
managing database connections and sessions.
|
6
|
+
"""
|
7
|
+
|
8
|
+
import contextlib
|
9
|
+
|
10
|
+
import sqlalchemy
|
11
|
+
from sqlalchemy.orm import scoped_session, sessionmaker
|
12
|
+
|
13
|
+
from sourcerer.infrastructure.db.models import Base
|
14
|
+
|
15
|
+
|
16
|
+
class Database:
|
17
|
+
"""
|
18
|
+
Acts as a connection pool and session factory.
|
19
|
+
|
20
|
+
This class manages database connections and provides
|
21
|
+
session management for database operations.
|
22
|
+
"""
|
23
|
+
|
24
|
+
def __init__(self, db_url):
|
25
|
+
"""
|
26
|
+
Initialize the database with a connection URL.
|
27
|
+
|
28
|
+
Args:
|
29
|
+
db_url (str): Database connection URL
|
30
|
+
"""
|
31
|
+
self.db_url = db_url
|
32
|
+
self.engine = sqlalchemy.create_engine(db_url)
|
33
|
+
self.scoped_session = scoped_session(sessionmaker(bind=self.engine)) # type: ignore
|
34
|
+
|
35
|
+
def prepare_db(self):
|
36
|
+
"""
|
37
|
+
Prepare the database by creating tables based on model definitions.
|
38
|
+
"""
|
39
|
+
# Prepare mappings
|
40
|
+
Base.metadata.create_all(self.engine)
|
41
|
+
|
42
|
+
@contextlib.contextmanager
|
43
|
+
def session(self):
|
44
|
+
"""
|
45
|
+
Context manager for database sessions.
|
46
|
+
|
47
|
+
Yields:
|
48
|
+
Session: A database session
|
49
|
+
|
50
|
+
Raises:
|
51
|
+
Exception: Any exception that occurs during session use
|
52
|
+
"""
|
53
|
+
session = self.scoped_session()
|
54
|
+
try:
|
55
|
+
yield session
|
56
|
+
except Exception as e:
|
57
|
+
session.rollback()
|
58
|
+
raise e
|
59
|
+
finally:
|
60
|
+
session.close()
|
61
|
+
|
62
|
+
@staticmethod
|
63
|
+
def session_factory(db):
|
64
|
+
"""
|
65
|
+
Create a session factory for the given database.
|
66
|
+
|
67
|
+
Args:
|
68
|
+
db (Session): Database instance
|
69
|
+
|
70
|
+
Returns:
|
71
|
+
callable: Session factory function
|
72
|
+
"""
|
73
|
+
return db.session
|
@@ -0,0 +1,47 @@
|
|
1
|
+
"""
|
2
|
+
Database models for the application.
|
3
|
+
|
4
|
+
This module defines SQLAlchemy models representing database tables
|
5
|
+
and their relationships.
|
6
|
+
"""
|
7
|
+
|
8
|
+
from datetime import datetime
|
9
|
+
|
10
|
+
from sqlalchemy import Column, Integer, Boolean, DateTime, String
|
11
|
+
from sqlalchemy.orm import declarative_base
|
12
|
+
from sqlalchemy_utils.types.encrypted.encrypted_type import EncryptedType
|
13
|
+
|
14
|
+
from sourcerer.settings import ENCRYPTION_KEY
|
15
|
+
|
16
|
+
Base = declarative_base()
|
17
|
+
|
18
|
+
|
19
|
+
class Credentials(Base):
|
20
|
+
"""
|
21
|
+
SQLAlchemy model for storing access credentials.
|
22
|
+
|
23
|
+
This model represents the credentials table in the database,
|
24
|
+
storing encrypted credential information for various providers.
|
25
|
+
|
26
|
+
Attributes:
|
27
|
+
id (int): Primary key
|
28
|
+
uuid (str): Unique identifier for the credentials
|
29
|
+
name (str): Name of the credentials
|
30
|
+
provider (str): Name of the service provider
|
31
|
+
credentials_type (str): Type of credentials (e.g., key_pair)
|
32
|
+
credentials (str): Encrypted credentials data
|
33
|
+
active (bool): Indicates if the credentials are active
|
34
|
+
created_at (datetime): Timestamp when the credentials were created
|
35
|
+
updated_at (datetime): Timestamp when the credentials were last updated
|
36
|
+
"""
|
37
|
+
|
38
|
+
__tablename__ = "credentials"
|
39
|
+
id = Column(Integer, primary_key=True)
|
40
|
+
uuid = Column(String, unique=True, nullable=False)
|
41
|
+
name = Column(String, nullable=False)
|
42
|
+
provider = Column(String, nullable=False)
|
43
|
+
credentials_type = Column(String, nullable=False)
|
44
|
+
credentials = Column(EncryptedType(String, ENCRYPTION_KEY), nullable=False)
|
45
|
+
active = Column(Boolean, default=True)
|
46
|
+
created_at = Column(DateTime, default=datetime.utcnow)
|
47
|
+
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
|
@@ -0,0 +1,89 @@
|
|
1
|
+
"""
|
2
|
+
File system exception classes.
|
3
|
+
|
4
|
+
This module defines exception classes for handling errors that occur
|
5
|
+
during interactions with the local file system.
|
6
|
+
"""
|
7
|
+
|
8
|
+
from sourcerer.domain.file_system.exceptions import BaseFileSystemException
|
9
|
+
|
10
|
+
|
11
|
+
class FileSystemGrepException(BaseFileSystemException):
|
12
|
+
"""
|
13
|
+
Custom exception for errors occurring during a file system search operation.
|
14
|
+
|
15
|
+
This exception is used to indicate and encapsulate errors specific
|
16
|
+
to the process of searching and grepping through file system contents.
|
17
|
+
It provides additional context about the nature of the error.
|
18
|
+
"""
|
19
|
+
|
20
|
+
|
21
|
+
class ReadFileException(BaseFileSystemException):
|
22
|
+
"""
|
23
|
+
Custom exception for errors occurring during a file system read operation.
|
24
|
+
|
25
|
+
This exception is used to indicate and encapsulate errors specific
|
26
|
+
to the process of reading file contents.
|
27
|
+
It provides additional context about the nature of the error.
|
28
|
+
"""
|
29
|
+
|
30
|
+
|
31
|
+
class CreateFileException(BaseFileSystemException):
|
32
|
+
"""
|
33
|
+
Custom exception for errors occurring during a file system create file operation.
|
34
|
+
|
35
|
+
This exception is used to indicate and encapsulate errors specific
|
36
|
+
to the process of creating a new file.
|
37
|
+
It provides additional context about the nature of the error.
|
38
|
+
"""
|
39
|
+
|
40
|
+
|
41
|
+
class CreateDirException(BaseFileSystemException):
|
42
|
+
"""
|
43
|
+
Custom exception for errors occurring during a file system create directory operation.
|
44
|
+
|
45
|
+
This exception is used to indicate and encapsulate errors specific
|
46
|
+
to the process of creating a new directory.
|
47
|
+
It provides additional context about the nature of the error.
|
48
|
+
"""
|
49
|
+
|
50
|
+
|
51
|
+
class MoveFileException(BaseFileSystemException):
|
52
|
+
"""
|
53
|
+
Exception raised for errors during file move operation.
|
54
|
+
|
55
|
+
This class is a specific type of exception that handles issues encountered
|
56
|
+
when attempting to move files in a file system. It inherits from
|
57
|
+
`BaseFileSystemException` to maintain consistency with other file system
|
58
|
+
related exceptions.
|
59
|
+
"""
|
60
|
+
|
61
|
+
|
62
|
+
class ListDirException(BaseFileSystemException):
|
63
|
+
"""
|
64
|
+
Custom exception for errors occurring during a file system list directory operation.
|
65
|
+
|
66
|
+
This exception is used to indicate and encapsulate errors specific
|
67
|
+
to the process of listing directory contents.
|
68
|
+
It provides additional context about the nature of the error.
|
69
|
+
"""
|
70
|
+
|
71
|
+
|
72
|
+
class DeleteFileException(BaseFileSystemException):
|
73
|
+
"""
|
74
|
+
Custom exception for errors occurring during a file system delete file operation.
|
75
|
+
|
76
|
+
This exception is used to indicate and encapsulate errors specific
|
77
|
+
to the process of deleting a file.
|
78
|
+
It provides additional context about the nature of the error.
|
79
|
+
"""
|
80
|
+
|
81
|
+
|
82
|
+
class DeleteDirException(BaseFileSystemException):
|
83
|
+
"""
|
84
|
+
Custom exception for errors occurring during a file system delete directory operation.
|
85
|
+
|
86
|
+
This exception is used to indicate and encapsulate errors specific
|
87
|
+
to the process of deleting a directory.
|
88
|
+
It provides additional context about the nature of the error.
|
89
|
+
"""
|