From 2508b579a6f9d3fdeb3080aac55ed9ba5cf555dd Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Fri, 29 Jul 2022 22:09:07 -0700 Subject: [PATCH] upload: Replace boto3.Session with boto3.session.Session. boto3-stubs seems to have dropped the former for some reason. Signed-off-by: Anders Kaseorg --- tools/tail-ses | 12 ++++++------ tools/upload-release | 4 ++-- zerver/lib/test_helpers.py | 4 ++-- zerver/lib/upload.py | 4 ++-- .../0149_realm_emoji_drop_unique_constraint.py | 4 ++-- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/tools/tail-ses b/tools/tail-ses index 4ae522656f..8de0366b4f 100755 --- a/tools/tail-ses +++ b/tools/tail-ses @@ -14,7 +14,7 @@ import secrets from contextlib import contextmanager from typing import Iterator, List, Tuple, TypedDict -import boto3 +import boto3.session import orjson from django.conf import settings from mypy_boto3_ses import SESClient @@ -30,7 +30,7 @@ class IdentityArgsDict(TypedDict, total=False): def main() -> None: - session = boto3.Session() + session = boto3.session.Session() from_address = settings.NOREPLY_EMAIL_ADDRESS from_host = Address(addr_spec=from_address).domain @@ -69,7 +69,7 @@ def main() -> None: print_messages(session, queue_url) -def get_ses_arn(session: boto3.Session, args: argparse.Namespace) -> str: +def get_ses_arn(session: boto3.session.Session, args: argparse.Namespace) -> str: ses: SESClient = session.client("ses") notification_settings = ses.get_identity_notification_attributes(Identities=[args.identity]) @@ -85,7 +85,7 @@ def get_ses_arn(session: boto3.Session, args: argparse.Namespace) -> str: @contextmanager -def our_sqs_queue(session: boto3.Session, ses_topic_arn: str) -> Iterator[Tuple[str, str]]: +def our_sqs_queue(session: boto3.session.Session, ses_topic_arn: str) -> Iterator[Tuple[str, str]]: (_, _, _, region, account_id, topic_name) = ses_topic_arn.split(":") sqs: SQSClient = session.client("sqs") @@ -122,7 +122,7 @@ def our_sqs_queue(session: boto3.Session, ses_topic_arn: str) -> Iterator[Tuple[ @contextmanager def our_sns_subscription( - session: boto3.Session, ses_topic_arn: str, queue_arn: str + session: boto3.session.Session, ses_topic_arn: str, queue_arn: str ) -> Iterator[str]: sns: SNSClient = session.client("sns") try: @@ -141,7 +141,7 @@ def our_sns_subscription( sns.unsubscribe(SubscriptionArn=subscription_arn) -def print_messages(session: boto3.Session, queue_url: str) -> None: +def print_messages(session: boto3.session.Session, queue_url: str) -> None: sqs: SQSClient = session.client("sqs") try: while True: diff --git a/tools/upload-release b/tools/upload-release index 37f54590c1..8c4f91c870 100755 --- a/tools/upload-release +++ b/tools/upload-release @@ -12,7 +12,7 @@ from scripts.lib.setup_path import setup_path setup_path() -import boto3 +import boto3.session from mypy_boto3_s3 import S3Client from natsort import natsorted @@ -37,7 +37,7 @@ new_basename = os.path.basename(args.filename) if not new_basename.startswith("zulip-server-") or not new_basename.endswith(".tar.gz"): parser.error("File does not match zulip-server-*.tar.gz") -session = boto3.Session() +session = boto3.session.Session() client: S3Client = session.client("s3") bucket = session.resource("s3", region_name="us-east-1").Bucket("zulip-download") diff --git a/zerver/lib/test_helpers.py b/zerver/lib/test_helpers.py index 115e43308d..da9bf3aec7 100644 --- a/zerver/lib/test_helpers.py +++ b/zerver/lib/test_helpers.py @@ -23,7 +23,7 @@ from typing import ( ) from unittest import mock -import boto3 +import boto3.session import fakeldap import ldap import orjson @@ -564,7 +564,7 @@ def use_s3_backend(method: FuncT) -> FuncT: def create_s3_buckets(*bucket_names: str) -> List[Bucket]: - session = boto3.Session(settings.S3_KEY, settings.S3_SECRET_KEY) + session = boto3.session.Session(settings.S3_KEY, settings.S3_SECRET_KEY) s3 = session.resource("s3") buckets = [s3.create_bucket(Bucket=name) for name in bucket_names] return buckets diff --git a/zerver/lib/upload.py b/zerver/lib/upload.py index ed4fba9e35..e3a9f44820 100644 --- a/zerver/lib/upload.py +++ b/zerver/lib/upload.py @@ -331,7 +331,7 @@ class ZulipUploadBackend: def get_bucket(bucket_name: str, session: Optional[Session] = None) -> Bucket: if session is None: - session = boto3.Session(settings.S3_KEY, settings.S3_SECRET_KEY) + session = Session(settings.S3_KEY, settings.S3_SECRET_KEY) bucket = session.resource( "s3", region_name=settings.S3_REGION, endpoint_url=settings.S3_ENDPOINT_URL ).Bucket(bucket_name) @@ -418,7 +418,7 @@ def get_signed_upload_url(path: str, download: bool = False) -> str: class S3UploadBackend(ZulipUploadBackend): def __init__(self) -> None: - self.session = boto3.Session(settings.S3_KEY, settings.S3_SECRET_KEY) + self.session = Session(settings.S3_KEY, settings.S3_SECRET_KEY) self.avatar_bucket = get_bucket(settings.S3_AVATAR_BUCKET, self.session) self.uploads_bucket = get_bucket(settings.S3_AUTH_UPLOADS_BUCKET, self.session) diff --git a/zerver/migrations/0149_realm_emoji_drop_unique_constraint.py b/zerver/migrations/0149_realm_emoji_drop_unique_constraint.py index 1e5d09f3ec..ef43ddbf8c 100644 --- a/zerver/migrations/0149_realm_emoji_drop_unique_constraint.py +++ b/zerver/migrations/0149_realm_emoji_drop_unique_constraint.py @@ -1,7 +1,7 @@ import os import shutil -import boto3 +import boto3.session from django.conf import settings from django.db import migrations, models from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor @@ -61,7 +61,7 @@ class LocalUploader(Uploader): class S3Uploader(Uploader): def __init__(self) -> None: super().__init__() - session = boto3.Session(settings.S3_KEY, settings.S3_SECRET_KEY) + session = boto3.session.Session(settings.S3_KEY, settings.S3_SECRET_KEY) self.bucket_name = settings.S3_AVATAR_BUCKET self.bucket = session.resource( "s3", region_name=settings.S3_REGION, endpoint_url=settings.S3_ENDPOINT_URL