mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-05 10:45:21 +03:00
Add error handling for S3 client creation in StorageS3 class
This commit is contained in:
parent
361e8604c8
commit
d257fd29ef
@ -8,6 +8,7 @@ import boto3
|
|||||||
from botocore import UNSIGNED
|
from botocore import UNSIGNED
|
||||||
from botocore.config import Config
|
from botocore.config import Config
|
||||||
from botocore.session import Session as boto_session
|
from botocore.session import Session as boto_session
|
||||||
|
from botocore.exceptions import BotoCoreError, ClientError
|
||||||
from peewee import fn
|
from peewee import fn
|
||||||
import os
|
import os
|
||||||
import tempfile
|
import tempfile
|
||||||
@ -28,6 +29,7 @@ class StorageS3:
|
|||||||
self.config = config
|
self.config = config
|
||||||
if self.config.storage.s3.enabled or self.config.storage.s3.archive:
|
if self.config.storage.s3.enabled or self.config.storage.s3.archive:
|
||||||
if self.config.storage.s3.endpoint_url.startswith('http://'):
|
if self.config.storage.s3.endpoint_url.startswith('http://'):
|
||||||
|
try:
|
||||||
session = boto_session()
|
session = boto_session()
|
||||||
session.set_config_variable('s3',
|
session.set_config_variable('s3',
|
||||||
{
|
{
|
||||||
@ -42,13 +44,20 @@ class StorageS3:
|
|||||||
endpoint_url=self.config.storage.s3.endpoint_url,
|
endpoint_url=self.config.storage.s3.endpoint_url,
|
||||||
config=Config(signature_version=UNSIGNED)
|
config=Config(signature_version=UNSIGNED)
|
||||||
)
|
)
|
||||||
|
except (BotoCoreError, ClientError) as error:
|
||||||
|
logger.error(f"Failed to create S3 client: {error}")
|
||||||
|
return None
|
||||||
else:
|
else:
|
||||||
|
try:
|
||||||
self.s3_client = boto3.client(
|
self.s3_client = boto3.client(
|
||||||
"s3",
|
"s3",
|
||||||
aws_access_key_id=self.config.storage.s3.access_key_id,
|
aws_access_key_id=self.config.storage.s3.access_key_id,
|
||||||
aws_secret_access_key=self.config.storage.s3.secret_access_key,
|
aws_secret_access_key=self.config.storage.s3.secret_access_key,
|
||||||
endpoint_url=self.config.storage.s3.endpoint_url,
|
endpoint_url=self.config.storage.s3.endpoint_url,
|
||||||
)
|
)
|
||||||
|
except (BotoCoreError, ClientError) as error:
|
||||||
|
logger.error(f"Failed to create S3 client: {error}")
|
||||||
|
return None
|
||||||
|
|
||||||
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
|
||||||
@ -57,8 +66,11 @@ class StorageS3:
|
|||||||
try:
|
try:
|
||||||
s3_filename = self.s3_path + "/" + os.path.relpath(file_path, RECORD_DIR)
|
s3_filename = self.s3_path + "/" + os.path.relpath(file_path, RECORD_DIR)
|
||||||
self.s3_client.upload_file(file_path, self.s3_bucket, s3_filename)
|
self.s3_client.upload_file(file_path, self.s3_bucket, s3_filename)
|
||||||
except Exception as e:
|
|
||||||
logger.debug(
|
logger.debug(
|
||||||
|
f"Uploading {file_path} to S3 {s3_filename}"
|
||||||
|
)
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(
|
||||||
f"Error occurred while uploading {file_path} to S3 {s3_filename}: {e}"
|
f"Error occurred while uploading {file_path} to S3 {s3_filename}: {e}"
|
||||||
)
|
)
|
||||||
return ""
|
return ""
|
||||||
@ -80,7 +92,7 @@ class StorageS3:
|
|||||||
logger.debug(f"Downloaded {s3_file_name} to {local_file_path}")
|
logger.debug(f"Downloaded {s3_file_name} to {local_file_path}")
|
||||||
return local_file_path
|
return local_file_path
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.debug(
|
logger.error(
|
||||||
f"Error occurred while downloading {s3_file_name} from S3: {e}"
|
f"Error occurred while downloading {s3_file_name} from S3: {e}"
|
||||||
)
|
)
|
||||||
return None
|
return None
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user