Skip to content

Commit 21baf8b

Browse files
author
Andrei Neagu
committed
revert to discriminator to original field name type
1 parent 2f0862c commit 21baf8b

File tree

3 files changed

+22
-26
lines changed

3 files changed

+22
-26
lines changed

packages/models-library/src/models_library/api_schemas_clusters_keeper/clusters.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class ClusterState(StrAutoEnum):
1717

1818
class OnDemandCluster(BaseModel):
1919
endpoint: AnyUrl
20-
authentication: ClusterAuthentication = Field(discriminator="discriminator_type")
20+
authentication: ClusterAuthentication = Field(discriminator="type")
2121
state: ClusterState
2222
user_id: UserID
2323
wallet_id: WalletID | None

packages/models-library/src/models_library/api_schemas_directorv2/clusters.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,7 @@ class ClusterDetailsGet(ClusterDetails):
114114

115115
class ClusterCreate(BaseCluster):
116116
owner: GroupID | None = None # type: ignore[assignment]
117-
authentication: ExternalClusterAuthentication = Field(
118-
discriminator="discriminator_type"
119-
)
117+
authentication: ExternalClusterAuthentication = Field(discriminator="type")
120118
access_rights: dict[GroupID, ClusterAccessRights] = Field(
121119
alias="accessRights", default_factory=dict
122120
)
@@ -129,7 +127,7 @@ class ClusterCreate(BaseCluster):
129127
"type": ClusterTypeInModel.ON_PREMISE,
130128
"endpoint": "https://registry.osparc-development.fake.dev",
131129
"authentication": {
132-
"discriminator_type": "simple",
130+
"type": "simple",
133131
"username": "someuser",
134132
"password": "somepassword",
135133
},
@@ -141,7 +139,7 @@ class ClusterCreate(BaseCluster):
141139
"owner": 154,
142140
"endpoint": "https://registry.osparc-development.fake.dev",
143141
"authentication": {
144-
"discriminator_type": "simple",
142+
"type": "simple",
145143
"username": "someuser",
146144
"password": "somepassword",
147145
},
@@ -176,7 +174,7 @@ class ClusterPatch(BaseCluster):
176174
owner: GroupID | None = None # type: ignore[assignment]
177175
thumbnail: HttpUrl | None = None
178176
endpoint: AnyUrl | None = None # type: ignore[assignment]
179-
authentication: ExternalClusterAuthentication | None = Field(None, discriminator="discriminator_type") # type: ignore[assignment]
177+
authentication: ExternalClusterAuthentication | None = Field(None, discriminator="type") # type: ignore[assignment]
180178
access_rights: dict[GroupID, ClusterAccessRights] | None = Field( # type: ignore[assignment]
181179
default=None, alias="accessRights"
182180
)
@@ -207,5 +205,5 @@ class ClusterPing(BaseModel):
207205
authentication: ClusterAuthentication = Field(
208206
...,
209207
description="Dask gateway authentication",
210-
discriminator="discriminator_type",
208+
discriminator="type",
211209
)

packages/models-library/src/models_library/clusters.py

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,21 @@ class ClusterAccessRights(BaseModel):
4242

4343

4444
class BaseAuthentication(BaseModel):
45-
discriminator_type: str
45+
type: str
4646

4747
model_config = ConfigDict(frozen=True, extra="forbid")
4848

4949

5050
class SimpleAuthentication(BaseAuthentication):
51-
discriminator_type: Literal["simple"] = "simple"
51+
type: Literal["simple"] = "simple"
5252
username: str
5353
password: SecretStr
5454

