-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a618bd8
commit 41766f6
Showing
2 changed files
with
43 additions
and
40 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
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,38 @@ | ||
from azure.cli.core.aaz import register_client,AAZClientConfiguration | ||
from azure.cli.core.aaz._client import AAZMgmtClient | ||
import datetime | ||
|
||
@register_client("DupAadTokenClient") | ||
class AAZDupAadTokenClient(AAZMgmtClient): | ||
@classmethod | ||
def _build_configuration(cls, ctx, credential, **kwargs): | ||
from azure.cli.core.auth.util import resource_to_scopes | ||
from azure.core.pipeline.policies import HeadersPolicy | ||
|
||
token="Bearer "+credential.get_token().token | ||
headers_policy=HeadersPolicy(**kwargs) | ||
headers_policy.add_header("x-ms-aad-user-token",token) | ||
kwargs["headers_policy"]=headers_policy | ||
|
||
return AAZClientConfiguration( | ||
credential=credential, | ||
credential_scopes=resource_to_scopes(ctx.cli_ctx.cloud.endpoints.active_directory_resource_id), | ||
**kwargs | ||
) | ||
|
||
def ParseSubsFromResources(resourceList): | ||
"""Parse subscriptions from resources""" | ||
subs = set() | ||
for resource in resourceList: | ||
sub = resource.resource_id._data.split("/")[2] | ||
subs.add(sub) | ||
return list(subs) | ||
|
||
def GetLocalTimeZone(): | ||
"""Get local time zone""" | ||
return str(datetime.datetime.now(datetime.timezone.utc).astimezone().tzinfo) | ||
|
||
def GetClosestFullHour(): | ||
"""Get closest full hour""" | ||
now = datetime.datetime.now() | ||
return str(now.replace(minute=0, second=0, microsecond=0) + datetime.timedelta(hours=1)) |