Skip to content

Commit

Permalink
Adds calculate policy endpoint to admin client (#278)
Browse files Browse the repository at this point in the history
  • Loading branch information
bvertkin authored Oct 17, 2024
1 parent 6a836df commit 2ebd510
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ $ python examples/report_users_and_phones.py

```
$ nose2
Example: `cd tests/admin && nose2`
```

# Linting
Expand Down
17 changes: 17 additions & 0 deletions duo_client/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3625,6 +3625,23 @@ def get_policy_summary_v2(self):
response = self.json_api_call("GET", path, {})
return response

def calculate_policy(self, integration_key, user_id):
"""
Args:
integration_key - The integration_key of the application to evaluate. (required)
user_id - The user_id of the user to evaluate (required)
Returns (dict) - Dictionary containing "policy_elements" and "sections"
"""

path = "/admin/v2/policies/calculate"
response = self.json_api_call(
"GET",
path,
{"integration_key": integration_key, "user_id": user_id},
)
return response

def get_passport_config(self):
"""
Returns the current Passport configuration.
Expand Down
15 changes: 14 additions & 1 deletion tests/admin/test_policies.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,17 @@ def test_get_policy_summary(self):
uri, _ = response["uri"].split("?")

self.assertEqual(response["method"], "GET")
self.assertEqual(uri, "/admin/v2/policies/summary")
self.assertEqual(uri, "/admin/v2/policies/summary")

def test_calculate_policy(self):
ikey = "DI82WWNVI5Z4V10LZJR6"
ukey = "DUQU89MDEWOUR277H44G"

response = self.client.calculate_policy(integration_key=ikey, user_id=ukey)
uri, args = response["uri"].split("?")

self.assertEqual(response["method"], "GET")
self.assertEqual(uri, "/admin/v2/policies/calculate")
self.assertDictEqual(
util.params_to_dict(args), {"integration_key": [ikey], "user_id": [ukey]}
)

0 comments on commit 2ebd510

Please sign in to comment.