Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DOP-22140] Add API schemas for SFTP, FTP, FTPS, WebDAV, Samba file sources #187

Merged
merged 1 commit into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/changelog/next_release/187.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add API schemas for SFTP, FTP, FTPS, WebDAV, Samba file sources
5 changes: 5 additions & 0 deletions syncmaster/db/models/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ class ConnectionType(StrEnum):
MYSQL = "mysql"
S3 = "s3"
HDFS = "hdfs"
SFTP = "sftp"
FTP = "ftp"
FTPS = "ftps"
WEBDAV = "webdav"
SAMBA = "samba"


class Connection(Base, ResourceMixin, TimestampMixin):
Expand Down
21 changes: 21 additions & 0 deletions syncmaster/schemas/v1/auth/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# SPDX-FileCopyrightText: 2023-2024 MTS PJSC
# SPDX-License-Identifier: Apache-2.0
from syncmaster.schemas.v1.auth.basic import (
BasicAuthSchema,
CreateBasicAuthSchema,
ReadBasicAuthSchema,
UpdateBasicAuthSchema,
)
from syncmaster.schemas.v1.auth.s3 import (
CreateS3AuthSchema,
ReadS3AuthSchema,
S3AuthSchema,
UpdateS3AuthSchema,
)
from syncmaster.schemas.v1.auth.samba import (
CreateSambaAuthSchema,
ReadSambaAuthSchema,
SambaAuthSchema,
UpdateSambaAuthSchema,
)
from syncmaster.schemas.v1.auth.token import AuthTokenSchema, TokenPayloadSchema
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,6 @@
from pydantic import BaseModel, SecretStr


class TokenPayloadSchema(BaseModel):
user_id: int


class AuthTokenSchema(BaseModel):
access_token: str
token_type: str
expires_at: float


class BasicAuthSchema(BaseModel):
type: Literal["basic"]

Expand All @@ -31,21 +21,3 @@ class ReadBasicAuthSchema(BasicAuthSchema):
class UpdateBasicAuthSchema(BasicAuthSchema):
user: str | None = None # noqa: F722
password: SecretStr | None = None


class S3AuthSchema(BaseModel):
type: Literal["s3"]


class CreateS3AuthSchema(S3AuthSchema):
access_key: str
secret_key: SecretStr


class ReadS3AuthSchema(S3AuthSchema):
access_key: str


class UpdateS3AuthSchema(S3AuthSchema):
access_key: str | None = None
secret_key: SecretStr | None = None
23 changes: 23 additions & 0 deletions syncmaster/schemas/v1/auth/s3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# SPDX-FileCopyrightText: 2023-2024 MTS PJSC
# SPDX-License-Identifier: Apache-2.0
from typing import Literal

from pydantic import BaseModel, SecretStr


class S3AuthSchema(BaseModel):
type: Literal["s3"]


class CreateS3AuthSchema(S3AuthSchema):
access_key: str
secret_key: SecretStr


class ReadS3AuthSchema(S3AuthSchema):
access_key: str


class UpdateS3AuthSchema(S3AuthSchema):
access_key: str | None = None
secret_key: SecretStr | None = None
26 changes: 26 additions & 0 deletions syncmaster/schemas/v1/auth/samba.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# SPDX-FileCopyrightText: 2023-2024 MTS PJSC
# SPDX-License-Identifier: Apache-2.0
from typing import Literal

from pydantic import BaseModel, SecretStr


class SambaAuthSchema(BaseModel):
type: Literal["samba"]


class CreateSambaAuthSchema(SambaAuthSchema):
user: str
password: SecretStr
auth_type: Literal["NTLMv1", "NTLMv2"] = "NTLMv2"


class ReadSambaAuthSchema(SambaAuthSchema):
user: str
auth_type: Literal["NTLMv1", "NTLMv2"]


class UpdateSambaAuthSchema(SambaAuthSchema):
user: str | None = None
password: SecretStr | None = None
auth_type: Literal["NTLMv1", "NTLMv2"] | None = None
13 changes: 13 additions & 0 deletions syncmaster/schemas/v1/auth/token.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# SPDX-FileCopyrightText: 2023-2024 MTS PJSC
# SPDX-License-Identifier: Apache-2.0
from pydantic import BaseModel


