Skip to content

Commit 8746327

Browse files
authored
Add enforce_sso, disabled fields in tenant API (#538)
* added enforce_sso, disabled to tenant api * update search and test * Revert "update search and test" This reverts commit 6f1d75d. * fisx create tenant test * Update test_tenant.py
1 parent b3d1fde commit 8746327

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

descope/management/tenant.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ def create(
1111
id: Optional[str] = None,
1212
self_provisioning_domains: Optional[List[str]] = None,
1313
custom_attributes: Optional[dict] = None,
14+
enforce_sso: Optional[bool] = False,
15+
disabled: Optional[bool] = False,
1416
) -> dict:
1517
"""
1618
Create a new tenant with the given name. Tenant IDs are provisioned automatically, but can be provided
@@ -22,6 +24,8 @@ def create(
2224
self_provisioning_domains (List[str]): An optional list of domain that are associated with this tenant.
2325
Users authenticating from these domains will be associated with this tenant.
2426
custom_attributes (dict): Optional, set the different custom attributes values of the keys that were previously configured in Descope console app
27+
enforce_sso (bool): Optional, login to the tenant is possible only using the configured sso
28+
disabled (bool): Optional, login to the tenant will be disabled
2529
2630
Return value (dict):
2731
Return dict in the format
@@ -38,7 +42,7 @@ def create(
3842
response = self._auth.do_post(
3943
uri,
4044
Tenant._compose_create_update_body(
41-
name, id, self_provisioning_domains, custom_attributes
45+
name, id, self_provisioning_domains, custom_attributes, enforce_sso, disabled
4246
),
4347
pswd=self._auth.management_key,
4448
)
@@ -50,6 +54,8 @@ def update(
5054
name: str,
5155
self_provisioning_domains: Optional[List[str]] = None,
5256
custom_attributes: Optional[dict] = None,
57+
enforce_sso: Optional[bool] = False,
58+
disabled: Optional[bool] = False,
5359
):
5460
"""
5561
Update an existing tenant with the given name and domains. IMPORTANT: All parameters are used as overrides
@@ -61,6 +67,8 @@ def update(
6167
self_provisioning_domains (List[str]): An optional list of domain that are associated with this tenant.
6268
Users authenticating from these domains will be associated with this tenant.
6369
custom_attributes (dict): Optional, set the different custom attributes values of the keys that were previously configured in Descope console app
70+
enforce_sso (bool): Optional, login to the tenant is possible only using the configured sso
71+
disabled (bool): Optional, login to the tenant will be disabled
6472
6573
Raise:
6674
AuthException: raised if creation operation fails
@@ -73,7 +81,7 @@ def update(
7381
self._auth.do_post(
7482
uri,
7583
Tenant._compose_create_update_body(
76-
name, id, self_provisioning_domains, custom_attributes
84+
name, id, self_provisioning_domains, custom_attributes, enforce_sso, disabled
7785
),
7886
pswd=self._auth.management_key,
7987
)
@@ -184,11 +192,15 @@ def _compose_create_update_body(
184192
id: Optional[str],
185193
self_provisioning_domains: List[str],
186194
custom_attributes: Optional[dict] = None,
195+
enforce_sso: Optional[bool] = False,
196+
disabled: Optional[bool] = False,
187197
) -> dict:
188198
body: dict[str, Any] = {
189199
"name": name,
190200
"id": id,
191201
"selfProvisioningDomains": self_provisioning_domains,
202+
"enforceSSO": enforce_sso,
203+
"disabled": disabled
192204
}
193205
if custom_attributes is not None:
194206
body["customAttributes"] = custom_attributes

tests/management/test_tenant.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,19 +61,21 @@ def test_create(self):
6161
"name": "name",
6262
"id": "t1",
6363
"selfProvisioningDomains": ["domain.com"],
64+
"enforceSSO": False,
65+
"disabled": False,
6466
},
6567
allow_redirects=False,
6668
verify=True,
6769
timeout=DEFAULT_TIMEOUT_SECONDS,
6870
)
6971

70-
# Test success flow with custom attributes
72+
# Test success flow with custom attributes, enforce_sso, disabled
7173
with patch("requests.post") as mock_post:
7274
network_resp = mock.Mock()
7375
network_resp.ok = True
7476
network_resp.json.return_value = json.loads("""{"id": "t1"}""")
7577
mock_post.return_value = network_resp
76-
resp = client.mgmt.tenant.create("name", "t1", ["domain.com"], {"k1": "v1"})
78+
resp = client.mgmt.tenant.create("name", "t1", ["domain.com"], {"k1": "v1"}, enforce_sso=True, disabled=True)
7779
self.assertEqual(resp["id"], "t1")
7880
mock_post.assert_called_with(
7981
f"{common.DEFAULT_BASE_URL}{MgmtV1.tenant_create_path}",
@@ -88,6 +90,8 @@ def test_create(self):
8890
"id": "t1",
8991
"selfProvisioningDomains": ["domain.com"],
9092
"customAttributes": {"k1": "v1"},
93+
"enforceSSO": True,
94+
"disabled": True,
9195
},
9296
allow_redirects=False,
9397
verify=True,
@@ -116,7 +120,7 @@ def test_update(self):
116120
with patch("requests.post") as mock_post:
117121
mock_post.return_value.ok = True
118122
self.assertIsNone(
119-
client.mgmt.tenant.update("t1", "new-name", ["domain.com"])
123+
client.mgmt.tenant.update("t1", "new-name", ["domain.com"], enforce_sso=True, disabled=True)
120124
)
121125
mock_post.assert_called_with(
122126
f"{common.DEFAULT_BASE_URL}{MgmtV1.tenant_update_path}",
@@ -130,18 +134,20 @@ def test_update(self):
130134
"name": "new-name",
131135
"id": "t1",
132136
"selfProvisioningDomains": ["domain.com"],
137+
"enforceSSO": True,
138+
"disabled": True,
133139
},
134140
allow_redirects=False,
135141
verify=True,
136142
timeout=DEFAULT_TIMEOUT_SECONDS,
137143
)
138144

139-
# Test success flow with custom attributes
145+
# Test success flow with custom attributes, enforce_sso, disabled
140146
with patch("requests.post") as mock_post:
141147
mock_post.return_value.ok = True
142148
self.assertIsNone(
143149
client.mgmt.tenant.update(
144-
"t1", "new-name", ["domain.com"], {"k1": "v1"}
150+
"t1", "new-name", ["domain.com"], {"k1": "v1"}, enforce_sso=True, disabled=True
145151
)
146152
)
147153
mock_post.assert_called_with(
@@ -157,6 +163,8 @@ def test_update(self):
157163
"id": "t1",
158164
"selfProvisioningDomains": ["domain.com"],
159165
"customAttributes": {"k1": "v1"},
166+
"enforceSSO": True,
167+
"disabled": True,
160168
},
161169
allow_redirects=False,
162170
verify=True,

0 commit comments

Comments
 (0)