Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds calculate policy endpoint to admin client #278

Merged
merged 1 commit into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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`
spencermaxfield marked this conversation as resolved.
Show resolved Hide resolved
```

# 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]}
)
Loading