Skip to content

Commit

Permalink
updating example code to create AccountAdmin with the child api_host… (
Browse files Browse the repository at this point in the history
…#235)

* updating example code to create Account Admin with the child api_hostname per our api docs

* Bypassing the child_api_host lookup if the child_api_host is provided by the caller

* Updating example code comments
  • Loading branch information
hsaloiye authored Oct 10, 2023
1 parent cdf7da6 commit 603eeaf
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
26 changes: 15 additions & 11 deletions duo_client/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3433,19 +3433,23 @@ def get_policy_summary_v2(self):
class AccountAdmin(Admin):
"""AccountAdmin manages a child account using an Accounts API integration."""

def __init__(self, account_id, **kwargs):
def __init__(self, account_id, child_api_host=None, **kwargs):
"""Initializes an AccountAdmin for administering a child account.
account_id is the account id of the child account.
See the Client base class for other parameters."""
child_api_host = Accounts.child_map.get(account_id, None)
if child_api_host is None:
child_api_host = kwargs.get('host')
try:
accounts_api = Accounts(**kwargs)
accounts_api.get_child_accounts()
child_api_host = Accounts.child_map.get(account_id, kwargs['host'])
except RuntimeError:
pass
child_api_host is the api hostname of the child account.
If this is not provided, this value will be calculated for correct API usage.
See the Client base class for other parameters.
"""
if not child_api_host:
child_api_host = Accounts.child_map.get(account_id, None)
if child_api_host is None:
child_api_host = kwargs.get('host')
try:
accounts_api = Accounts(**kwargs)
accounts_api.get_child_accounts()
child_api_host = Accounts.child_map.get(account_id, kwargs['host'])
except RuntimeError:
pass
kwargs['host'] = child_api_host

super(AccountAdmin, self).__init__(**kwargs)
Expand Down
3 changes: 2 additions & 1 deletion examples/get_billing_and_telephony_credits.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ def get_next_arg(prompt):
child_accounts = accounts_api.get_child_accounts()

for child_account in child_accounts:
# Create AccountAdmin with child account_id and kwargs consisting of ikey, skey, and host
# Create AccountAdmin with child account_id, child api_hostname and kwargs consisting of ikey, skey, and host
account_admin_api = duo_client.admin.AccountAdmin(
child_account['account_id'],
child_api_host = child_account['api_hostname'],
**kwargs,
)
try:
Expand Down

0 comments on commit 603eeaf

Please sign in to comment.