Skip to content
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
9 changes: 9 additions & 0 deletions duo_client/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2956,6 +2956,7 @@ def add_admin(self, name, email, phone, password, role=None, subaccount_role=Non
phone - <str:phone number>
password - Deprecated; ignored if specified.
role - <str|None:role>
subaccount_role - <str|None:role>

Returns the added administrator. See the adminapi docs.

Expand All @@ -2981,6 +2982,8 @@ def update_admin(self, admin_id,
password=None,
password_change_required=None,
status=None,
role=None,
subaccount_role=None
):
"""
Update one or more attributes of an administrator.
Expand All @@ -2991,6 +2994,8 @@ def update_admin(self, admin_id,
password - Deprecated; ignored if specified.
password_change_required - <bool|None:Whether admin is required to change their password at next login> (optional)
status - the status of the administrator (optional) - NOTE: Valid values are "Active" and "Disabled" - "Disabled" NOT valid for administrators with role - Owner
role - <str|None:role> (optional)
subaccount_role - <str|None:role> (optional)

Returns the updated administrator. See the adminapi docs.

Expand All @@ -3007,6 +3012,10 @@ def update_admin(self, admin_id,
params['password_change_required'] = password_change_required
if status is not None:
params['status'] = status
if role is not None:
params['role'] = role
if subaccount_role is not None:
params['subaccount_role'] = subaccount_role
response = self.json_api_call('POST', path, params)
return response

Expand Down
4 changes: 2 additions & 2 deletions examples/Admin/create_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ def get_next_arg(prompt):
EMAIL = get_next_arg('Email: ')
PHONE = get_next_arg('Phone number (e.g. 2154567890): ')
PASSWORD = get_next_arg('Password: ')
ROLE = get_next_arg('Administrative Role: ')
SUBACCOUNT_ROLE = get_next_arg('Subaccount Role: ')
ROLE = get_next_arg('Administrative Role(Optional): ') or None
SUBACCOUNT_ROLE = get_next_arg('Subaccount Role(Optional): ') or None

created_admin = admin_api.add_admin(NAME, EMAIL, PHONE, PASSWORD, ROLE, SUBACCOUNT_ROLE)
print('Created Admin: ')
Expand Down
37 changes: 37 additions & 0 deletions examples/Admin/update_admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/python
import pprint
import sys

import duo_client

argv_iter = iter(sys.argv[1:])
def get_next_arg(prompt):
try:
return next(argv_iter)
except StopIteration:
return input(prompt)

# Configuration and information about objects to create.
admin_api = duo_client.Admin(
ikey=get_next_arg('Admin API integration key ("DI..."): '),
skey=get_next_arg('integration secret key: '),
host=get_next_arg('API hostname ("api-....duosecurity.com"): '),
)

ADMIN_ID = get_next_arg('Admin Id: ')
NAME = get_next_arg('Admin name: ') or None
PHONE = get_next_arg('Phone number (e.g. 2154567890): ') or None
PASSWORD_CHANGE_REQ = get_next_arg('password_change_required: ') or None
STATUS = get_next_arg('status: ') or None
ROLE = get_next_arg('Administrative Role(Optional): ') or None
SUBACCOUNT_ROLE = get_next_arg('Subaccount Role(Optional): ') or None

updated_admin = admin_api.update_admin(admin_id=ADMIN_ID,
name=NAME,
phone=PHONE,
password_change_required=PASSWORD_CHANGE_REQ,
status=STATUS,
role=ROLE,
subaccount_role=SUBACCOUNT_ROLE)
print('Updated Admin: ')
pprint.pprint(updated_admin)
39 changes: 39 additions & 0 deletions tests/admin/test_admins.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,3 +217,42 @@ def test_create_admin_with_subaccount_role(self):
'role': 'test-role',
'subaccount_role': 'test-subaccount-role',
})

def test_update_admin_pass_all_params(self):
response = self.client.update_admin('test-id', 'test-name1', 'test-phone', None, False, 'test-status', 'test-role', 'test-subaccount-role')
self.assertEqual(response['method'], 'POST')
self.assertEqual(response['uri'], '/admin/v1/admins/test-id')
self.assertEqual(
json.loads(response['body']),
{
'account_id': self.client.account_id,
'name': 'test-name1',
'password_change_required': False,
'phone': 'test-phone',
'role': 'test-role',
'status': 'test-status',
'subaccount_role': 'test-subaccount-role',
})

def test_update_admin_pass_two_optional_params(self):
response = self.client.update_admin(admin_id='test-id', name='test-name2', status='test-status')
self.assertEqual(response['method'], 'POST')
self.assertEqual(response['uri'], '/admin/v1/admins/test-id')
self.assertEqual(
json.loads(response['body']),
{
'account_id': self.client.account_id,
'name': 'test-name2',
'status': 'test-status',
})

def test_update_admin_pass_one_optional_param(self):
response = self.client.update_admin(admin_id='test-id', name='test-name3')
self.assertEqual(response['method'], 'POST')
self.assertEqual(response['uri'], '/admin/v1/admins/test-id')
self.assertEqual(
json.loads(response['body']),
{
'account_id': self.client.account_id,
'name': 'test-name3',
})