Skip to content

Commit

Permalink
azure - identity upgrade fixes (cloud-custodian#6773)
Browse files Browse the repository at this point in the history
  • Loading branch information
stefangordon authored and Alex committed Jul 26, 2021
1 parent 12abc8e commit ba893d4
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 22 deletions.
4 changes: 1 addition & 3 deletions tools/c7n_azure/c7n_azure/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,10 @@ def __init__(self, cloud_endpoints, authorization_file=None, subscription_id_ove
elif self._auth_params.get('enable_cli_auth'):
auth_name = 'Azure CLI'
self._credential = AzureCliCredential()
account_info, error = _run_command('az account show --output json')
account_info = _run_command('az account show --output json')
account_json = json.loads(account_info)
self._auth_params['subscription_id'] = account_json['id']
self._auth_params['tenant_id'] = account_json['tenantId']
if error is not None:
raise Exception('Unable to query TenantId and SubscriptionId')

if subscription_id_override is not None:
self._auth_params['subscription_id'] = subscription_id_override
Expand Down
31 changes: 16 additions & 15 deletions tools/c7n_azure/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions tools/c7n_azure/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ azure-cosmosdb-table==1.0.6
azure-functions==1.7.2; python_version >= "3" and python_version < "4"
azure-graphrbac==0.61.1
azure-identity==1.6.0
azure-keyvault-certificates==4.2.1
azure-keyvault-keys==4.3.1
azure-keyvault-secrets==4.2.0
azure-keyvault-certificates==4.3.0
azure-keyvault-keys==4.4.0
azure-keyvault-secrets==4.3.0
azure-keyvault==4.1.0
azure-mgmt-apimanagement==1.0.0
azure-mgmt-applicationinsights==1.0.0
Expand All @@ -24,7 +24,7 @@ azure-mgmt-containerinstance==7.0.0
azure-mgmt-containerregistry==8.0.0b1
azure-mgmt-containerservice==15.1.0
azure-mgmt-core==1.2.2
azure-mgmt-cosmosdb==6.3.0
azure-mgmt-cosmosdb==6.4.0
azure-mgmt-costmanagement==1.0.0
azure-mgmt-databricks==1.0.0b1
azure-mgmt-datafactory==1.1.0
Expand Down
9 changes: 9 additions & 0 deletions tools/c7n_azure/tests_azure/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,15 @@ def test_initialize_session_principal(self):
self.assertEqual(s.get_subscription_id(), DEFAULT_SUBSCRIPTION_ID)
self.assertEqual(s.get_tenant_id(), DEFAULT_TENANT_ID)

@patch('c7n_azure.session._run_command')
def test_initialize_session_cli(self, mock_run):
mock_run.return_value = \
f'{{"id":"{DEFAULT_SUBSCRIPTION_ID}", "tenantId":"{DEFAULT_TENANT_ID}"}}'

s = Session()

self.assertEqual(s.get_subscription_id(), DEFAULT_SUBSCRIPTION_ID)

@patch('azure.identity.ClientSecretCredential.get_token')
@patch('c7n_azure.session.log.error')
def test_initialize_session_authentication_error(self, mock_log, mock_cred):
Expand Down

0 comments on commit ba893d4

Please sign in to comment.