5555
model_config = ConfigDict(
5656
json_schema_extra={
5757
"examples": [
5858
{
59-
"discriminator_type": "simple",
59+
"type": "simple",
6060
"username": "someuser",
6161
"password": "somepassword",
6262
},
@@ -66,28 +66,28 @@ class SimpleAuthentication(BaseAuthentication):
6666

6767

6868
class KerberosAuthentication(BaseAuthentication):
69-
discriminator_type: Literal["kerberos"] = "kerberos"
69+
type: Literal["kerberos"] = "kerberos"
7070

7171
model_config = ConfigDict(
7272
json_schema_extra={
7373
"examples": [
7474
{
75-
"discriminator_type": "kerberos",
75+
"type": "kerberos",
7676
},
7777
]
7878
}
7979
)
8080

8181

8282
class JupyterHubTokenAuthentication(BaseAuthentication):
83-
discriminator_type: Literal["jupyterhub"] = "jupyterhub"
83+
type: Literal["jupyterhub"] = "jupyterhub"
8484
api_token: str
8585

8686
model_config = ConfigDict(
8787
json_schema_extra={
8888
"examples": [
8989
{
90-
"discriminator_type": "jupyterhub",
90+
"type": "jupyterhub",
9191
"api_token": "some_jupyterhub_token",
9292
},
9393
]
@@ -96,15 +96,13 @@ class JupyterHubTokenAuthentication(BaseAuthentication):
9696

9797

9898
class NoAuthentication(BaseAuthentication):
99-
discriminator_type: Literal["none"] = "none"
99+
type: Literal["none"] = "none"
100100

101-
model_config = ConfigDict(
102-
json_schema_extra={"examples": [{"discriminator_type": "none"}]}
103-
)
101+
model_config = ConfigDict(json_schema_extra={"examples": [{"type": "none"}]})
104102

105103

106104
class TLSAuthentication(BaseAuthentication):
107-
discriminator_type: Literal["tls"] = "tls"
105+
type: Literal["tls"] = "tls"
108106
tls_ca_file: Path
109107
tls_client_cert: Path
110108
tls_client_key: Path
@@ -113,7 +111,7 @@ class TLSAuthentication(BaseAuthentication):
113111
json_schema_extra={
114112
"examples": [
115113
{
116-
"discriminator_type": "tls",
114+
"type": "tls",
117115
"tls_ca_file": "/path/to/ca_file",
118116
"tls_client_cert": "/path/to/cert_file",
119117
"tls_client_key": "/path/to/key_file",
@@ -147,7 +145,7 @@ class BaseCluster(BaseModel):
147145
authentication: ClusterAuthentication = Field(
148146
...,
149147
description="Dask gateway authentication",
150-
discriminator="discriminator_type",
148+
discriminator="type",
151149
)
152150
access_rights: dict[GroupID, ClusterAccessRights] = Field(default_factory=dict)
153151

@@ -176,7 +174,7 @@ class Cluster(BaseCluster):
176174
"owner": 1456,
177175
"endpoint": "tcp://default-dask-scheduler:8786",
178176
"authentication": {
179-
"discriminator_type": "simple",
177+
"type": "simple",
180178
"username": "someuser",
181179
"password": "somepassword",
182180
},
@@ -188,7 +186,7 @@ class Cluster(BaseCluster):
188186
"owner": 12,
189187
"endpoint": "https://registry.osparc-development.fake.dev",
190188
"authentication": {
191-
"discriminator_type": "simple",
189+
"type": "simple",
192190
"username": "someuser",
193191
"password": "somepassword",
194192
},
@@ -200,7 +198,7 @@ class Cluster(BaseCluster):
200198
"type": ClusterTypeInModel.AWS,
201199
"owner": 154,
202200
"endpoint": "https://registry.osparc-development.fake.dev",
203-
"authentication": {"discriminator_type": "kerberos"},
201+
"authentication": {"type": "kerberos"},
204202
"access_rights": {
205203
154: CLUSTER_ADMIN_RIGHTS, # type: ignore[dict-item]
206204
12: CLUSTER_MANAGER_RIGHTS, # type: ignore[dict-item]
@@ -215,7 +213,7 @@ class Cluster(BaseCluster):
215213
"owner": 2321,
216214
"endpoint": "https://registry.osparc-development.fake2.dev",
217215
"authentication": {
218-
"discriminator_type": "jupyterhub",
216+
"type": "jupyterhub",
219217
"api_token": "some_fake_token",
220218
},
221219
"access_rights": {

0 commit comments

Comments
 (0)