Add support for unsigned connections to S3 client when endpoint URL starts with 'http://' in StorageS3 constructor

This commit is contained in:
Sergey Krashevich 2023-05-23 22:21:45 +03:00
parent 5f4a107e8e
commit f60af0f212
No known key found for this signature in database
GPG Key ID: 625171324E7D3856

View File

@ -5,6 +5,9 @@ from pathlib import Path
import shutil import shutil
import threading import threading
import boto3 import boto3
from botocore import UNSIGNED
from botocore.config import Config
from botocore.session import Session as boto_session
from peewee import fn from peewee import fn
import os import os
import tempfile import tempfile
@ -24,12 +27,29 @@ class StorageS3:
def __init__(self, config: FrigateConfig) -> None: def __init__(self, config: FrigateConfig) -> None:
self.config = config self.config = config
if self.config.storage.s3.enabled: if self.config.storage.s3.enabled:
self.s3_client = boto3.client( if self.config.storage.s3.endpoint_url.startswith('http://'):
"s3", session = boto_session()
aws_access_key_id=self.config.storage.s3.access_key_id, session.set_config_variable('s3',
aws_secret_access_key=self.config.storage.s3.secret_access_key, {
endpoint_url=self.config.storage.s3.endpoint_url, 'use_ssl': False,
) 'verify': False,
}
)
self.s3_client = session.create_client(
"s3",
aws_access_key_id=self.config.storage.s3.access_key_id,
aws_secret_access_key=self.config.storage.s3.secret_access_key,
endpoint_url=self.config.storage.s3.endpoint_url,
config=Config(signature_version=UNSIGNED)
)
else:
self.s3_client = boto3.client(
"s3",
aws_access_key_id=self.config.storage.s3.access_key_id,
aws_secret_access_key=self.config.storage.s3.secret_access_key,
endpoint_url=self.config.storage.s3.endpoint_url,
)
self.s3_bucket = self.config.storage.s3.bucket_name self.s3_bucket = self.config.storage.s3.bucket_name
self.s3_path = self.config.storage.s3.path self.s3_path = self.config.storage.s3.path