class TokenPayloadSchema(BaseModel):
user_id: int


class AuthTokenSchema(BaseModel):
access_token: str
token_type: str
expires_at: float
5 changes: 5 additions & 0 deletions syncmaster/schemas/v1/connection_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,8 @@
MYSQL_TYPE = Literal["mysql"]
S3_TYPE = Literal["s3"]
HDFS_TYPE = Literal["hdfs"]
SFTP_TYPE = Literal["sftp"]
FTP_TYPE = Literal["ftp"]
FTPS_TYPE = Literal["ftps"]
WEBDAV_TYPE = Literal["webdav"]
SAMBA_TYPE = Literal["samba"]
46 changes: 43 additions & 3 deletions syncmaster/schemas/v1/connections/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@
ReadClickhouseConnectionSchema,
UpdateClickhouseConnectionSchema,
)
from syncmaster.schemas.v1.connections.ftp import (
CreateFTPConnectionSchema,
ReadFTPConnectionSchema,
UpdateFTPConnectionSchema,
)
from syncmaster.schemas.v1.connections.ftps import (
CreateFTPSConnectionSchema,
ReadFTPSConnectionSchema,
UpdateFTPSConnectionSchema,
)
from syncmaster.schemas.v1.connections.hdfs import (
CreateHDFSConnectionSchema,
ReadHDFSConnectionSchema,
Expand Down Expand Up @@ -45,6 +55,21 @@
ReadS3ConnectionSchema,
UpdateS3ConnectionSchema,
)
from syncmaster.schemas.v1.connections.samba import (
CreateSambaConnectionSchema,
ReadSambaConnectionSchema,
UpdateSambaConnectionSchema,
)
from syncmaster.schemas.v1.connections.sftp import (
CreateSFTPConnectionSchema,
ReadSFTPConnectionSchema,
UpdateSFTPConnectionSchema,
)
from syncmaster.schemas.v1.connections.webdav import (
CreateWebDAVConnectionSchema,
ReadWebDAVConnectionSchema,
UpdateWebDAVConnectionSchema,
)
from syncmaster.schemas.v1.page import PageSchema
from syncmaster.schemas.v1.types import NameConstr

Expand All @@ -56,7 +81,12 @@
| CreateClickhouseConnectionSchema
| CreateHiveConnectionSchema
| CreateHDFSConnectionSchema
| CreateS3ConnectionSchema,
| CreateS3ConnectionSchema
| CreateSFTPConnectionSchema
| CreateFTPConnectionSchema
| CreateFTPSConnectionSchema
| CreateWebDAVConnectionSchema
| CreateSambaConnectionSchema,
Field(discriminator="type"),
]
ReadConnectionSchema = Annotated[
Expand All @@ -67,7 +97,12 @@
| ReadClickhouseConnectionSchema
| ReadHiveConnectionSchema
| ReadHDFSConnectionSchema
| ReadS3ConnectionSchema,
| ReadS3ConnectionSchema
| ReadSFTPConnectionSchema
| ReadFTPConnectionSchema
| ReadFTPSConnectionSchema
| ReadWebDAVConnectionSchema
| ReadSambaConnectionSchema,
Field(discriminator="type"),
]
UpdateConnectionSchema = Annotated[
Expand All @@ -78,7 +113,12 @@
| UpdateClickhouseConnectionSchema
| UpdateHiveConnectionSchema
| UpdateHDFSConnectionSchema
| UpdateS3ConnectionSchema,
| UpdateS3ConnectionSchema
| UpdateSFTPConnectionSchema
| UpdateFTPConnectionSchema
| UpdateFTPSConnectionSchema
| UpdateWebDAVConnectionSchema
| UpdateSambaConnectionSchema,
Field(discriminator="type"),
]

Expand Down
57 changes: 57 additions & 0 deletions syncmaster/schemas/v1/connections/ftp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# SPDX-FileCopyrightText: 2023-2024 MTS PJSC
# SPDX-License-Identifier: Apache-2.0

from pydantic import BaseModel, Field

