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

Fixups to AzureFileShareService auth token #819

Open
wants to merge 33 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
2a6cd0d
use token-based credential instead of a storage key in Azure file sha…
motus Jul 8, 2024
951fdba
initialize auth service before azure fileshare in unit tests
motus Jul 8, 2024
9aeaa92
late initialization for azure fileshare _share_client; proper monkey …
motus Jul 9, 2024
54c308b
remove storageAccountKey parameter from azure_fileshare fixture
motus Jul 9, 2024
9b65bd7
Merge branch 'main' into sergiym/svc/fs_token_auth
motus Jul 10, 2024
101b593
Merge branch 'main' into sergiym/svc/fs_token_auth
motus Jul 10, 2024
71fae3c
Merge branch 'main' into sergiym/svc/fs_token_auth
motus Jul 12, 2024
4bc4c25
Merge branch 'main' of https://github.com/microsoft/MLOS into sergiym…
motus Jul 12, 2024
289af50
Merge branch 'sergiym/svc/fs_token_auth' of https://github.com/motus/…
motus Jul 12, 2024
ead96a1
black formatting updates
motus Jul 12, 2024
a46bcd4
Merge branch 'main' into sergiym/svc/fs_token_auth
motus Jul 15, 2024
68c6d0d
Merge branch 'main' into sergiym/svc/fs_token_auth
motus Jul 16, 2024
99172ed
Merge branch 'main' of https://github.com/microsoft/MLOS into sergiym…
motus Jul 19, 2024
8078d70
docformatter fixes
motus Jul 19, 2024
527ae66
Merge branch 'sergiym/svc/fs_token_auth' of https://github.com/motus/…
motus Jul 19, 2024
56704f6
Merge branch 'main' into sergiym/svc/fs_token_auth
motus Jul 19, 2024
5af8b6f
Merge branch 'main' into sergiym/svc/fs_token_auth
bpkroth Jul 22, 2024
378f073
Merge branch 'main' into sergiym/svc/fs_token_auth
motus Jul 22, 2024
f2b47c6
formatting fixes
motus Jul 22, 2024
e9e48f2
remove git merge artifact
motus Jul 22, 2024
2925ebb
more git merge fixes
motus Jul 22, 2024
00ff3bf
move sanity check into __init__
bpkroth Jul 23, 2024
fd45a8c
Merge remote-tracking branch 'origin/sergiym/svc/fs_token_auth' into …
bpkroth Jul 24, 2024
7895fe5
use the mock auth service
bpkroth Jul 24, 2024
72b6c15
refactor
bpkroth Jul 25, 2024
a33de94
comments
bpkroth Jul 25, 2024
d9747f9
Merge branch 'main' into fixes-to-pr-779
bpkroth Aug 8, 2024
941a1d6
tweaks to make the config error load time checkable
bpkroth Aug 8, 2024
c81e9f5
format
bpkroth Aug 8, 2024
c38c611
fixup
bpkroth Aug 8, 2024
fbf40b9
Merge branch 'main' into fixes-to-pr-779
bpkroth Aug 14, 2024
32e8a6d
Merge branch 'main' into fixes-to-pr-779
bpkroth Sep 23, 2024
0bec988
Merge branch 'main' into fixes-to-pr-779
motus Nov 19, 2024
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
22 changes: 15 additions & 7 deletions mlos_bench/mlos_bench/services/remote/azure/azure_fileshare.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import logging
import os
from typing import Any, Callable, Dict, List, Optional, Set, Union
from typing import Any, Callable, Dict, List, Optional, Set, Union, get_type_hints

from azure.core.credentials import TokenCredential
from azure.core.exceptions import ResourceNotFoundError
Expand Down Expand Up @@ -61,19 +61,27 @@ def __init__(
"storageFileShareName",
},
)
assert self._parent is not None and isinstance(
self._parent, SupportsAuth
), "Authorization service not provided. Include service-auth.jsonc?"
# Ensure that the parent service is an authentication service that provides
# a TokenCredential.
assert (
self._parent is not None
and isinstance(self._parent, SupportsAuth)
and get_type_hints(self._parent.get_credential).get("return") == TokenCredential
), (
"Azure Authentication service not provided. "
"Include services/remote/azure/service-auth.jsonc?"
)
self._auth_service: SupportsAuth[TokenCredential] = self._parent
self._share_client: Optional[ShareClient] = None

def _get_share_client(self) -> ShareClient:
"""Get the Azure file share client object."""
if self._share_client is None:
credential = self._auth_service.get_credential()
assert isinstance(
credential, TokenCredential
), f"Expected a TokenCredential, but got {type(credential)} instead."
assert isinstance(credential, TokenCredential), (
f"Expected a TokenCredential, but got {type(credential)} instead. "
"Include services/remote/azure/service-auth.jsonc?"
)
self._share_client = ShareClient.from_share_url(
self._SHARE_URL.format(
account_name=self.config["storageAccountName"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,26 @@ def test_load_service_config_examples(
"""Tests loading a config example."""
parent: Service = config_loader_service
config = config_loader_service.load_config(config_path, ConfigSchema.SERVICE)

# Add other services that require a SupportsAuth parent service as necessary.
# AzureFileShareService requires an AzureAuth service to be loaded as well.
# mock_auth_service_config = "services/remote/mock/mock_auth_service.jsonc"
azure_auth_service_config = "services/remote/azure/service-auth.jsonc"
requires_auth_service_parent = {
"AzureFileShareService",
"AzureFileShareService": azure_auth_service_config,
}
config_class_name = str(config.get("class", "MISSING CLASS")).rsplit(".", maxsplit=1)[-1]
if config_class_name in requires_auth_service_parent:
# AzureFileShareService requires an auth service to be loaded as well.
if auth_service_config_path := requires_auth_service_parent.get(config_class_name):
auth_service_config = config_loader_service.load_config(
"services/remote/mock/mock_auth_service.jsonc",
auth_service_config_path,
ConfigSchema.SERVICE,
)
auth_service = config_loader_service.build_service(
config=auth_service_config,
parent=config_loader_service,
)
parent = auth_service

# Make an instance of the class based on the config.
service_inst = config_loader_service.build_service(
config=config,
Expand Down
Loading