data-syncmaster 0.1.1__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.
Files changed (110) hide show
  1. data_syncmaster-0.1.1.dist-info/LICENSE.txt +203 -0
  2. data_syncmaster-0.1.1.dist-info/METADATA +115 -0
  3. data_syncmaster-0.1.1.dist-info/RECORD +110 -0
  4. data_syncmaster-0.1.1.dist-info/WHEEL +4 -0
  5. syncmaster/__init__.py +6 -0
  6. syncmaster/backend/__init__.py +2 -0
  7. syncmaster/backend/api/__init__.py +2 -0
  8. syncmaster/backend/api/deps.py +20 -0
  9. syncmaster/backend/api/monitoring.py +10 -0
  10. syncmaster/backend/api/router.py +10 -0
  11. syncmaster/backend/api/v1/__init__.py +2 -0
  12. syncmaster/backend/api/v1/auth/__init__.py +2 -0
  13. syncmaster/backend/api/v1/auth/router.py +32 -0
  14. syncmaster/backend/api/v1/auth/utils.py +26 -0
  15. syncmaster/backend/api/v1/connections.py +300 -0
  16. syncmaster/backend/api/v1/groups.py +225 -0
  17. syncmaster/backend/api/v1/queue.py +148 -0
  18. syncmaster/backend/api/v1/router.py +18 -0
  19. syncmaster/backend/api/v1/transfers/__init__.py +2 -0
  20. syncmaster/backend/api/v1/transfers/router.py +469 -0
  21. syncmaster/backend/api/v1/transfers/utils.py +17 -0
  22. syncmaster/backend/api/v1/users.py +75 -0
  23. syncmaster/backend/export_openapi_schema.py +26 -0
  24. syncmaster/backend/handler.py +203 -0
  25. syncmaster/backend/logger.py +2 -0
  26. syncmaster/backend/main.py +63 -0
  27. syncmaster/backend/pre_start.py +94 -0
  28. syncmaster/backend/services/__init__.py +4 -0
  29. syncmaster/backend/services/auth.py +58 -0
  30. syncmaster/backend/services/unit_of_work.py +44 -0
  31. syncmaster/config.py +110 -0
  32. syncmaster/db/__init__.py +2 -0
  33. syncmaster/db/alembic.ini +41 -0
  34. syncmaster/db/base.py +28 -0
  35. syncmaster/db/factory.py +37 -0
  36. syncmaster/db/migrations/README +1 -0
  37. syncmaster/db/migrations/__init__.py +2 -0
  38. syncmaster/db/migrations/env.py +87 -0
  39. syncmaster/db/migrations/script.py.mako +24 -0
  40. syncmaster/db/migrations/versions/2023-11-23_478240cdad4b_init.py +242 -0
  41. syncmaster/db/migrations/versions/__init__.py +2 -0
  42. syncmaster/db/mixins.py +33 -0
  43. syncmaster/db/models.py +194 -0
  44. syncmaster/db/repositories/__init__.py +22 -0
  45. syncmaster/db/repositories/base.py +109 -0
  46. syncmaster/db/repositories/connection.py +138 -0
  47. syncmaster/db/repositories/credentials_repository.py +87 -0
  48. syncmaster/db/repositories/group.py +264 -0
  49. syncmaster/db/repositories/queue.py +195 -0
  50. syncmaster/db/repositories/repository_with_owner.py +115 -0
  51. syncmaster/db/repositories/run.py +78 -0
  52. syncmaster/db/repositories/transfer.py +202 -0
  53. syncmaster/db/repositories/user.py +72 -0
  54. syncmaster/db/repositories/utils.py +25 -0
  55. syncmaster/db/utils.py +31 -0
  56. syncmaster/dto/__init__.py +2 -0
  57. syncmaster/dto/connections.py +60 -0
  58. syncmaster/dto/transfers.py +46 -0
  59. syncmaster/exceptions/__init__.py +13 -0
  60. syncmaster/exceptions/base.py +12 -0
  61. syncmaster/exceptions/connection.py +28 -0
  62. syncmaster/exceptions/credentials.py +8 -0
  63. syncmaster/exceptions/group.py +27 -0
  64. syncmaster/exceptions/queue.py +16 -0
  65. syncmaster/exceptions/run.py +19 -0
  66. syncmaster/exceptions/transfer.py +39 -0
  67. syncmaster/exceptions/user.py +11 -0
  68. syncmaster/schemas/__init__.py +2 -0
  69. syncmaster/schemas/v1/__init__.py +54 -0
  70. syncmaster/schemas/v1/auth.py +12 -0
  71. syncmaster/schemas/v1/connection_types.py +9 -0
  72. syncmaster/schemas/v1/connections/__init__.py +2 -0
  73. syncmaster/schemas/v1/connections/connection.py +146 -0
  74. syncmaster/schemas/v1/connections/hdfs.py +40 -0
  75. syncmaster/schemas/v1/connections/hive.py +40 -0
  76. syncmaster/schemas/v1/connections/oracle.py +58 -0
  77. syncmaster/schemas/v1/connections/postgres.py +48 -0
  78. syncmaster/schemas/v1/connections/s3.py +66 -0
  79. syncmaster/schemas/v1/file_formats.py +7 -0
  80. syncmaster/schemas/v1/groups.py +39 -0
  81. syncmaster/schemas/v1/page.py +40 -0
  82. syncmaster/schemas/v1/queue.py +32 -0
  83. syncmaster/schemas/v1/status.py +16 -0
  84. syncmaster/schemas/v1/transfer_types.py +6 -0
  85. syncmaster/schemas/v1/transfers/__init__.py +172 -0
  86. syncmaster/schemas/v1/transfers/db.py +23 -0
  87. syncmaster/schemas/v1/transfers/file/__init__.py +2 -0
  88. syncmaster/schemas/v1/transfers/file/base.py +47 -0
  89. syncmaster/schemas/v1/transfers/file/hdfs.py +27 -0
  90. syncmaster/schemas/v1/transfers/file/s3.py +27 -0
  91. syncmaster/schemas/v1/transfers/file_format.py +29 -0
  92. syncmaster/schemas/v1/transfers/run.py +37 -0
  93. syncmaster/schemas/v1/transfers/strategy.py +15 -0
  94. syncmaster/schemas/v1/types.py +5 -0
  95. syncmaster/schemas/v1/users.py +83 -0
  96. syncmaster/worker/__init__.py +2 -0
  97. syncmaster/worker/base.py +14 -0
  98. syncmaster/worker/config.py +18 -0
  99. syncmaster/worker/controller.py +127 -0
  100. syncmaster/worker/handlers/__init__.py +2 -0
  101. syncmaster/worker/handlers/base.py +49 -0
  102. syncmaster/worker/handlers/file/__init__.py +2 -0
  103. syncmaster/worker/handlers/file/base.py +56 -0
  104. syncmaster/worker/handlers/file/hdfs.py +14 -0
  105. syncmaster/worker/handlers/file/s3.py +20 -0
  106. syncmaster/worker/handlers/hive.py +41 -0
  107. syncmaster/worker/handlers/oracle.py +48 -0
  108. syncmaster/worker/handlers/postgres.py +47 -0
  109. syncmaster/worker/spark.py +93 -0
  110. syncmaster/worker/transfer.py +85 -0
