Skip to content

Commit

Permalink
B2 now has an S3 compatible API so libcloud is no longer required
Browse files Browse the repository at this point in the history
  • Loading branch information
techlover1 committed May 5, 2020
1 parent a7038b8 commit ce93e6e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 26 deletions.
7 changes: 2 additions & 5 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,11 @@ db_name=olly
db_username=olly
db_password=secret_password

# Object storage credentials
# Use S3 for AWS S3 compatible. Use B2 for Backblaze B2
storage_type=
# Object storage credentials (AWS S3 compatable)
storage_key_id=
storage_secret_key=
storage_bucket_name=
# Note: This is only required for S3, not B2
storage_endpoint_url=
storage_endpoint_url=https://

# Your email server (for example smtp.gmail.com)
email_host=
Expand Down
27 changes: 7 additions & 20 deletions olly/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,26 +59,13 @@
# Media files
MEDIA_ROOT = os.path.join(BASE_DIR, 'olly/media')

if os.environ['storage_type'] == 'S3':
AWS_ACCESS_KEY_ID = os.environ['storage_key_id']
AWS_SECRET_ACCESS_KEY = os.environ['storage_secret_key']
AWS_S3_ENDPOINT_URL = os.environ['storage_endpoint_url']
AWS_STORAGE_BUCKET_NAME = os.environ['storage_bucket_name']
AWS_LOCATION = ''
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
MEDIA_URL = "%s/%s/" % (AWS_S3_ENDPOINT_URL, AWS_STORAGE_BUCKET_NAME)
elif os.environ['storage_type'] == 'B2':
LIBCLOUD_PROVIDERS = {
'backblaze': {
'type': 'libcloud.storage.types.Provider.BACKBLAZE_B2',
'user': os.environ['storage_key_id'],
'key': os.environ['storage_secret_key'],
'bucket': os.environ['storage_bucket_name'],
}
}
DEFAULT_LIBCLOUD_PROVIDER = 'backblaze'
DEFAULT_FILE_STORAGE = 'storages.backends.apache_libcloud.LibCloudStorage'
MEDIA_URL = 'https://f000.backblazeb2.com/file/%s/' % (LIBCLOUD_PROVIDERS['backblaze']['bucket'])
AWS_ACCESS_KEY_ID = os.environ['storage_key_id']
AWS_SECRET_ACCESS_KEY = os.environ['storage_secret_key']
AWS_S3_ENDPOINT_URL = os.environ['storage_endpoint_url']
AWS_STORAGE_BUCKET_NAME = os.environ['storage_bucket_name']
AWS_LOCATION = ''
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
MEDIA_URL = "%s/%s/" % (AWS_S3_ENDPOINT_URL, AWS_STORAGE_BUCKET_NAME)

# Email stuff
EMAIL_USE_TLS = os.environ['email_use_tls']
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@ psycopg2-binary>=2.7.4
pytz>=2018.4
boto3>=1.7.42
django-storages>=1.9.1
apache-libcloud>=2.7.0
django-cleanup

0 comments on commit ce93e6e

Please sign in to comment.