Skip to content

Commit 66eb799

Browse files
IlyasDevelopmentIlyas Gasanov
andauthored
[DOP-29495] Add Iceberg OAuth2ClientCredentials (#294)
Co-authored-by: Ilyas Gasanov <[email protected]>
1 parent 57a1d66 commit 66eb799

File tree

15 files changed

+437
-71
lines changed

15 files changed

+437
-71
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Added OAuth2ClientCredentials to Iceberg REST Catalog

poetry.lock

Lines changed: 107 additions & 43 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

syncmaster/dto/connections.py

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,8 @@ class HiveConnectionDTO(ConnectionDTO):
7474

7575

7676
@dataclass
77-
class IcebergRESTCatalogS3ConnectionDTO(ConnectionDTO):
77+
class IcebergRESTCatalogS3ConnectionBaseDTO(ConnectionDTO):
7878
metastore_url: str
79-
metastore_username: str
80-
metastore_password: str
8179
s3_warehouse_path: str
8280
s3_host: str
8381
s3_bucket: str
@@ -91,6 +89,33 @@ class IcebergRESTCatalogS3ConnectionDTO(ConnectionDTO):
9189
type: ClassVar[str] = "iceberg_rest_s3"
9290

9391

92+
@dataclass(kw_only=True)
93+
class IcebergRESTCatalogBasicAuthS3DTO(IcebergRESTCatalogS3ConnectionBaseDTO):
94+
metastore_username: str
95+
metastore_password: str
96+
metastore_auth_type: Literal["basic"] = "basic"
97+
98+
99+
@dataclass(kw_only=True)
100+
class IcebergRESTCatalogOAuth2ClientCredentialsS3DTO(IcebergRESTCatalogS3ConnectionBaseDTO):
101+
metastore_oauth2_client_id: str
102+
metastore_oauth2_client_secret: str
103+
metastore_oauth2_scopes: list[str]
104+
metastore_oauth2_resource: str | None = None
105+
metastore_oauth2_audience: str | None = None
106+
metastore_oauth2_server_uri: str | None = None
107+
metastore_auth_type: Literal["oauth2"] = "oauth2"
108+
109+
110+
# TODO: should be refactored
111+
class IcebergRESTCatalogS3ConnectionDTO:
112+
def __new__(cls, **data):
113+
if "metastore_oauth2_client_id" in data:
114+
return IcebergRESTCatalogOAuth2ClientCredentialsS3DTO(**data)
115+
116+
return IcebergRESTCatalogBasicAuthS3DTO(**data)
117+
118+
94119
@dataclass
95120
class HDFSConnectionDTO(ConnectionDTO):
96121
user: str

syncmaster/schemas/v1/auth/__init__.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,6 @@
66
ReadBasicAuthSchema,
77
UpdateBasicAuthSchema,
88
)
9-
from syncmaster.schemas.v1.auth.iceberg_rest_basic import (
10-
CreateIcebergRESTCatalogBasicAuthSchema,
11-
IcebergRESTCatalogBasicAuthSchema,
12-
ReadIcebergRESTCatalogBasicAuthSchema,
13-
UpdateIcebergRESTCatalogBasicAuthSchema,
14-
)
159
from syncmaster.schemas.v1.auth.s3 import (
1610
CreateS3AuthSchema,
1711
ReadS3AuthSchema,
@@ -41,8 +35,4 @@
4135
"UpdateSambaAuthSchema",
4236
"AuthTokenSchema",
4337
"TokenPayloadSchema",
44-
"IcebergRESTCatalogBasicAuthSchema",
45-
"CreateIcebergRESTCatalogBasicAuthSchema",
46-
"ReadIcebergRESTCatalogBasicAuthSchema",
47-
"UpdateIcebergRESTCatalogBasicAuthSchema",
4838
]
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# SPDX-FileCopyrightText: 2023-2024 MTS PJSC
2+
# SPDX-License-Identifier: Apache-2.0
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# SPDX-FileCopyrightText: 2023-2024 MTS PJSC
2+
# SPDX-License-Identifier: Apache-2.0
3+
from typing import Annotated
4+
5+
from pydantic import Field
6+
7+
from syncmaster.schemas.v1.auth.iceberg.basic import (
8+
CreateIcebergRESTCatalogBasicAuthSchema,
9+
ReadIcebergRESTCatalogBasicAuthSchema,
10+
UpdateIcebergRESTCatalogBasicAuthSchema,
11+
)
12+
from syncmaster.schemas.v1.auth.iceberg.oauth2_client_credentials import (
13+
CreateIcebergRESTCatalogOAuth2ClientCredentialsAuthSchema,
14+
ReadIcebergRESTCatalogOAuth2ClientCredentialsAuthSchema,
15+
UpdateIcebergRESTCatalogOAuth2ClientCredentialsAuthSchema,
16+
)
17+
18+
CreateIcebergRESTCatalogS3ConnectionAuthDataSchema = Annotated[
19+
CreateIcebergRESTCatalogBasicAuthSchema | CreateIcebergRESTCatalogOAuth2ClientCredentialsAuthSchema,
20+
Field(discriminator="type"),
21+
]
22+
23+
ReadIcebergRESTCatalogS3ConnectionAuthDataSchema = Annotated[
24+
ReadIcebergRESTCatalogBasicAuthSchema | ReadIcebergRESTCatalogOAuth2ClientCredentialsAuthSchema,
25+
Field(discriminator="type"),
26+
]
27+
28+
UpdateIcebergRESTCatalogS3ConnectionAuthDataSchema = Annotated[
29+
UpdateIcebergRESTCatalogBasicAuthSchema | UpdateIcebergRESTCatalogOAuth2ClientCredentialsAuthSchema,
30+
Field(discriminator="type"),
31+
]
File renamed without changes.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# SPDX-FileCopyrightText: 2023-2024 MTS PJSC
2+
# SPDX-License-Identifier: Apache-2.0
3+
from typing import Literal
4+
5+
from pydantic import BaseModel, Field, SecretStr
6+
7+
8+
class IcebergRESTCatalogOAuth2ClientCredentialsAuthSchema(BaseModel):
9+
type: Literal["iceberg_rest_oauth2_client_credentials_s3_basic"]
10+
11+
12+
class CreateIcebergRESTCatalogOAuth2ClientCredentialsAuthSchema(IcebergRESTCatalogOAuth2ClientCredentialsAuthSchema):
13+
metastore_oauth2_client_id: str
14+
metastore_oauth2_client_secret: SecretStr
15+
metastore_oauth2_scopes: list[str] = Field(default_factory=list)
16+
metastore_oauth2_resource: str | None = None
17+
metastore_oauth2_audience: str | None = None
18+
metastore_oauth2_server_uri: str | None = None
19+
s3_access_key: str
20+
s3_secret_key: SecretStr
21+
22+
23+
class ReadIcebergRESTCatalogOAuth2ClientCredentialsAuthSchema(IcebergRESTCatalogOAuth2ClientCredentialsAuthSchema):
24+
metastore_oauth2_client_id: str
25+
metastore_oauth2_scopes: list[str]
26+
metastore_oauth2_resource: str | None
27+
metastore_oauth2_audience: str | None
28+
metastore_oauth2_server_uri: str | None
29+
s3_access_key: str
30+
31+
32+
class UpdateIcebergRESTCatalogOAuth2ClientCredentialsAuthSchema(
33+
CreateIcebergRESTCatalogOAuth2ClientCredentialsAuthSchema,
34+
):
35+
metastore_oauth2_client_secret: SecretStr | None = None
36+
s3_secret_key: SecretStr | None = None
37+
38+
def get_secret_fields(self) -> tuple[str, ...]:
39+
return ("metastore_oauth2_client_secret", "s3_secret_key")