syncmaster/db/utils.py ADDED
@@ -0,0 +1,31 @@
1
+ # SPDX-FileCopyrightText: 2023-2024 MTS (Mobile Telesystems)
2
+ # SPDX-License-Identifier: Apache-2.0
3
+ import math
4
+ from collections.abc import Sequence
5
+ from enum import IntEnum
6
+ from typing import Any
7
+
8
+
9
+ class Pagination:
10
+ def __init__(self, items: Sequence[Any], page: int, page_size: int, total: int) -> None:
11
+ self.items = items
12
+ self.total = total
13
+ self.page_size = page_size
14
+ self.page = page
15
+ self.previous_page = None
16
+ self.next_page = None
17
+ self.has_previous = page > 1
18
+ if self.has_previous:
19
+ self.previous_page = page - 1
20
+ previous_items = (page - 1) * page_size
21
+ self.has_next = previous_items + len(items) < total
22
+ if self.has_next:
23
+ self.next_page = page + 1
24
+ self.pages = int(math.ceil(total / float(page_size))) or 1
25
+
26
+
27
+ class Permission(IntEnum):
28
+ NONE = 0
29
+ READ = 1
30
+ WRITE = 2 # same as CREATE, UPDATE, START, STOP
31
+ DELETE = 3
@@ -0,0 +1,2 @@
1
+ # SPDX-FileCopyrightText: 2023-2024 MTS (Mobile Telesystems)
2
+ # SPDX-License-Identifier: Apache-2.0
@@ -0,0 +1,60 @@
1
+ # SPDX-FileCopyrightText: 2023-2024 MTS (Mobile Telesystems)
2
+ # SPDX-License-Identifier: Apache-2.0
3
+ from dataclasses import dataclass
4
+
5
+
6
+ @dataclass
7
+ class ConnectionDTO:
8
+ pass
9
+
10
+
11
+ @dataclass
12
+ class PostgresConnectionDTO(ConnectionDTO):
13
+ host: str
14
+ port: int
15
+ user: str
16
+ password: str
17
+ additional_params: dict
18
+ database_name: str
19
+ type: str = "postgres"
20
+
21
+
22
+ @dataclass
23
+ class OracleConnectionDTO(ConnectionDTO):
24
+ host: str
25
+ port: int
26
+ user: str
27
+ password: str
28
+ additional_params: dict
29
+ sid: str | None = None
30
+ service_name: str | None = None
31
+ type: str = "oracle"
32
+
33
+
34
+ @dataclass
35
+ class HiveConnectionDTO(ConnectionDTO):
36
+ user: str
37
+ password: str
38
+ cluster: str
39
+ type: str = "hive"
40
+
41
+
42
+ @dataclass
43
+ class HDFSConnectionDTO(ConnectionDTO):
44
+ user: str
45
+ password: str
46
+ cluster: str
47
+ type: str = "hdfs"
48
+
49
+
50
+ @dataclass
51
+ class S3ConnectionDTO(ConnectionDTO):
52
+ host: str
53
+ port: int
54
+ access_key: str
55
+ secret_key: str
56
+ bucket: str
57
+ additional_params: dict
58
+ region: str | None = None
59
+ protocol: str = "https"
60
+ type: str = "s3"
@@ -0,0 +1,46 @@
1
+ # SPDX-FileCopyrightText: 2023-2024 MTS (Mobile Telesystems)
2
+ # SPDX-License-Identifier: Apache-2.0
3
+ from dataclasses import dataclass
4
+
5
+ from syncmaster.schemas.v1.transfers.file_format import CSV, JSON, JSONLine
6
+
7
+
8
+ @dataclass
9
+ class TransferDTO:
10
+ pass
11
+
12
+
13
+ @dataclass
14
+ class PostgresTransferDTO(TransferDTO):
15
+ table_name: str
16
+ type: str = "postgres"
17
+
18
+
19
+ @dataclass
20
+ class OracleTransferDTO(TransferDTO):
21
+ table_name: str
22
+ type: str = "oracle"
23
+
24
+
25
+ @dataclass
26
+ class HiveTransferDTO(TransferDTO):
27
+ table_name: str
28
+ type: str = "hive"
29
+
30
+
31
+ @dataclass
32
+ class S3TransferDTO(TransferDTO):
33
+ directory_path: str
34
+ file_format: CSV | JSONLine | JSON
35
+ options: dict
36
+ df_schema: dict | None = None
37
+ type: str = "s3"
38
+
39
+
40
+ @dataclass
41
+ class HDFSTransferDTO(TransferDTO):
42
+ directory_path: str
43
+ file_format: CSV | JSONLine | JSON
44
+ options: dict
45
+ df_schema: dict | None = None
46
+ type: str = "hdfs"
@@ -0,0 +1,13 @@
1
+ # SPDX-FileCopyrightText: 2023-2024 MTS (Mobile Telesystems)
2
+ # SPDX-License-Identifier: Apache-2.0
3
+ from syncmaster.exceptions.base import (
4
+ ActionNotAllowedError,
5
+ EntityNotFoundError,
6
+ SyncmasterError,
7
+ )
8
+
9
+ __all__ = [
10
+ "ActionNotAllowedError",
11
+ "EntityNotFoundError",
12
+ "SyncmasterError",
13
+ ]
@@ -0,0 +1,12 @@
1
+ # SPDX-FileCopyrightText: 2023-2024 MTS (Mobile Telesystems)
2
+ # SPDX-License-Identifier: Apache-2.0
3
+ class SyncmasterError(Exception):
4
+ pass
5
+
6
+
7
+ class EntityNotFoundError(SyncmasterError):
8
+ pass
9
+
10
+
11
+ class ActionNotAllowedError(SyncmasterError):
12
+ pass
@@ -0,0 +1,28 @@
1
+ # SPDX-FileCopyrightText: 2023-2024 MTS (Mobile Telesystems)
2
+ # SPDX-License-Identifier: Apache-2.0
3
+ from syncmaster.exceptions.base import EntityNotFoundError, SyncmasterError
4
+
5
+
6
+ class ConnectionNotFoundError(EntityNotFoundError):
7
+ pass
8
+
9
+
10
+ class ConnectionOwnerError(SyncmasterError):
11
+ pass
12
+
13
+
14
+ class ConnectionTypeNotRecognizedError(SyncmasterError):
15
+ pass
16
+
17
+
18
+ class UserDoNotHaveRightsInTheTargetGroupError(SyncmasterError):
19
+ pass
20
+
21
+
22
+ class DuplicatedConnectionNameError(SyncmasterError):
23
+ pass
24
+
25
+
26
+ class ConnectionDeleteError(SyncmasterError):
27
+ def __init__(self, message: str) -> None:
28
+ self.message = message
@@ -0,0 +1,8 @@
1
+ # SPDX-FileCopyrightText: 2023-2024 MTS (Mobile Telesystems)
2
+ # SPDX-License-Identifier: Apache-2.0
3
+ from syncmaster.exceptions import SyncmasterError
4
+
5
+
6
+ class AuthDataNotFoundError(SyncmasterError):
7
+ def __init__(self, message: str) -> None:
8
+ self.message = message
@@ -0,0 +1,27 @@
1
+ # SPDX-FileCopyrightText: 2023-2024 MTS (Mobile Telesystems)
2
+ # SPDX-License-Identifier: Apache-2.0
3
+ from syncmaster.exceptions.base import SyncmasterError
4
+
5
+
6
+ class GroupNameAlreadyExistsError(SyncmasterError):
7
+ pass
8
+
9
+
10
+ class GroupAdminNotFoundError(SyncmasterError):
11
+ pass
12
+
13
+
14
+ class GroupAlreadyExistsError(SyncmasterError):
15
+ pass
16
+
17
+
18
+ class AlreadyIsGroupMemberError(SyncmasterError):
19
+ pass
20
+
21
+
22
+ class AlreadyIsNotGroupMemberError(SyncmasterError):
23
+ pass
24
+
25
+
26
+ class GroupNotFoundError(SyncmasterError):
27
+ pass
@@ -0,0 +1,16 @@
1
+ # SPDX-FileCopyrightText: 2023-2024 MTS (Mobile Telesystems)
2
+ # SPDX-License-Identifier: Apache-2.0
3
+ from syncmaster.exceptions.base import EntityNotFoundError, SyncmasterError
4
+
5
+
6
+ class QueueNotFoundError(EntityNotFoundError):
7
+ pass
8
+
9
+
10
+ class QueueDeleteError(SyncmasterError):
11
+ def __init__(self, message: str) -> None:
12
+ self.message = message
13
+
14
+
15
+ class DifferentTransferAndQueueGroupError(SyncmasterError):
16
+ pass
@@ -0,0 +1,19 @@
1
+ # SPDX-FileCopyrightText: 2023-2024 MTS (Mobile Telesystems)
2
+ # SPDX-License-Identifier: Apache-2.0
3
+ from syncmaster.db.models import Status
4
+ from syncmaster.exceptions.base import EntityNotFoundError, SyncmasterError
5
+
6
+
7
+ class RunNotFoundError(EntityNotFoundError):
8
+ pass
9
+
10
+
11
+ class CannotStopRunError(SyncmasterError):
12
+ def __init__(self, run_id: int, current_status: Status):
13
+ self.run_id = run_id
14
+ self.current_status = current_status
15
+
16
+
17
+ class CannotConnectToTaskQueueError(SyncmasterError):
18
+ def __init__(self, run_id: int):
19
+ self.run_id = run_id
@@ -0,0 +1,39 @@
1
+ # SPDX-FileCopyrightText: 2023-2024 MTS (Mobile Telesystems)
2
+ # SPDX-License-Identifier: Apache-2.0
3
+ from typing import Literal
4
+
5
+ from syncmaster.exceptions.base import SyncmasterError
6
+
7
+
8
+ class TransferOwnerError(SyncmasterError):
9
+ pass
10
+
11
+
12
+ class TransferNotFoundError(SyncmasterError):
13
+ pass
14
+
15
+
16
+ class DuplicatedTransferNameError(SyncmasterError):
17
+ pass
18
+
19
+
20
+ class DifferentTransferAndConnectionsGroupsError(SyncmasterError):
21
+ pass
22
+
23
+
24
+ class DifferentTypeConnectionsAndParamsError(SyncmasterError):
25
+ def __init__(
26
+ self,
27
+ connection_type: str,
28
+ params_type: str,
29
+ conn: Literal["source", "target"],
30
+ ):
31
+ self.connection_type = connection_type
32
+ self.params_type = params_type
33
+ self.conn = conn.capitalize()
34
+
35
+ @property
36
+ def message(self) -> str:
37
+ return (
38
+ f"{self.conn} connection has type `{self.connection_type}` " f"but its params has `{self.params_type}` type"
39
+ )
@@ -0,0 +1,11 @@
1
+ # SPDX-FileCopyrightText: 2023-2024 MTS (Mobile Telesystems)
2
+ # SPDX-License-Identifier: Apache-2.0
3
+ from syncmaster.exceptions.base import SyncmasterError
4
+
5
+
6
+ class UsernameAlreadyExistsError(SyncmasterError):
7
+ pass
8
+
9
+
10
+ class UserNotFoundError(SyncmasterError):
11
+ pass
@@ -0,0 +1,2 @@
1
+ # SPDX-FileCopyrightText: 2023-2024 MTS (Mobile Telesystems)
2
+ # SPDX-License-Identifier: Apache-2.0
@@ -0,0 +1,54 @@
1
+ # SPDX-FileCopyrightText: 2023-2024 MTS (Mobile Telesystems)
2
+ # SPDX-License-Identifier: Apache-2.0
3
+
4
+ from syncmaster.schemas.v1.auth import AuthTokenSchema, TokenPayloadSchema
5
+ from syncmaster.schemas.v1.connections.connection import (
6
+ ConnectionCopySchema,
7
+ ConnectionPageSchema,
8
+ CreateConnectionSchema,
9
+ ReadConnectionSchema,
10
+ UpdateConnectionSchema,
11
+ )
12
+ from syncmaster.schemas.v1.groups import (
13
+ AddUserSchema,
14
+ CreateGroupSchema,
15
+ GroupPageSchema,
16
+ ReadGroupSchema,
17
+ UpdateGroupSchema,
18
+ )
19
+ from syncmaster.schemas.v1.queue import (
20
+ CreateQueueSchema,
21
+ QueuePageSchema,
22
+ ReadQueueSchema,
23
+ UpdateQueueSchema,
24
+ )
25
+ from syncmaster.schemas.v1.transfers import (
26
+ CopyTransferSchema,
27
+ CreateTransferSchema,
28
+ ReadFullTransferSchema,
29
+ ReadTransferSchema,
30
+ TransferPageSchema,
31
+ UpdateTransferSchema,
32
+ )
33
+ from syncmaster.schemas.v1.transfers.db import (
34
+ HiveReadTransferSourceAndTarget,
35
+ OracleReadTransferSourceAndTarget,
36
+ PostgresReadTransferSourceAndTarget,
37
+ ReadDBTransfer,
38
+ )
39
+ from syncmaster.schemas.v1.transfers.file_format import CSV, JSON, JSONLine
40
+ from syncmaster.schemas.v1.transfers.run import (
41
+ CreateRunSchema,
42
+ ReadRunSchema,
43
+ RunPageSchema,
44
+ ShortRunSchema,
45
+ )
46
+ from syncmaster.schemas.v1.transfers.strategy import FullStrategy, IncrementalStrategy
47
+ from syncmaster.schemas.v1.users import (
48
+ FullUserSchema,
49
+ ReadGroupMember,
50
+ ReadUserSchema,
51
+ UpdateUserSchema,
52
+ UserPageSchema,
53
+ UserPageSchemaAsGroupMember,
54
+ )
@@ -0,0 +1,12 @@
1
+ # SPDX-FileCopyrightText: 2023-2024 MTS (Mobile Telesystems)
2
+ # SPDX-License-Identifier: Apache-2.0
3
+ from pydantic import BaseModel
4
+
5
+
6
+ class TokenPayloadSchema(BaseModel):
7
+ user_id: int
8
+
9
+
10
+ class AuthTokenSchema(BaseModel):
11
+ access_token: str
12
+ refresh_token: str
@@ -0,0 +1,9 @@
1
+ # SPDX-FileCopyrightText: 2023-2024 MTS (Mobile Telesystems)
2
+ # SPDX-License-Identifier: Apache-2.0
3
+ from typing import Literal
4
+
5
+ HIVE_TYPE = Literal["hive"]
6
+ ORACLE_TYPE = Literal["oracle"]
7
+ POSTGRES_TYPE = Literal["postgres"]
8
+ S3_TYPE = Literal["s3"]
9
+ HDFS_TYPE = Literal["hdfs"]
@@ -0,0 +1,2 @@
1
+ # SPDX-FileCopyrightText: 2023-2024 MTS (Mobile Telesystems)
2
+ # SPDX-License-Identifier: Apache-2.0
@@ -0,0 +1,146 @@
1
+ # SPDX-FileCopyrightText: 2023-2024 MTS (Mobile Telesystems)
2
+ # SPDX-License-Identifier: Apache-2.0
3
+
4
+ from pydantic import BaseModel, Field, model_validator
5
+
6
+ from syncmaster.schemas.v1.connections.hdfs import (
7
+ HDFSCreateAuthSchema,
8
+ HDFSCreateConnectionSchema,
9
+ HDFSReadAuthSchema,
10
+ HDFSReadConnectionSchema,
11
+ HDFSUpdateAuthSchema,
12
+ HDFSUpdateConnectionSchema,
13
+ )
14
+ from syncmaster.schemas.v1.connections.hive import (
15
+ CreateHiveAuthSchema,
16
+ CreateHiveConnectionSchema,
17
+ ReadHiveAuthSchema,
18
+ ReadHiveConnectionSchema,
19
+ UpdateHiveAuthSchema,
20
+ UpdateHiveConnectionSchema,
21
+ )
22
+ from syncmaster.schemas.v1.connections.oracle import (
23
+ CreateOracleAuthSchema,
24
+ CreateOracleConnectionSchema,
25
+ ReadOracleAuthSchema,
26
+ ReadOracleConnectionSchema,
27
+ UpdateOracleAuthSchema,
28
+ UpdateOracleConnectionSchema,
29
+ )
30
+ from syncmaster.schemas.v1.connections.postgres import (
31
+ CreatePostgresAuthSchema,
32
+ CreatePostgresConnectionSchema,
33
+ ReadPostgresAuthSchema,
34
+ ReadPostgresConnectionSchema,
35
+ UpdatePostgresAuthSchema,
36
+ UpdatePostgresConnectionSchema,
37
+ )
38
+ from syncmaster.schemas.v1.connections.s3 import (
39
+ S3CreateAuthSchema,
40
+ S3CreateConnectionSchema,
41
+ S3ReadAuthSchema,
42
+ S3ReadConnectionSchema,
43
+ S3UpdateAuthSchema,
44
+ S3UpdateConnectionSchema,
45
+ )
46
+ from syncmaster.schemas.v1.page import PageSchema
47
+ from syncmaster.schemas.v1.types import NameConstr
48
+
49
+ ReadConnectionDataSchema = (
50
+ ReadHiveConnectionSchema
51
+ | HDFSReadConnectionSchema
52
+ | ReadOracleConnectionSchema
53
+ | ReadPostgresConnectionSchema
54
+ | S3ReadConnectionSchema
55
+ )
56
+ CreateConnectionDataSchema = (
57
+ CreateHiveConnectionSchema
58
+ | CreateOracleConnectionSchema
59
+ | CreatePostgresConnectionSchema
60
+ | HDFSCreateConnectionSchema
61
+ | S3CreateConnectionSchema
62
+ )
63
+ UpdateConnectionDataSchema = (
64
+ UpdateHiveConnectionSchema
65
+ | HDFSUpdateConnectionSchema
66
+ | S3UpdateConnectionSchema
67
+ | UpdateOracleConnectionSchema
68
+ | UpdatePostgresConnectionSchema
69
+ )
70
+ ReadConnectionAuthDataSchema = (
71
+ ReadHiveAuthSchema | ReadOracleAuthSchema | ReadPostgresAuthSchema | S3ReadAuthSchema | HDFSReadAuthSchema
72
+ )
73
+ CreateConnectionAuthDataSchema = (
74
+ CreateHiveAuthSchema | CreateOracleAuthSchema | CreatePostgresAuthSchema | S3CreateAuthSchema | HDFSCreateAuthSchema
75
+ )
76
+ UpdateConnectionAuthDataSchema = (
77
+ UpdateHiveAuthSchema | UpdateOracleAuthSchema | UpdatePostgresAuthSchema | S3UpdateAuthSchema | HDFSUpdateAuthSchema
78
+ )
79
+
80
+
81
+ class ReadConnectionSchema(BaseModel):
82
+ id: int
83
+ group_id: int
84
+ name: str
85
+ description: str
86
+ auth_data: ReadConnectionAuthDataSchema | None = None
87
+ data: ReadConnectionDataSchema = Field(
88
+ ...,
89
+ discriminator="type",
90
+ alias="connection_data",
91
+ )
92
+
93
+ class Config:
94
+ from_attributes = True
95
+ populate_by_name = True
96
+
97
+
98
+ class UpdateConnectionSchema(BaseModel):
99
+ name: NameConstr | None = None # noqa: F722
100
+ description: str | None = None
101
+ auth_data: UpdateConnectionAuthDataSchema | None = Field(discriminator="type", default=None)
102
+ data: UpdateConnectionDataSchema | None = Field(discriminator="type", alias="connection_data", default=None)
103
+
104
+ @model_validator(mode="before")
105
+ def check_types(cls, values):
106
+ data, auth_data = values.get("connection_data"), values.get("auth_data")
107
+ if data and auth_data and data.get("type") != auth_data.get("type"):
108
+ raise ValueError("Connection data and auth data must have same types")
109
+ return values
110
+
111
+
112
+ class CreateConnectionSchema(BaseModel):
113
+ group_id: int = Field(..., description="Connection owner group id")
114
+ name: NameConstr = Field(..., description="Connection name") # noqa: F722
115
+ description: str = Field(..., description="Additional description")
116
+ data: CreateConnectionDataSchema = Field(
117
+ ...,
118
+ discriminator="type",
119
+ alias="connection_data",
120
+ description=(
121
+ "Data required to connect to the database. These are the parameters that are specified in the "
122
+ "URL request."
123
+ ),
124
+ )
125
+ auth_data: CreateConnectionAuthDataSchema = Field(
126
+ ...,
127
+ discriminator="type",
128
+ description="Credentials for authorization",
129
+ )
130
+
131
+ @model_validator(mode="before")
132
+ def check_types(cls, values):
133
+ data, auth_data = values.get("data"), values.get("auth_data")
134
+ if data and auth_data and data.type != auth_data.type:
135
+ raise ValueError("Connection data and auth data must have same types")
136
+ return values
137
+
138
+
139
+ class ConnectionCopySchema(BaseModel):
140
+ new_group_id: int
141
+ new_name: NameConstr | None = None # noqa: F722
142
+ remove_source: bool = False
143
+
144
+
145
+ class ConnectionPageSchema(PageSchema):
146
+ items: list[ReadConnectionSchema]
@@ -0,0 +1,40 @@
1
+ # SPDX-FileCopyrightText: 2023-2024 MTS (Mobile Telesystems)
2
+ # SPDX-License-Identifier: Apache-2.0
3
+
4
+ from pydantic import BaseModel, SecretStr
5
+
6
+ from syncmaster.schemas.v1.connection_types import HDFS_TYPE
7
+
8
+
9
+ class HDFSConnectionBaseSchema(BaseModel):
10
+ type: HDFS_TYPE
11
+
12
+ class Config:
13
+ from_attributes = True
14
+
15
+
16
+ class HDFSReadConnectionSchema(HDFSConnectionBaseSchema):
17
+ cluster: str
18
+
19
+
20
+ class HDFSCreateConnectionSchema(HDFSConnectionBaseSchema):
21
+ cluster: str
22
+
23
+
24
+ class HDFSUpdateConnectionSchema(HDFSConnectionBaseSchema):
25
+ cluster: str
26
+
27
+
28
+ class HDFSReadAuthSchema(HDFSConnectionBaseSchema):
29
+ user: str
30
+
31
+
32
+ class HDFSCreateAuthSchema(HDFSConnectionBaseSchema):
33
+ # Needed to create a spark session. For authorization in Kerberos
34
+ user: str
35
+ password: SecretStr
36
+
37
+
38
+ class HDFSUpdateAuthSchema(HDFSConnectionBaseSchema):
39
+ user: str | None = None
40
+ password: SecretStr | None = None
@@ -0,0 +1,40 @@
1
+ # SPDX-FileCopyrightText: 2023-2024 MTS (Mobile Telesystems)
2
+ # SPDX-License-Identifier: Apache-2.0
3
+
4
+ from pydantic import BaseModel, SecretStr
5
+
6
+ from syncmaster.schemas.v1.connection_types import HIVE_TYPE
7
+
8
+
9
+ class HiveBaseSchema(BaseModel):
10
+ type: HIVE_TYPE
11
+
12
+ class Config:
13
+ from_attributes = True
14
+
15
+
16
+ class ReadHiveConnectionSchema(HiveBaseSchema):
17
+ cluster: str
18
+
19
+
20
+ class ReadHiveAuthSchema(HiveBaseSchema):
21
+ user: str
22
+
23
+
24
+ class UpdateHiveConnectionSchema(HiveBaseSchema):
25
+ cluster: str | None = None
26
+
27
+
28
+ class UpdateHiveAuthSchema(HiveBaseSchema):
29
+ user: str | None = None
30
+ password: SecretStr | None = None
31
+
32
+
33
+ class CreateHiveConnectionSchema(HiveBaseSchema):
34
+ cluster: str
35
+
36
+
37
+ class CreateHiveAuthSchema(HiveBaseSchema):
38
+ # Needed to create a spark session. For authorization in Kerberos
39
+ user: str
40
+ password: SecretStr