This repository has been archived by the owner on Nov 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bump azure-cli and azure-cli-core to 2.31.0 (#1557)
* bump azure-cli and azure-cli-core to 2.31.0 and all required dependencies * Update src/cli/onefuzz/cred_wrapper.py Co-authored-by: Joe Ranweiler <joe@lemma.co> * updating credential wrapper * Update src/cli/onefuzz/azure_identity_credential_adapter.py Co-authored-by: Joe Ranweiler <joe@lemma.co> * updating credential wrapper * . Co-authored-by: stas <statis@microsoft.com> Co-authored-by: Joe Ranweiler <joe@lemma.co>
- Loading branch information
1 parent
5515aa1
commit c542189
Showing
10 changed files
with
115 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# ------------------------------------ | ||
# Copyright (c) Microsoft Corporation. | ||
# Licensed under the MIT License. | ||
# ------------------------------------ | ||
|
||
# Adapt credentials from azure-identity to be compatible with SDK that needs msrestazure or azure.common.credentials | ||
# Need msrest >= 0.6.0 | ||
# See also https://pypi.org/project/azure-identity/ | ||
|
||
# Source: https://github.com/jongio/azidext/blob/8374293bd80648f764237ddfc5f5223e7e98472b/python/azure_identity_credential_adapter.py | ||
|
||
from typing import Any | ||
|
||
from azure.core.pipeline import PipelineContext, PipelineRequest | ||
from azure.core.pipeline.policies import BearerTokenCredentialPolicy | ||
from azure.core.pipeline.transport import HttpRequest | ||
from azure.identity import DefaultAzureCredential | ||
from msrest.authentication import BasicTokenAuthentication | ||
|
||
|
||
class AzureIdentityCredentialAdapter(BasicTokenAuthentication): | ||
def __init__( | ||
self, | ||
credential: Any = None, | ||
resource_id: Any = "https://management.azure.com/.default", | ||
**kwargs: Any | ||
): | ||
"""Adapt any azure-identity credential to work with SDK that needs azure.common.credentials or msrestazure. | ||
Default resource is ARM (syntax of endpoint v2) | ||
:param credential: Any azure-identity credential (DefaultAzureCredential by default) | ||
:param str resource_id: The scope to use to get the token (default ARM) | ||
""" | ||
super(AzureIdentityCredentialAdapter, self).__init__({}) | ||
if credential is None: | ||
credential = DefaultAzureCredential() | ||
self._policy = BearerTokenCredentialPolicy(credential, resource_id, **kwargs) | ||
|
||
def _make_request(self) -> Any: | ||
return PipelineRequest( | ||
HttpRequest( | ||
"AzureIdentityCredentialAdapter", | ||
# This URL is not actually used. We just create a phony request to get credentials using only public APIs. | ||
# Use a standard Microsoft-controlled example URL anyway. | ||
"https://contoso.com", | ||
), | ||
PipelineContext(None), | ||
) | ||
|
||
def set_token(self) -> Any: | ||
"""Ask the azure-core BearerTokenCredentialPolicy policy to get a token. | ||
Using the policy gives us for free the caching system of azure-core. | ||
We could make this code simpler by using private method, but by definition | ||
I can't assure they will be there forever, so mocking a fake call to the policy | ||
to extract the token, using 100% public API.""" | ||
request = self._make_request() | ||
self._policy.on_request(request) | ||
# Read Authorization, and get the second part after Bearer | ||
token = request.http_request.headers["Authorization"].split(" ", 1)[1] | ||
self.token = {"access_token": token} | ||
|
||
def signed_session(self, session: Any = None) -> Any: | ||
self.set_token() | ||
return super(AzureIdentityCredentialAdapter, self).signed_session(session) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
azure-mgmt-storage~=18.0.0 | ||
azure-cli-core==2.27.2 | ||
azure-mgmt-storage~=19.0.0 | ||
azure-cli-core==2.31.0 | ||
azure-mgmt-eventgrid==3.0.0rc9 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
azure-common~=1.1.25 | ||
azure-identity==1.7.0 | ||
azure-identity==1.7.1 | ||
PyGithub==1.55 | ||
azure-cli-core==2.27.2 | ||
azure-cli-core==2.31.0 | ||
msgraph-core==0.2.2 |