|
| 1 | +# SPDX-FileCopyrightText: 2023-2024 MTS PJSC |
| 2 | +# SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | +from typing import Literal |
| 5 | + |
| 6 | +from pydantic import BaseModel, Field, computed_field |
| 7 | + |
| 8 | +from syncmaster.schemas.v1.auth.iceberg_rest_basic import ( |
| 9 | + CreateIcebergRESTCatalogBasicAuthSchema, |
| 10 | + ReadIcebergRESTCatalogBasicAuthSchema, |
| 11 | + UpdateIcebergRESTCatalogBasicAuthSchema, |
| 12 | +) |
| 13 | +from syncmaster.schemas.v1.connection_types import ICEBERG_TYPE |
| 14 | +from syncmaster.schemas.v1.connections.connection_base import ( |
| 15 | + CreateConnectionBaseSchema, |
| 16 | + ReadConnectionBaseSchema, |
| 17 | +) |
| 18 | + |
| 19 | + |
| 20 | +class CreateIcebergRESTCatalogS3ConnectionDataSchema(BaseModel): |
| 21 | + s3_warehouse_path: str |
| 22 | + s3_host: str |
| 23 | + s3_port: int | None = None |
| 24 | + s3_protocol: Literal["http", "https"] = "https" |
| 25 | + s3_bucket: str |
| 26 | + s3_region: str |
| 27 | + s3_path_style_access: bool = False |
| 28 | + |
| 29 | + @computed_field |
| 30 | + @property |
| 31 | + def metastore_url(self) -> str: |
| 32 | + port = f":{self.s3_port}" if self.s3_port else "" |
| 33 | + return f"{self.s3_protocol}://{self.s3_host}{port}" |
| 34 | + |
| 35 | + |
| 36 | +class ReadIcebergRESTCatalogS3ConnectionDataSchema(BaseModel): |
| 37 | + metastore_url: str |
| 38 | + s3_warehouse_path: str |
| 39 | + s3_host: str |
| 40 | + s3_port: int | None = None |
| 41 | + s3_protocol: Literal["http", "https"] = "https" |
| 42 | + s3_bucket: str |
| 43 | + s3_region: str |
| 44 | + s3_path_style_access: bool = False |
| 45 | + |
| 46 | + |
| 47 | +class CreateIcebergConnectionSchema(CreateConnectionBaseSchema): |
| 48 | + type: ICEBERG_TYPE = Field(description="Connection type") |
| 49 | + data: CreateIcebergRESTCatalogS3ConnectionDataSchema = Field( |
| 50 | + ..., |
| 51 | + alias="connection_data", |
| 52 | + description=( |
| 53 | + "Data required to connect to the database. These are the parameters that are specified in the URL request." |
| 54 | + ), |
| 55 | + ) |
| 56 | + auth_data: CreateIcebergRESTCatalogBasicAuthSchema = Field( |
| 57 | + description="Credentials for authorization", |
| 58 | + ) |
| 59 | + |
| 60 | + |
| 61 | +class ReadIcebergConnectionSchema(ReadConnectionBaseSchema): |
| 62 | + type: ICEBERG_TYPE |
| 63 | + data: ReadIcebergRESTCatalogS3ConnectionDataSchema = Field(alias="connection_data") |
| 64 | + auth_data: ReadIcebergRESTCatalogBasicAuthSchema | None = None |
| 65 | + |
| 66 | + |
| 67 | +class UpdateIcebergConnectionSchema(CreateIcebergConnectionSchema): |
| 68 | + auth_data: UpdateIcebergRESTCatalogBasicAuthSchema = Field( |
| 69 | + description="Credentials for authorization", |
| 70 | + ) |
0 commit comments