diff --git a/duo_client/admin.py b/duo_client/admin.py index 491c60c..5dc029e 100644 --- a/duo_client/admin.py +++ b/duo_client/admin.py @@ -2956,6 +2956,7 @@ def add_admin(self, name, email, phone, password, role=None, subaccount_role=Non phone - password - Deprecated; ignored if specified. role - + subaccount_role - Returns the added administrator. See the adminapi docs. @@ -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. @@ -2991,6 +2994,8 @@ def update_admin(self, admin_id, password - Deprecated; ignored if specified. password_change_required - (optional) status - the status of the administrator (optional) - NOTE: Valid values are "Active" and "Disabled" - "Disabled" NOT valid for administrators with role - Owner + role - (optional) + subaccount_role - (optional) Returns the updated administrator. See the adminapi docs. @@ -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 diff --git a/examples/Admin/create_admin.py b/examples/Admin/create_admin.py index dd3aeca..71f59e6 100644 --- a/examples/Admin/create_admin.py +++ b/examples/Admin/create_admin.py @@ -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: ') diff --git a/examples/Admin/update_admin.py b/examples/Admin/update_admin.py new file mode 100644 index 0000000..093e70d --- /dev/null +++ b/examples/Admin/update_admin.py @@ -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) diff --git a/tests/admin/test_admins.py b/tests/admin/test_admins.py index df9a78a..2dad9b9 100644 --- a/tests/admin/test_admins.py +++ b/tests/admin/test_admins.py @@ -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', + })