Skip to content

Commit

Permalink
Merge branch 'duosecurity:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkTripod-Duo authored Aug 29, 2024
2 parents 05cb207 + eef3b40 commit ecfb4f8
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 20 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@

**Accounts** - https://www.duosecurity.com/docs/accountsapi

**Activity** - TBD (As of now, the activity endpoint is not in general availability and is restricted to a few customers for private preview.
If you have any questions or need more information, feel free to reach out to support for guidance.)
**Activity** - The activity endpoint is in public preview and subject to change

## Tested Against Python Versions
* 3.7
Expand Down
39 changes: 32 additions & 7 deletions duo_client/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,15 +174,16 @@
{"code": 40401, "message": "Resource not found", "stat": "FAIL"}
"""

from . import client, Accounts
from .logs.telephony import Telephony
import warnings
import base64
import json
import time
import base64
import urllib.parse
import warnings
from datetime import datetime, timedelta, timezone

from . import Accounts, client
from .logs.telephony import Telephony

USER_STATUS_ACTIVE = "active"
USER_STATUS_BYPASS = "bypass"
USER_STATUS_DISABLED = "disabled"
Expand Down Expand Up @@ -538,9 +539,7 @@ def get_activity_logs(self, **kwargs):
"""
Returns activity log events.
As of now, the activity endpoint is not in general availability and is restricted to a few customers for private preview.
If you have any questions or need more information, feel free to reach out to support for guidance.
The activity endpoint is in public preview and subject to change.
mintime - Unix timestamp in ms; fetch records >= mintime
maxtime - Unix timestamp in ms; fetch records <= maxtime
Expand Down Expand Up @@ -2652,6 +2651,23 @@ def create_integration(self,
)
return response

def get_secret_key (self, integration_key):
"""Returns the secret key of the specified integration.
integration_key - The ikey of the secret key to get.
Returns the skey
Raises RuntimeError on error.
"""
params = {}
response = self.json_api_call(
'GET',
'/admin/v1/integrations/' + integration_key + '/skey',
params,
)
return response

def delete_integration(self, integration_key):
"""Deletes an integration.
Expand Down Expand Up @@ -3520,6 +3536,15 @@ def get_policy_summary_v2(self):
response = self.json_api_call("GET", path, {})
return response

def get_passport_config(self):
"""
Returns the current Passport configuration.
"""

path = "/admin/v2/passport/config"
response = self.json_api_call("GET", path, {})
return response


class AccountAdmin(Admin):
"""AccountAdmin manages a child account using an Accounts API integration."""
Expand Down
17 changes: 12 additions & 5 deletions examples/Admin/policies.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,22 @@ def update_policy_with_device_health_app(policy_key, print_response=False):
"""
Update a given policy to include Duo Device Health App policy
settings. Requires Access or Beyond editions.
NOTE: this function is deprecated, please use update_policy_with_duo_desktop
"""
return update_policy_with_duo_desktop(policy_key, print_response)

def update_policy_with_duo_desktop(policy_key, print_response=False):
"""
Update a given policy to include Duo Desktop policy
settings. Requires Access or Beyond editions.
"""

json_request = {
"sections": {
"device_health_app": {
"duo_desktop": {
"enforce_encryption": ["windows"],
"enforce_firewall": ["windows"],
"prompt_to_install": ["windows"],
"requires_DHA": ["windows"],
"requires_duo_desktop": ["windows"],
"windows_endpoint_security_list": ["cisco-amp"],
"windows_remediation_note": "Please install Windows agent",
},
Expand Down Expand Up @@ -139,8 +146,8 @@ def main():
policy_key_a = create_empty_policy("Test New Policy - a")
policy_key_b = create_empty_policy("Test New Policy - b")

# Update policy with Duo Device Health App settings.
update_policy_with_device_health_app(policy_key_b)
# Update policy with Duo Desktop settings.
update_policy_with_duo_desktop(policy_key_b)

# Create an empty policy and delete it.
policy_key_c = create_empty_policy("Test New Policy - c")
Expand Down
18 changes: 12 additions & 6 deletions examples/Admin/policies_advanced.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,20 +85,26 @@ def bulk_delete_section(policy_keys, print_response=False):
pretty = json.dumps(response, indent=4, sort_keys=True, default=str)
print(pretty)


def update_policy_with_device_health_app(policy_key, print_response=False):
"""
Update a given policy to include Duo Device Health App policy
settings. Requires Access or Beyond editions.
NOTE: this function is deprecated, please use update_policy_with_duo_desktop
"""
return update_policy_with_duo_desktop(policy_key, print_response)

def update_policy_with_duo_desktop(policy_key, print_response=False):
"""
Update a given policy to include Duo Desktop policy
settings. Requires Access or Beyond editions.
"""

json_request = {
"sections": {
"device_health_app": {
"duo_desktop": {
"enforce_encryption": ["windows"],
"enforce_firewall": ["windows"],
"prompt_to_install": ["windows"],
"requires_DHA": ["windows"],
"requires_duo_desktop": ["windows"],
"windows_endpoint_security_list": ["cisco-amp"],
"windows_remediation_note": "Please install Windows agent",
},
Expand Down Expand Up @@ -148,8 +154,8 @@ def main():
policy_key_a = create_empty_policy("Test New Policy - a")
policy_key_b = create_empty_policy("Test New Policy - b")

# Update policy with Duo Device Health App settings.
update_policy_with_device_health_app(policy_key_b)
# Update policy with Duo Desktop settings.
update_policy_with_duo_desktop(policy_key_b)

# Create an empty policy and delete it.
policy_key_c = create_empty_policy("Test New Policy - c")
Expand Down
13 changes: 13 additions & 0 deletions tests/admin/test_passport.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from .base import TestAdmin
from .. import util


class TestPassport(TestAdmin):
def test_get_passport(self):
""" Test get passport configuration
"""
response = self.client.get_passport_config()
(uri, args) = response['uri'].split('?')
self.assertEqual(response['method'], 'GET')
self.assertEqual(uri, '/admin/v2/passport/config')
self.assertEqual(util.params_to_dict(args), {'account_id': [self.client.account_id]})

0 comments on commit ecfb4f8

Please sign in to comment.