Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
ant0nsc committed Nov 2, 2023
1 parent f049798 commit 645bb1d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 22 deletions.
21 changes: 3 additions & 18 deletions hi-ml-azure/src/health_azure/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1903,20 +1903,6 @@ def _get_legitimate_default_credential() -> Optional[TokenCredential]:
return cred


def _get_legitimate_azureml_credential() -> Optional[TokenCredential]:
"""
Create a AzureMLOnBehalfOfCredential for interacting with Azure resources and validates it.
:return: A valid Azure credential.
"""
cred = AzureMLOnBehalfOfCredential()
try:
_validate_credential(cred)
return cred
except Exception:
return None


def _get_legitimate_interactive_browser_credential() -> Optional[TokenCredential]:
"""
Create an InteractiveBrowser credential for interacting with Azure resources. If the credential can't be
Expand Down Expand Up @@ -1960,10 +1946,9 @@ def get_credential() -> TokenCredential:
return cred
except ClientAuthenticationError:
if is_running_in_azure_ml():
# In AzureML, we can try the OnBehalfOf credential
cred = _get_legitimate_azureml_credential()
if cred is not None:
return cred
# In AzureML, we can try the AzureMLOnBehalfOfCredential credential. This credential does not need
# to be validated (in fact, it raises errors when we try to validate it by getting a token)
return AzureMLOnBehalfOfCredential()
else:
# Outside of AzureML, try any of the interactive authentication methods
cred = _get_legitimate_device_code_credential()
Expand Down
11 changes: 7 additions & 4 deletions hi-ml-azure/testazure/use_run_with_output_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@ def main() -> None:
resource_group_name = uri_segments[uri_segments.index("resourceGroups") + 1]
workspace_name = uri_segments[uri_segments.index("workspaces") + 1]
credential = AzureMLOnBehalfOfCredential()
client = MLClient(
ml_client = MLClient(
credential=credential,
subscription_id=subscription_id,
resource_group_name=resource_group_name,
workspace_name=workspace_name,
)
print("Got the client")

run_id = "sincere_yacht_xjz95gwvq8"
workspace = get_workspace()
run = workspace.get_run(run_id)
Expand All @@ -41,7 +42,6 @@ def main() -> None:
else:
print("No output datasets")

ml_client = get_ml_client()
job = ml_client.jobs.get(run_id)
output_dataset = job.outputs["OUTPUT_0"]

Expand All @@ -51,7 +51,7 @@ def main() -> None:
account_url = f"{datastore.protocol}://{datastore.account_name}.blob.{datastore.endpoint}"
print(f"{output_dataset.path}")

blob_client = BlobServiceClient(account_url=account_url, credential=get_credential())
blob_client = BlobServiceClient(account_url=account_url, credential=credential)
container_client = blob_client.get_container_client(datastore.container_name)

# List all blobs (files) inside a specific folder (prefix)
Expand All @@ -63,11 +63,14 @@ def main() -> None:
for blob_name in blob_list:
print(blob_name)

# Get the client without further authentication.
ml_client2 = get_ml_client()


if __name__ == "__main__":
submit_to_azure_if_needed(
snapshot_root_directory=Path(__file__).parents[2],
compute_cluster_name="ds2-with-id",
compute_cluster_name="lite-testing-ds2",
strictly_aml_v1=True,
submit_to_azureml=True,
)
Expand Down

0 comments on commit 645bb1d

Please sign in to comment.