from syncmaster.schemas.v1.auth import (
CreateBasicAuthSchema,
ReadBasicAuthSchema,
UpdateBasicAuthSchema,
)
from syncmaster.schemas.v1.connection_types import FTP_TYPE
from syncmaster.schemas.v1.connections.connection_base import (
CreateConnectionBaseSchema,
ReadConnectionBaseSchema,
UpdateConnectionBaseSchema,
)


class CreateFTPConnectionDataSchema(BaseModel):
host: str
port: int


class ReadFTPConnectionDataSchema(BaseModel):
host: str
port: int


class UpdateFTPConnectionDataSchema(BaseModel):
host: str | None = None
port: int | None = None


class CreateFTPConnectionSchema(CreateConnectionBaseSchema):
type: FTP_TYPE = Field(..., description="Connection type")
data: CreateFTPConnectionDataSchema = Field(
...,
alias="connection_data",
description=(
"Data required to connect to the remote server. These are the parameters that are specified in the URL request."
),
)
auth_data: CreateBasicAuthSchema = Field(
description="Credentials for authorization",
)


class ReadFTPConnectionSchema(ReadConnectionBaseSchema):
type: FTP_TYPE
data: ReadFTPConnectionDataSchema = Field(alias="connection_data")
auth_data: ReadBasicAuthSchema | None = None


class UpdateFTPConnectionSchema(UpdateConnectionBaseSchema):
type: FTP_TYPE
data: UpdateFTPConnectionDataSchema | None = Field(alias="connection_data", default=None)
auth_data: UpdateBasicAuthSchema | None = None
57 changes: 57 additions & 0 deletions syncmaster/schemas/v1/connections/ftps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# SPDX-FileCopyrightText: 2023-2024 MTS PJSC
# SPDX-License-Identifier: Apache-2.0

from pydantic import BaseModel, Field

from syncmaster.schemas.v1.auth import (
CreateBasicAuthSchema,
ReadBasicAuthSchema,
UpdateBasicAuthSchema,
)
from syncmaster.schemas.v1.connection_types import FTPS_TYPE
from syncmaster.schemas.v1.connections.connection_base import (
CreateConnectionBaseSchema,
ReadConnectionBaseSchema,
UpdateConnectionBaseSchema,
)


class CreateFTPSConnectionDataSchema(BaseModel):
host: str
port: int


class ReadFTPSConnectionDataSchema(BaseModel):
host: str
port: int


class UpdateFTPSConnectionDataSchema(BaseModel):
host: str | None = None
port: int | None = None


class CreateFTPSConnectionSchema(CreateConnectionBaseSchema):
type: FTPS_TYPE = Field(..., description="Connection type")
data: CreateFTPSConnectionDataSchema = Field(
...,
alias="connection_data",
description=(
"Data required to connect to the remote server. These are the parameters that are specified in the URL request."
),
)
auth_data: CreateBasicAuthSchema = Field(
description="Credentials for authorization",
)


class ReadFTPSConnectionSchema(ReadConnectionBaseSchema):
type: FTPS_TYPE
data: ReadFTPSConnectionDataSchema = Field(alias="connection_data")
auth_data: ReadBasicAuthSchema | None = None


class UpdateFTPSConnectionSchema(UpdateConnectionBaseSchema):
type: FTPS_TYPE
data: UpdateFTPSConnectionDataSchema | None = Field(alias="connection_data", default=None)
auth_data: UpdateBasicAuthSchema | None = None
2 changes: 1 addition & 1 deletion syncmaster/schemas/v1/connections/hdfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class CreateHDFSConnectionSchema(CreateConnectionBaseSchema):
...,
alias="connection_data",
description=(
"Data required to connect to the database. These are the parameters that are specified in the URL request."
"Data required to connect to the HDFS cluster. These are the parameters that are specified in the URL request."
),
)
auth_data: CreateBasicAuthSchema = Field(
Expand Down
2 changes: 1 addition & 1 deletion syncmaster/schemas/v1/connections/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class CreateS3ConnectionSchema(CreateConnectionBaseSchema):
...,
alias="connection_data",
description=(
"Data required to connect to the database. These are the parameters that are specified in the URL request."
"Data required to connect to the S3 bucket. These are the parameters that are specified in the URL request."
),
)
auth_data: CreateS3AuthSchema = Field(
Expand Down
Loading
Loading