forked from evmos/safe-config-service
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add S3 bucket integration for currency logos (safe-global#217)
- Add S3 storage integration using django-storages - Native currency logos are stored in the following path: safe-config/chains/{chain_id}_currency_logo.{ext} - Add the following environment variables: * DEFAULT_FILE_STORAGE (default is S3Boto3Storage) * AWS_ACCESS_KEY_ID (no default) * AWS_SECRET_ACCESS_KEY (no default) * AWS_STORAGE_BUCKET_NAME (no default) * AWS_S3_CUSTOM_DOMAIN (no default) - If S3Boto3Storage is set, the AWS environment variables also need to be set (an exception is thrown otherwise) - For local development FileSystemStorage can be used and files will be stored under {repoRoot}/media/ (see MEDIA_ROOT) - For testing purposes, FileSystemStorage is automatically set for all the tests and a temporary directory is created and removed on test execution
- Loading branch information
Showing
15 changed files
with
160 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,6 +77,9 @@ jobs: | |
SECRET_KEY: 'insecure_key_for_dev' | ||
POSTGRES_HOST: localhost | ||
POSTGRES_PORT: 5432 | ||
AWS_ACCESS_KEY_ID: 'example-aws-access-key-id' | ||
AWS_SECRET_ACCESS_KEY: 'example-aws-secret-access-key' | ||
AWS_STORAGE_BUCKET_NAME: 'example-aws-storage-bucket-name' | ||
steps: | ||
- name: Check out repository code | ||
uses: actions/[email protected] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -134,3 +134,4 @@ dmypy.json | |
data/ | ||
docker-compose.override.yml | ||
.vscode/ | ||
src/media/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,12 @@ | ||
boto3==1.18.36 | ||
Django==3.2.7 | ||
django-cors-headers==3.8.0 | ||
djangorestframework==3.12.4 | ||
djangorestframework-camel-case==1.2.0 | ||
django-storages==1.11.1 | ||
drf-yasg[validation]==1.20.0 | ||
gnosis-py==3.2.2 | ||
gunicorn==20.1.0 | ||
Pillow==8.3.2 | ||
psycopg2-binary==2.9.1 | ||
requests==2.26.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
src/chains/migrations/0025_alter_chain_currency_logo_uri.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Generated by Django 3.2.7 on 2021-09-06 15:05 | ||
|
||
from django.db import migrations, models | ||
|
||
import chains.models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("chains", "0024_remove_gas_price_fields"), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name="chain", | ||
name="currency_logo_uri", | ||
field=models.ImageField(upload_to=chains.models.native_currency_path), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from django.core.exceptions import ImproperlyConfigured | ||
from pytest_django.asserts import assertRaisesMessage | ||
|
||
from chains.apps import _validate_storage_setup | ||
|
||
|
||
# Overriding settings on app configuration seems to be quite complex | ||
# ie.: using @override_settings in a typical TestCase might not have | ||
# the intended effect due to the other on which Django initializes | ||
# some internals. | ||
# | ||
# Therefore a settings fixture is used: | ||
# https://pytest-django.readthedocs.io/en/latest/helpers.html#settings | ||
# | ||
# More reading: | ||
# https://stackoverflow.com/questions/31148172/django-override-setting-used-in-appconfig-ready-function | ||
# https://code.djangoproject.com/ticket/22002 | ||
def test_validate_storage_setup(settings): | ||
settings.DEFAULT_FILE_STORAGE = "storages.backends.s3boto3.S3Boto3Storage" | ||
settings.AWS_ACCESS_KEY_ID = None | ||
settings.AWS_SECRET_ACCESS_KEY = None | ||
settings.AWS_STORAGE_BUCKET_NAME = None | ||
|
||
assertRaisesMessage( | ||
ImproperlyConfigured, | ||
"Storage set to S3 but AWS is not configured", | ||
_validate_storage_setup, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import shutil | ||
import tempfile | ||
|
||
import pytest | ||
|
||
|
||
@pytest.fixture(autouse=True) | ||
def use_file_system_storage(settings): | ||
settings.DEFAULT_FILE_STORAGE = "django.core.files.storage.FileSystemStorage" | ||
|
||
|
||
@pytest.fixture(autouse=True) | ||
def use_tmp_media_root(settings): | ||
# Creates tmp directory for tests | ||
settings.MEDIA_ROOT = tempfile.mkdtemp() | ||
|
||
yield # run test | ||
|
||
# After running each test remove the tmp directory | ||
shutil.rmtree(settings.MEDIA_ROOT) |