Skip to content

Commit c498b62

Browse files
committed
added enforce_sso, disabled to tenant api
1 parent 8a2e05f commit c498b62

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
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] = None,
15+
disabled: Optional[bool] = None,
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] = None,
58+
disabled: Optional[bool] = None,
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] = None,
196+
disabled: Optional[bool] = None,
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: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,13 @@ def test_create(self):
6666
timeout=DEFAULT_TIMEOUT_SECONDS,
6767
)
6868

69-
# Test success flow with custom attributes
69+
# Test success flow with custom attributes, enforce_sso, disabled
7070
with patch("requests.post") as mock_post:
7171
network_resp = mock.Mock()
7272
network_resp.ok = True
7373
network_resp.json.return_value = json.loads("""{"id": "t1"}""")
7474
mock_post.return_value = network_resp
75-
resp = client.mgmt.tenant.create("name", "t1", ["domain.com"], {"k1": "v1"})
75+
resp = client.mgmt.tenant.create("name", "t1", ["domain.com"], {"k1": "v1"}, enforce_sso=True, disabled=True)
7676
self.assertEqual(resp["id"], "t1")
7777
mock_post.assert_called_with(
7878
f"{common.DEFAULT_BASE_URL}{MgmtV1.tenant_create_path}",
@@ -86,6 +86,8 @@ def test_create(self):
8686
"id": "t1",
8787
"selfProvisioningDomains": ["domain.com"],
8888
"customAttributes": {"k1": "v1"},
89+
"enforceSSO": True,
90+
"disabled": True,
8991
},
9092
allow_redirects=False,
9193
verify=True,
@@ -133,12 +135,12 @@ def test_update(self):
133135
timeout=DEFAULT_TIMEOUT_SECONDS,
134136
)
135137

136-
# Test success flow with custom attributes
138+
# Test success flow with custom attributes, enforce_sso, disabled
137139
with patch("requests.post") as mock_post:
138140
mock_post.return_value.ok = True
139141
self.assertIsNone(
140142
client.mgmt.tenant.update(
141-
"t1", "new-name", ["domain.com"], {"k1": "v1"}
143+
"t1", "new-name", ["domain.com"], {"k1": "v1"}, enforce_sso=True, disabled=True
142144
)
143145
)
144146
mock_post.assert_called_with(
@@ -153,6 +155,8 @@ def test_update(self):
153155
"id": "t1",
154156
"selfProvisioningDomains": ["domain.com"],
155157
"customAttributes": {"k1": "v1"},
158+
"enforceSSO": True,
159+
"disabled": True,
156160
},
157161
allow_redirects=False,
158162
verify=True,

0 commit comments

Comments
 (0)