diff --git a/CURRENT_VERSION b/CURRENT_VERSION index 0c89fc927e..99eba4de93 100644 --- a/CURRENT_VERSION +++ b/CURRENT_VERSION @@ -1 +1 @@ -4.0.0 \ No newline at end of file +4.1.0 \ No newline at end of file diff --git a/src/deployment/deploylib/set_admins.py b/src/deployment/deploylib/set_admins.py index 92e67d92bc..91e9cd2e4e 100644 --- a/src/deployment/deploylib/set_admins.py +++ b/src/deployment/deploylib/set_admins.py @@ -4,17 +4,74 @@ # Licensed under the MIT License. import argparse +import json +import logging +from typing import List, Optional from uuid import UUID from azure.common.client_factory import get_client_from_cli_profile from azure.cosmosdb.table.tableservice import TableService from azure.mgmt.storage import StorageManagementClient -from deploylib.configuration import ( - InstanceConfigClient, - update_admins, - update_allowed_aad_tenants, -) +storage_client_logger = logging.getLogger("azure.cosmosdb.table.common.storageclient") +TABLE_NAME = "InstanceConfig" + + +## Disable logging from storageclient. This module displays an error message +## when a resource is not found even if the exception is raised and handled internally. +## This happen when a table does not exist. An error message is displayed but the exception is +## handled by the library. +def disable_storage_client_logging() -> None: + if storage_client_logger: + storage_client_logger.disabled = True + + +def enable_storage_client_logging() -> None: + if storage_client_logger: + storage_client_logger.disabled = False + + +def create_if_missing(table_service: TableService) -> None: + try: + disable_storage_client_logging() + + if not table_service.exists(TABLE_NAME): + table_service.create_table(TABLE_NAME) + finally: + enable_storage_client_logging() + + +def update_allowed_aad_tenants( + table_service: TableService, resource_group: str, tenants: List[UUID] +) -> None: + create_if_missing(table_service) + as_str = [str(x) for x in tenants] + table_service.insert_or_merge_entity( + TABLE_NAME, + { + "PartitionKey": resource_group, + "RowKey": resource_group, + "allowed_aad_tenants": json.dumps(as_str), + }, + ) + + +def update_admins( + table_service: TableService, resource_group: str, admins: List[UUID] +) -> None: + create_if_missing(table_service) + admins_as_str: Optional[List[str]] = None + if admins: + admins_as_str = [str(x) for x in admins] + + table_service.insert_or_merge_entity( + TABLE_NAME, + { + "PartitionKey": resource_group, + "RowKey": resource_group, + "admins": json.dumps(admins_as_str), + }, + ) def main() -> None: @@ -33,11 +90,12 @@ def main() -> None: table_service = TableService( account_name=args.storage_account, account_key=storage_keys.keys[0].value ) - config_client = InstanceConfigClient(table_service, args.resource_group) if args.admins: - update_admins(config_client, args.admins) + update_admins(table_service, args.resource_group, args.admins) if args.allowed_aad_tenants: - update_allowed_aad_tenants(config_client, args.allowed_aad_tenants) + update_allowed_aad_tenants( + table_service, args.resource_group, args.allowed_aad_tenants + ) if __name__ == "__main__": diff --git a/src/utils/check-pr/check-pr.py b/src/utils/check-pr/check-pr.py index ec59c12c44..d23391042f 100755 --- a/src/utils/check-pr/check-pr.py +++ b/src/utils/check-pr/check-pr.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # # Copyright (c) Microsoft Corporation. # Licensed under the MIT License. @@ -188,9 +188,9 @@ def merge(self) -> None: def deploy(self, filename: str) -> None: print(f"deploying {filename} to {self.instance}") venv = "deploy-venv" - subprocess.check_call(f"python -mvenv {venv}", shell=True) + subprocess.check_call(f"python3 -mvenv {venv}", shell=True) pip = venv_path(venv, "pip") - py = venv_path(venv, "python") + py = venv_path(venv, "python3") config = os.path.join(os.getcwd(), "config.json") commands = [ ("extracting release-artifacts", f"unzip -qq {filename}"), @@ -212,8 +212,8 @@ def deploy(self, filename: str) -> None: def test(self, filename: str) -> None: venv = "test-venv" - subprocess.check_call(f"python -mvenv {venv}", shell=True) - py = venv_path(venv, "python") + subprocess.check_call(f"python3 -mvenv {venv}", shell=True) + py = venv_path(venv, "python3") test_dir = "integration-test-artifacts" script = "integration-test.py" endpoint = f"https://{self.instance}.azurewebsites.net" @@ -223,7 +223,7 @@ def test(self, filename: str) -> None: "extracting integration-test-artifacts", f"unzip -qq {filename} -d {test_dir}", ), - ("test venv", f"python -mvenv {venv}"), + ("test venv", f"python3 -mvenv {venv}"), ("installing wheel", f"./{venv}/bin/pip install -q wheel"), ("installing sdk", f"./{venv}/bin/pip install -q sdk/*.whl"), (