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
4 changes: 3 additions & 1 deletion duo_client/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2947,7 +2947,7 @@ def get_admin(self, admin_id):
response = self.json_api_call('GET', path, {})
return response

def add_admin(self, name, email, phone, password, role=None):
def add_admin(self, name, email, phone, password, role=None, subaccount_role=None):
"""
Create an administrator and adds it to a customer.

Expand All @@ -2970,6 +2970,8 @@ def add_admin(self, name, email, phone, password, role=None):
params['phone'] = phone
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', '/admin/v1/admins', params)
return response

Expand Down
30 changes: 30 additions & 0 deletions examples/Admin/create_admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/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"): '),
)

NAME = get_next_arg('Admin name: ')
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: ')

created_admin = admin_api.add_admin(NAME, EMAIL, PHONE, PASSWORD, ROLE, SUBACCOUNT_ROLE)
print('Created Admin: ')
pprint.pprint(created_admin)
42 changes: 42 additions & 0 deletions tests/admin/test_admins.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,45 @@ def test_update_admin_password_mgmt_status_set_password(self):
'has_external_password_mgmt': 'True',
'password': 'dolphins'
})

def test_create_admin(self):
response = self.client.add_admin('test-name', 'test-email', 'test-phone', 'test-pswd')
self.assertEqual(response['method'], 'POST')
self.assertEqual(response['uri'], '/admin/v1/admins')
self.assertEqual(
json.loads(response['body']),
{
'account_id': self.client.account_id,
'name': 'test-name',
'email': 'test-email',
'phone': 'test-phone',
})

def test_create_admin_with_role(self):
response = self.client.add_admin('test-name', 'test-email', 'test-phone', 'test-pswd', 'test-role')
self.assertEqual(response['method'], 'POST')
self.assertEqual(response['uri'], '/admin/v1/admins')
self.assertEqual(
json.loads(response['body']),
{
'account_id': self.client.account_id,
'name': 'test-name',
'email': 'test-email',
'phone': 'test-phone',
'role': 'test-role',
})

def test_create_admin_with_subaccount_role(self):
response = self.client.add_admin('test-name', 'test-email', 'test-phone', 'test-pswd', 'test-role', 'test-subaccount-role')
self.assertEqual(response['method'], 'POST')
self.assertEqual(response['uri'], '/admin/v1/admins')
self.assertEqual(
json.loads(response['body']),
{
'account_id': self.client.account_id,
'name': 'test-name',
'email': 'test-email',
'phone': 'test-phone',
'role': 'test-role',
'subaccount_role': 'test-subaccount-role',
})