Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updating example code to create AccountAdmin with the child api_host… #235

Merged
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
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
Loading