Skip to content

Commit

Permalink
only ensure default provider and remove yaml config
Browse files Browse the repository at this point in the history
  • Loading branch information
John Tordoff committed Jun 28, 2022
1 parent 9f2e357 commit 91c24df
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 31 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -204,4 +204,3 @@ ssl/
# pyenv
.python-version

/storage-regions.yaml # contains secrets
28 changes: 17 additions & 11 deletions osf/migrations/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# -*- coding: utf-8 -*-
import sys
import yaml
import logging
from django.apps import apps
from django.db.utils import ProgrammingError
from website import settings
from django.core.management import call_command
from api.base import settings as api_settings
from addons.osfstorage.settings import DEFAULT_REGION_ID, DEFAULT_REGION_NAME

logger = logging.getLogger(__file__)

Expand Down Expand Up @@ -127,17 +128,22 @@ def update_permission_groups(sender, verbosity=0, **kwargs):


def update_storage_regions(sender, verbosity=0, **kwargs):
from django.apps import apps

if getattr(sender, 'label', None) == 'osf':
with open(settings.STORAGE_REGION_CONFIG_PATH, 'r') as stream:
features = yaml.safe_load(stream)
Region = apps.get_model('addons_osfstorage', 'Region')
for region in features['storage_regions']:
Region.objects.update_or_create(_id=region['_id'], defaults=region)

if 'pytest' not in sys.modules: # Allows for isolated tests without Regions
assert not Region.objects.all(), 'No storage regions found.'
ensure_default_storage_region()


def ensure_default_storage_region():
osfstorage_config = apps.get_app_config('addons_osfstorage')
Region = apps.get_model('addons_osfstorage', 'Region')
Region.objects.update_or_create(
_id=DEFAULT_REGION_ID,
defaults={
'name': DEFAULT_REGION_NAME,
'waterbutler_credentials': osfstorage_config.WATERBUTLER_CREDENTIALS,
'waterbutler_settings': osfstorage_config.WATERBUTLER_SETTINGS,
'waterbutler_url': settings.WATERBUTLER_URL
}
)


def create_cache_table(sender, verbosity=0, **kwargs):
Expand Down
13 changes: 0 additions & 13 deletions storage-regions-local.yaml

This file was deleted.

2 changes: 0 additions & 2 deletions website/settings/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -2101,5 +2101,3 @@ def from_node_usage(cls, usage_bytes, private_limit=None, public_limit=None):
CAS_LOG_LEVEL = 3 # ERROR

PREPRINT_METRICS_START_DATE = datetime.datetime(2019, 1, 1)

STORAGE_REGION_CONFIG_PATH = '/code/storage-regions.yaml'
2 changes: 0 additions & 2 deletions website/settings/local-dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,5 +142,3 @@ class CeleryConfig(defaults.CeleryConfig):
DATACITE_ENABLED = False

OOPSPAM_CHECK_IP = False

STORAGE_REGION_CONFIG_PATH = 'storage-regions-local.yaml'
2 changes: 0 additions & 2 deletions website/settings/local-travis.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,3 @@ class CeleryConfig(defaults.CeleryConfig):
SHARE_ENABLED = False
DATACITE_ENABLED = False
IA_ARCHIVE_ENABLED = False

STORAGE_REGION_CONFIG_PATH = 'storage-regions-local.yaml'

0 comments on commit 91c24df

Please sign in to comment.