From b6aa998ec3a8a7d8d9da0088bffb9c939fcbe2ad Mon Sep 17 00:00:00 2001 From: elay Date: Thu, 20 Jun 2024 10:25:21 -0700 Subject: [PATCH] use azure clients as context manager --- pcfuncs/ipban/__init__.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/pcfuncs/ipban/__init__.py b/pcfuncs/ipban/__init__.py index 6e3d66fd..7a7d1ce0 100644 --- a/pcfuncs/ipban/__init__.py +++ b/pcfuncs/ipban/__init__.py @@ -2,7 +2,7 @@ import logging import azure.functions as func -from azure.data.tables import TableClient, TableServiceClient +from azure.data.tables import TableServiceClient from azure.identity import DefaultAzureCredential from azure.monitor.query import LogsQueryClient @@ -18,12 +18,10 @@ def main(mytimer: func.TimerRequest) -> None: ) logger.info("Updating the ip ban list at %s", utc_timestamp) credential: DefaultAzureCredential = DefaultAzureCredential() - logs_query_client: LogsQueryClient = LogsQueryClient(credential) - table_service_client: TableServiceClient = TableServiceClient( + with LogsQueryClient(credential) as logs_query_client, TableServiceClient( endpoint=settings.storage_account_url, credential=credential - ) - table_client: TableClient = table_service_client.create_table_if_not_exists( + ) as table_service_client, table_service_client.create_table_if_not_exists( settings.banned_ip_table - ) - task: UpdateBannedIPTask = UpdateBannedIPTask(logs_query_client, table_client) - task.run() + ) as table_client: + task = UpdateBannedIPTask(logs_query_client, table_client) + task.run()