From fc76444316432e76eac0319c0e3c91e37dfd86d1 Mon Sep 17 00:00:00 2001 From: Kostas Papadimitriou Date: Fri, 31 May 2013 17:56:32 +0300 Subject: [PATCH] Component/service friendly views - Enrich settings with setting keys shared with pithos-app in order to be able to properly resolve dynamically set urls and prefixes - Serve ui service of the pithos component --- snf-pithos-webclient/pithos_webclient/settings.py | 72 +++++++++++++++++--- .../pithos_webclient/synnefo_settings.py | 3 +- snf-pithos-webclient/pithos_webclient/urls.py | 7 +- snf-pithos-webclient/pithos_webclient/views.py | 6 +- 4 files changed, 73 insertions(+), 15 deletions(-) diff --git a/snf-pithos-webclient/pithos_webclient/settings.py b/snf-pithos-webclient/pithos_webclient/settings.py index c0f3208..a791407 100644 --- a/snf-pithos-webclient/pithos_webclient/settings.py +++ b/snf-pithos-webclient/pithos_webclient/settings.py @@ -32,16 +32,70 @@ # or implied, of GRNET S.A. from django.conf import settings +from synnefo.lib import join_urls, parse_base_url +from synnefo.util.keypath import get_path +from pithos_webclient.services import pithos_services +from astakosclient import astakos_services -# !!!!!ATTENTION!!!!! -# loginUrl MUST end at "next=". You should not give the value of the next -# parameter. It will be determined automatically -LOGIN_URL = getattr(settings, 'PITHOS_UI_LOGIN_URL', - 'https://accounts.synnefo.org/astakos/im/login?next=') +from copy import deepcopy + +# Process Pithos settings. This code is shared between snf-pithos-app and +# snf-pithos-webclient since they share the PITHOS_ settings prefix for most +# of their settings. + +# Top-level URL for Pithos. Must set. +BASE_URL = getattr(settings, 'PITHOS_BASE_URL', + "https://object-store.example.synnefo.org/pithos/") + +BASE_HOST, BASE_PATH = parse_base_url(BASE_URL) + +# Process Astakos settings +ASTAKOS_BASE_URL = getattr(settings, 'ASTAKOS_BASE_URL', + 'https://accounts.example.synnefo.org/astakos/') +ASTAKOS_BASE_HOST, ASTAKOS_BASE_PATH = parse_base_url(ASTAKOS_BASE_URL) + +PITHOS_PREFIX = get_path(pithos_services, 'pithos_object-store.prefix') +PUBLIC_PREFIX = get_path(pithos_services, 'pithos_public.prefix') +UI_PREFIX = get_path(pithos_services, 'pithos_ui.prefix') + +CUSTOMIZE_ASTAKOS_SERVICES = \ + getattr(settings, 'PITHOS_CUSTOMIZE_ASTAKOS_SERVICES', ()) +for path, value in CUSTOMIZE_ASTAKOS_SERVICES: + set_path(astakos_services, path, value, createpath=True) + +ASTAKOS_ACCOUNTS_PREFIX = get_path(astakos_services, 'astakos_account.prefix') +ASTAKOS_VIEWS_PREFIX = get_path(astakos_services, 'astakos_ui.prefix') +ASTAKOS_KEYSTONE_PREFIX = get_path(astakos_services, 'astakos_keystone.prefix') + +BASE_ASTAKOS_PROXY_PATH = getattr(settings, 'PITHOS_BASE_ASTAKOS_PROXY_PATH', + ASTAKOS_BASE_PATH) + +PROXY_USER_SERVICES = getattr(settings, 'PITHOS_PROXY_USER_SERVICES', True) + +# Base settings set. Resolve webclient required settings +ASTAKOS_ACCOUNTS_URL = join_urls(ASTAKOS_BASE_URL, ASTAKOS_ACCOUNTS_PREFIX) +if PROXY_USER_SERVICES: + ASTAKOS_ACCOUNTS_URL = join_urls('/', BASE_ASTAKOS_PROXY_PATH, + ASTAKOS_ACCOUNTS_PREFIX) + + +if not BASE_PATH.startswith("/"): + BASE_PATH = "/" + BASE_PATH + +ACCOUNTS_URL = getattr(settings, 'PITHOS_UI_ACCOUNTS_URL', + join_urls(ASTAKOS_ACCOUNTS_URL)) +USER_CATALOG_URL = getattr(settings, 'PITHOS_UI_USER_CATALOG_URL', + join_urls(ACCOUNTS_URL, 'user_catalogs')) FEEDBACK_URL = getattr(settings, 'PITHOS_UI_FEEDBACK_URL', - 'https://accounts.synnefo.org/astakos/im/feedback') + join_urls(ACCOUNTS_URL, 'feedback')) +PITHOS_URL = getattr(settings, 'PITHOS_UI_PITHOS_URL', + join_urls(BASE_PATH, PITHOS_PREFIX, 'v1')) AUTH_COOKIE_NAME = getattr(settings, 'PITHOS_UI_AUTH_COOKIE_NAME', '_pithos2_a') -CLOUDBAR_ACTIVE_SERVICE = getattr(settings, - 'PITHOS_UI_CLOUDBAR_ACTIVE_SERVICE', - 'pithos') + +DEFAULT_LOGIN_URL = join_urls(ASTAKOS_BASE_URL, ASTAKOS_VIEWS_PREFIX, 'login') +LOGIN_URL = getattr(settings, 'PITHOS_UI_LOGIN_URL', DEFAULT_LOGIN_URL) +CLOUDBAR_ACTIVE_SERVICE = getattr( + settings, + 'PITHOS_UI_CLOUDBAR_ACTIVE_SERVICE', + 'pithos') diff --git a/snf-pithos-webclient/pithos_webclient/synnefo_settings.py b/snf-pithos-webclient/pithos_webclient/synnefo_settings.py index e9997a4..74e1d85 100644 --- a/snf-pithos-webclient/pithos_webclient/synnefo_settings.py +++ b/snf-pithos-webclient/pithos_webclient/synnefo_settings.py @@ -49,6 +49,5 @@ context_processors = [ # namespace from django.conf.urls.defaults import include, patterns urlpatterns = patterns('', - (r'^ui/$', 'pithos_webclient.views.index'), - (r'^ui/index.html$', 'pithos_webclient.views.index'), + ('', include('pithos_webclient.urls')), ) diff --git a/snf-pithos-webclient/pithos_webclient/urls.py b/snf-pithos-webclient/pithos_webclient/urls.py index bc41d16..fc2c6a5 100644 --- a/snf-pithos-webclient/pithos_webclient/urls.py +++ b/snf-pithos-webclient/pithos_webclient/urls.py @@ -32,9 +32,12 @@ # or implied, of GRNET S.A. from django.conf.urls.defaults import include, patterns +from pithos_webclient import settings +from snf_django.lib.api.utils import prefix_pattern +from synnefo.lib import join_urls urlpatterns = patterns('', - (r'^$', 'pithos_webclient.views.index') + (prefix_pattern(join_urls(settings.BASE_PATH, settings.UI_PREFIX)), + 'pithos_webclient.views.index'), ) - diff --git a/snf-pithos-webclient/pithos_webclient/views.py b/snf-pithos-webclient/pithos_webclient/views.py index d1fd0a9..5fcf306 100644 --- a/snf-pithos-webclient/pithos_webclient/views.py +++ b/snf-pithos-webclient/pithos_webclient/views.py @@ -44,8 +44,10 @@ MEDIA_URL = getattr(settings, "PITHOS_WEB_CLIENT_MEDIA_URL", \ getattr(django_settings, "MEDIA_URL", "/static/")) URLS_CONFIG = { - 'STORAGE_API_URL': '/v1', - 'USER_CATALOGS_API_URL': '/user_catalog' + 'STORAGE_API_URL': settings.PITHOS_URL.rstrip('/') + '/', + 'USER_CATALOGS_API_URL': settings.USER_CATALOG_URL.rstrip('/') + '/', + 'loginUrl': settings.LOGIN_URL, + 'feedbackUrl': settings.FEEDBACK_URL } -- 1.7.10.4