Skip to content

Conversation

@cisco-shivamk
Copy link
Contributor

Updated the duo_client_python code to be able to set the subaccount role through the admin api when updating an admin.

Description

  1. Modified update_admin() in admin.py for including subaccount role.
  2. Created an example for updating admin.
  3. Modified the test_admins.py to include tests for admin updation.
  4. Also, marked the optionality of role and subaccount for create_admin example.

Motivation and Context

We have recently added subaccount role to admin API, exactly the below endpoint. And, thus this repo needs an update to be able to use this addition to admin API.

endpoint: /admin/v1/admins

How Has This Been Tested?

  1. Unit testing done.
  2. Manually Tested using the example created.
    Output:
[Tested the change done to update_admin()]
(.env) shikalra@SHIKALRA-M-CR33 duo_client_python % python examples/Admin/update_admin.py
Admin API integration key ("DI..."): DIB659A1OZJL56C4CMS1
integration secret key: ZqRCqa9N3QFklAMoh1eEIWTqVekDxRW42pvhafBK
API hostname ("api-....duosecurity.com"): api-duo1.duo.test
Admin Id: DE3ZZF0WTPN4B9U6VUZC
Admin name: 
Phone number (e.g. 2154567890): 2154567891
password_change_required: 
status:
Administrative Role(Optional): 
Subaccount Role(Optional): 
Updated Admin: 
{'activation_url': 'https://admin-duo1.duo.test/admins/activation/DA6N7OXLH6BABW4APTZM/7b9bd773a0ae1b2ef69760682dd19fde',
 'activation_url_expires': 1742810156,
 'admin_id': 'DE3ZZF0WTPN4B9U6VUZC',
 'admin_units': [],
 'created': 1742205356,
 'email': 'testadmin92@testsk.com',
 'hardtoken': None,
 'last_directory_sync': None,
 'last_login': None,
 'name': 'Test Admin SK API 92',
 'password_change_required': False,
 'phone': '+12154567891',
 'restricted_by_admin_units': False,
 'role': 'Owner',
 'status': 'Pending Activation',
 'subaccount_role': None,
 'webauthncredentials': []}

[Tested the change done to create_admin example]
((.env) shikalra@SHIKALRA-M-CR33 duo_client_python % python examples/Admin/create_admin.py
Admin API integration key ("DI..."): DIB659A1OZJL56C4CMS1
integration secret key: ZqRCqa9N3QFklAMoh1eEIWTqVekDxRW42pvhafBK
API hostname ("api-....duosecurity.com"): api-duo1.duo.test
Admin name: Test Admin SK API 92
Email: testadmin92@testsk.com
Phone number (e.g. 2154567890): 2154567890
Password: test-pwd
Administrative Role(Optional): 
Subaccount Role(Optional): 
Created Admin: 
{'activation_url': 'https://admin-duo1.duo.test/admins/activation/DA6N7OXLH6BABW4APTZM/7b9bd773a0ae1b2ef69760682dd19fde',
 'activation_url_expires': 1742810156,
 'admin_id': 'DE3ZZF0WTPN4B9U6VUZC',
 'admin_units': [],
 'created': 1742205356,
 'email': 'testadmin92@testsk.com',
 'hardtoken': None,
 'last_directory_sync': None,
 'last_login': None,
 'name': 'Test Admin SK API 92',
 'password_change_required': False,
 'phone': '+12154567890',
 'restricted_by_admin_units': False,
 'role': 'Owner',
 'status': 'Pending Activation',
 'subaccount_role': None,
 'webauthncredentials': []}

Types of Changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

@cisco-shivamk cisco-shivamk marked this pull request as ready for review March 18, 2025 10:03
@AaronAtDuo AaronAtDuo merged commit c0767a8 into duosecurity:master Mar 18, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants