Skip to content

Commit

Permalink
remove storage region configuration from the migration stream and add…
Browse files Browse the repository at this point in the history
… to config file
  • Loading branch information
John Tordoff committed Jun 26, 2022
1 parent 614673b commit 731cad8
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -204,3 +204,4 @@ ssl/
# pyenv
.python-version

/storage-regions.yaml # contains secrets
6 changes: 5 additions & 1 deletion osf/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from django.apps import AppConfig as BaseAppConfig
from django.db.models.signals import post_migrate
from osf.migrations import update_permission_groups
from osf.migrations import update_permission_groups, update_storage_regions


class AppConfig(BaseAppConfig):
Expand All @@ -16,3 +16,7 @@ def ready(self):
update_permission_groups,
dispatch_uid='osf.apps.update_permissions_groups'
)
post_migrate.connect(
update_storage_regions,
dispatch_uid='osf.apps.update_storage_regions'
)
18 changes: 18 additions & 0 deletions osf/migrations/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# -*- coding: utf-8 -*-
import sys
import yaml
import logging
from django.db.utils import ProgrammingError
from website import settings

logger = logging.getLogger(__file__)

Expand Down Expand Up @@ -52,6 +55,7 @@ def get_admin_write_permissions():
'delete_preprintprovider',
'change_subject',
'change_maintenancestate',
'change_registrationschema',
'delete_maintenancestate',
'change_scheduledbanner',
'delete_scheduledbanner',
Expand Down Expand Up @@ -118,3 +122,17 @@ def update_permission_groups(sender, verbosity=0, **kwargs):
if getattr(sender, 'label', None) == 'osf':
update_admin_permissions(verbosity)
update_provider_auth_groups(verbosity)


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.'
13 changes: 13 additions & 0 deletions storage-regions-local.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# This is used to populate fake storage region's for use in development, urls and file paths in this file should point
# to urls and file paths in test environments and services.
storage_regions:
- _id: us # default
name: United States
waterbutler_credentials:
storage: {}
waterbutler_url: http://localhost:7777
mfr_url: http://localhost:7778
waterbutler_settings:
storage:
folder: /code/website/osfstoragecache
provider: filesystem
2 changes: 2 additions & 0 deletions website/settings/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -2101,3 +2101,5 @@ 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: 2 additions & 0 deletions website/settings/local-dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,5 @@ class CeleryConfig(defaults.CeleryConfig):
DATACITE_ENABLED = False

OOPSPAM_CHECK_IP = False

STORAGE_REGION_CONFIG_PATH = 'storage-regions-local.yaml'
2 changes: 2 additions & 0 deletions website/settings/local-travis.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,5 @@ 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 731cad8

Please sign in to comment.