syncmaster/schemas/v1/connections/connection_base.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,23 @@
44

55
from syncmaster.schemas.v1.auth import (
66
ReadBasicAuthSchema,
7-
ReadIcebergRESTCatalogBasicAuthSchema,
87
ReadS3AuthSchema,
98
ReadSambaAuthSchema,
109
)
10+
from syncmaster.schemas.v1.auth.iceberg.basic import (
11+
ReadIcebergRESTCatalogBasicAuthSchema,
12+
)
13+
from syncmaster.schemas.v1.auth.iceberg.oauth2_client_credentials import (
14+
ReadIcebergRESTCatalogOAuth2ClientCredentialsAuthSchema,
15+
)
1116
from syncmaster.schemas.v1.types import NameConstr
1217

1318
ReadConnectionAuthDataSchema = (
14-
ReadBasicAuthSchema | ReadS3AuthSchema | ReadSambaAuthSchema | ReadIcebergRESTCatalogBasicAuthSchema
19+
ReadBasicAuthSchema
20+
| ReadS3AuthSchema
21+
| ReadSambaAuthSchema
22+
| ReadIcebergRESTCatalogBasicAuthSchema
23+
| ReadIcebergRESTCatalogOAuth2ClientCredentialsAuthSchema
1524
)
1625

1726

syncmaster/schemas/v1/connections/iceberg.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55

66
from pydantic import BaseModel, Field
77

8-
from syncmaster.schemas.v1.auth.iceberg_rest_basic import (
9-
CreateIcebergRESTCatalogBasicAuthSchema,
10-
ReadIcebergRESTCatalogBasicAuthSchema,
11-
UpdateIcebergRESTCatalogBasicAuthSchema,
8+
from syncmaster.schemas.v1.auth.iceberg.auth import (
9+
CreateIcebergRESTCatalogS3ConnectionAuthDataSchema,
10+
ReadIcebergRESTCatalogS3ConnectionAuthDataSchema,
11+
UpdateIcebergRESTCatalogS3ConnectionAuthDataSchema,
1212
)
1313
from syncmaster.schemas.v1.connection_types import ICEBERG_REST_S3_TYPE
1414
from syncmaster.schemas.v1.connections.connection_base import (
@@ -50,18 +50,18 @@ class CreateIcebergConnectionSchema(CreateConnectionBaseSchema):
5050
"Data required to connect to the database. These are the parameters that are specified in the URL request."
5151
),
5252
)
53-
auth_data: CreateIcebergRESTCatalogBasicAuthSchema = Field(
53+
auth_data: CreateIcebergRESTCatalogS3ConnectionAuthDataSchema = Field(
5454
description="Credentials for authorization",
5555
)
5656

5757

5858
class ReadIcebergConnectionSchema(ReadConnectionBaseSchema):
5959
type: ICEBERG_REST_S3_TYPE
6060
data: ReadIcebergRESTCatalogS3ConnectionDataSchema = Field(alias="connection_data")
61-
auth_data: ReadIcebergRESTCatalogBasicAuthSchema | None = None
61+
auth_data: ReadIcebergRESTCatalogS3ConnectionAuthDataSchema | None = None
6262

6363

6464
class UpdateIcebergConnectionSchema(CreateIcebergConnectionSchema):
65-
auth_data: UpdateIcebergRESTCatalogBasicAuthSchema = Field(
65+
auth_data: UpdateIcebergRESTCatalogS3ConnectionAuthDataSchema = Field(
6666
description="Credentials for authorization",
6767
)

0 commit comments

Comments
 (0)