Skip to content

Commit ba63095

Browse files
committed
Create outbound application by DCR Preset
1 parent 0425586 commit ba63095

File tree

3 files changed

+73
-0
lines changed

3 files changed

+73
-0
lines changed

descope/management/common.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class MgmtV1:
4949

5050
# outbound application
5151
outbound_application_create_path = "/v1/mgmt/outbound/app/create"
52+
outbound_application_create_by_dcr_preset_path = "/v1/mgmt/outbound/app/create/bydcrpreset"
5253
outbound_application_update_path = "/v1/mgmt/outbound/app/update"
5354
outbound_application_delete_path = "/v1/mgmt/outbound/app/delete"
5455
outbound_application_load_path = "/v1/mgmt/outbound/app"

descope/management/outbound_application.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,31 @@ def create_application(
188188
)
189189
return response.json()
190190

191+
def create_application_by_dcr_preset(
192+
self,
193+
dcr_preset_id: str,
194+
) -> dict:
195+
"""
196+
Create a new outbound application using a DCR (Dynamic Client Registration) preset.
197+
198+
Args:
199+
dcr_preset_id (str): The ID of the DCR preset to use for creating the application.
200+
201+
Return value (dict):
202+
Return dict in the format
203+
{"app": {"id": <id>, "name": <name>, "description": <description>, "logo": <logo>}}
204+
205+
Raise:
206+
AuthException: raised if create operation fails
207+
"""
208+
uri = MgmtV1.outbound_application_create_by_dcr_preset_path
209+
response = self._auth.do_post(
210+
uri,
211+
{"dcrPresetId": dcr_preset_id},
212+
pswd=self._auth.management_key,
213+
)
214+
return response.json()
215+
191216
def update_application(
192217
self,
193218
id: str,

tests/management/test_outbound_application.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,53 @@ def test_create_application_failure(self):
126126
"Test App",
127127
)
128128

129+
def test_create_application_by_dcr_preset_success(self):
130+
client = DescopeClient(
131+
self.dummy_project_id,
132+
self.public_key_dict,
133+
False,
134+
self.dummy_management_key,
135+
)
136+
137+
with patch("requests.post") as mock_post:
138+
network_resp = mock.Mock()
139+
network_resp.ok = True
140+
network_resp.json.return_value = {
141+
"app": {
142+
"id": "app123",
143+
"name": "DCR Preset App",
144+
"description": "App created from DCR preset",
145+
}
146+
}
147+
mock_post.return_value = network_resp
148+
response = client.mgmt.outbound_application.create_application_by_dcr_preset(
149+
"dcr-preset-456"
150+
)
151+
152+
assert response == {
153+
"app": {
154+
"id": "app123",
155+
"name": "DCR Preset App",
156+
"description": "App created from DCR preset",
157+
}
158+
}
159+
160+
def test_create_application_by_dcr_preset_failure(self):
161+
client = DescopeClient(
162+
self.dummy_project_id,
163+
self.public_key_dict,
164+
False,
165+
self.dummy_management_key,
166+
)
167+
168+
with patch("requests.post") as mock_post:
169+
mock_post.return_value.ok = False
170+
self.assertRaises(
171+
AuthException,
172+
client.mgmt.outbound_application.create_application_by_dcr_preset,
173+
"dcr-preset-456",
174+
)
175+
129176
def test_update_application_success(self):
130177
client = DescopeClient(
131178
self.dummy_project_id,

0 commit comments

Comments
 (0)