Skip to content

Commit

Permalink
Take pipeline remote url from env var (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
helenst authored Nov 3, 2017
1 parent 1e6b858 commit c326244
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
12 changes: 10 additions & 2 deletions storage_service/locations/api/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,16 @@ def obj_create(self, bundle, **kwargs):
create_default_locations = bundle.data.get('create_default_locations', False)
# Try to guess Pipeline's IP, if doing default setup
if create_default_locations:
ip = bundle.request.META.get('REMOTE_ADDR') or None
bundle.obj.remote_name = ip
# Use configured version of remote dashboard URL,
# or try to infer it if not configured
remote_name = (
settings.PIPELINE_REMOTE_NAME or
bundle.request.META.get('REMOTE_ADDR') or
None
)

bundle.obj.remote_name = remote_name

shared_path = bundle.data.get('shared_path', None)
bundle.obj.save(create_default_locations, shared_path)
return bundle
Expand Down
7 changes: 5 additions & 2 deletions storage_service/locations/models/pipeline.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import absolute_import
# stdlib, alphabetical
import logging
from urlparse import urlparse, urlunparse

# Core Django, alphabetical
from django.core import validators
Expand Down Expand Up @@ -140,8 +141,10 @@ def create_default_locations(self, shared_path=None):
# HTTP API CALLS

def _request_api(self, method, path, fields=None):
url = 'http://{}/api/{}'.format(
self.remote_name,
# Add http scheme if no scheme is present.
remote_name = urlunparse(urlparse(self.remote_name, scheme='http'))
url = '{}api/{}'.format(
remote_name,
path.lstrip('/'),
)
data = {
Expand Down
3 changes: 3 additions & 0 deletions storage_service/storage_service/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,9 @@ def get_env_variable(var_name):
ALLOW_USER_EDITS = True


PIPELINE_REMOTE_NAME = environ.get('SS_PIPELINE_REMOTE_NAME', '')


def is_true(env_str):
if env_str:
return env_str.lower() in ['true', 'yes', 'on', '1']
Expand Down

0 comments on commit c326244

Please sign in to comment.