From c8b444fca3de6c254ec23fb68864f67011485f6e Mon Sep 17 00:00:00 2001 From: Hannah Saloiye-Johnson Date: Fri, 6 Oct 2023 13:11:59 -0400 Subject: [PATCH 1/3] updating example code to create Account Admin with the child api_hostname per our api docs --- examples/get_billing_and_telephony_credits.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/get_billing_and_telephony_credits.py b/examples/get_billing_and_telephony_credits.py index 18bd1e6..8846d15 100644 --- a/examples/get_billing_and_telephony_credits.py +++ b/examples/get_billing_and_telephony_credits.py @@ -28,16 +28,16 @@ def get_next_arg(prompt): kwargs = { 'ikey': ikey, 'skey': skey, - 'host': host, } # Get all child accounts 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 account_admin_api = duo_client.admin.AccountAdmin( child_account['account_id'], + host = child_account['api_hostname'], **kwargs, ) try: From 59f2dc3571f23084f98b2905a0c451471f2a26ff Mon Sep 17 00:00:00 2001 From: Hannah Saloiye-Johnson Date: Mon, 9 Oct 2023 16:01:40 -0400 Subject: [PATCH 2/3] Bypassing the child_api_host lookup if the child_api_host is provided by the caller --- duo_client/admin.py | 26 +++++++++++-------- examples/get_billing_and_telephony_credits.py | 3 ++- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/duo_client/admin.py b/duo_client/admin.py index 1e7acc9..7a4162f 100644 --- a/duo_client/admin.py +++ b/duo_client/admin.py @@ -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) diff --git a/examples/get_billing_and_telephony_credits.py b/examples/get_billing_and_telephony_credits.py index 8846d15..37da606 100644 --- a/examples/get_billing_and_telephony_credits.py +++ b/examples/get_billing_and_telephony_credits.py @@ -28,6 +28,7 @@ def get_next_arg(prompt): kwargs = { 'ikey': ikey, 'skey': skey, + 'host': host, } # Get all child accounts @@ -37,7 +38,7 @@ def get_next_arg(prompt): # Create AccountAdmin with child account_id, child api_hostname and kwargs consisting of ikey, skey account_admin_api = duo_client.admin.AccountAdmin( child_account['account_id'], - host = child_account['api_hostname'], + child_api_host = child_account['api_hostname'], **kwargs, ) try: From fb52b3e69655bbfba626e8c09ccc864340d97650 Mon Sep 17 00:00:00 2001 From: Hannah Saloiye-Johnson Date: Mon, 9 Oct 2023 16:03:41 -0400 Subject: [PATCH 3/3] Updating example code comments --- examples/get_billing_and_telephony_credits.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/get_billing_and_telephony_credits.py b/examples/get_billing_and_telephony_credits.py index 37da606..12edbac 100644 --- a/examples/get_billing_and_telephony_credits.py +++ b/examples/get_billing_and_telephony_credits.py @@ -35,7 +35,7 @@ def get_next_arg(prompt): child_accounts = accounts_api.get_child_accounts() for child_account in child_accounts: - # Create AccountAdmin with child account_id, child api_hostname and kwargs consisting of ikey, skey + # 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'],