You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
depot_django/test_minio_connection.py

42 lines
1.4 KiB
Python

import os
import boto3
from botocore.exceptions import ClientError
def test_minio_connection():
minio_server_url = os.environ.get('MINIO_SERVER_URL')
access_key = os.environ.get('MINIO_ACCESS_KEY')
secret_key = os.environ.get('MINIO_SECRET_KEY')
secure = os.environ.get('MINIO_SECURE', 'False').lower() == 'true'
print(f"Attempting to connect to MinIO at: {minio_server_url}")
print(f"Using Access Key: {access_key}")
print(f"Secure connection: {secure}")
try:
s3_client = boto3.client(
's3',
endpoint_url=minio_server_url,
aws_access_key_id=access_key,
aws_secret_access_key=secret_key,
use_ssl=secure,
verify=False # For self-signed certs or local testing
)
print("Attempting to list buckets...")
response = s3_client.list_buckets()
print("Successfully listed buckets!")
print("Buckets:")
for bucket in response['Buckets']:
print(f" - {bucket['Name']}")
except ClientError as e:
print(f"MinIO ClientError: {e}")
print(f"Error Code: {e.response.get('Error', {}).get('Code')}")
print(f"Error Message: {e.response.get('Error', {}).get('Message')}")
except Exception as e:
print(f"An unexpected error occurred: {e}")
if __name__ == "__main__":
test_minio_connection()