From 48c9018a1a28bc07068ad95c098cda061174bb7b Mon Sep 17 00:00:00 2001 From: Kirill Izotov Date: Tue, 29 Apr 2014 14:44:06 +0700 Subject: [PATCH] Add authentication to dashboard Also: * fix authentication routine in mistralclient Change-Id: Ie7e0bd45e3108477b364966b413a474403e5c889 --- horizon_dashboard/README.rst | 10 +++++++++- .../demo_dashboard/dashboards/mistral/api.py | 18 +++++++++++++++++- mistralclient/api/client.py | 11 ++++++----- 3 files changed, 32 insertions(+), 7 deletions(-) diff --git a/horizon_dashboard/README.rst b/horizon_dashboard/README.rst index 90191d4e..9843d0bb 100644 --- a/horizon_dashboard/README.rst +++ b/horizon_dashboard/README.rst @@ -17,13 +17,21 @@ The following should get you started:: $ git clone https://github.com/stackforge/python-mistralclient.git $ cd python-mistralclient/horizon_dashboard - $ cp demo_dashboard/local/local_settings.py.example demo_dashboard/local/local_settings.py + $ cp demo_dashboard/local/local_settings.py.example \ + demo_dashboard/local/local_settings.py Edit the ``local_settings.py`` file as needed. Make sure you have changed OPENSTACK_HOST to point to your keystone server and also check all endpoints are accessible. You may want to change OPENSTACK_ENDPOINT_TYPE to "publicURL" if some of your endpoints are inaccessible. +You may also need to add a service and endpoints to keystone:: + + $ MISTRAL_URL="http://[host]:[port]/v1" + $ keystone service-create --name mistral --type workflow + $ keystone endpoint-create --service_id mistral --publicurl $MISTRAL_URL \ + --adminurl $MISTRAL_URL --internalurl $MISTRAL_URL + When you're ready to run the development server:: $ ./run_tests.sh --runserver diff --git a/horizon_dashboard/demo_dashboard/dashboards/mistral/api.py b/horizon_dashboard/demo_dashboard/dashboards/mistral/api.py index 486e6256..2a46a053 100644 --- a/horizon_dashboard/demo_dashboard/dashboards/mistral/api.py +++ b/horizon_dashboard/demo_dashboard/dashboards/mistral/api.py @@ -1,5 +1,21 @@ +from django.conf import settings + from mistralclient.api import client as mistral_client +SERVICE_TYPE = 'workflow' + def mistralclient(request): - return mistral_client.Client() + return mistral_client.Client( + username=request.user.username, + auth_token=request.user.token.id, + project_id=request.user.tenant_id, + # Ideally, we should get it from identity endpoint, but since + # python-mistralclient is not supporting v2.0 API it might create + # additional troubles for those who still rely on v2.0 stack-wise. + auth_url=getattr(settings, 'OPENSTACK_KEYSTONE_URL'), + # Todo: add SECONDARY_ENDPOINT_TYPE support + endpoint_type=getattr(settings, + 'OPENSTACK_ENDPOINT_TYPE', + 'internalURL'), + service_type=SERVICE_TYPE) diff --git a/mistralclient/api/client.py b/mistralclient/api/client.py index e6195ebe..0bd8b91e 100644 --- a/mistralclient/api/client.py +++ b/mistralclient/api/client.py @@ -95,11 +95,12 @@ class Client(object): project_id = keystone.project_id if not mistral_url: - catalog = keystone.service_catalog.get_endpoints(service_type) + catalog = keystone.service_catalog.get_endpoints( + service_type=service_type, + endpoint_type=endpoint_type + ) if service_type in catalog: - for e_type, endpoint in catalog.get[service_type][0].items(): - if str(e_type).lower() == str(endpoint_type).lower(): - mistral_url = endpoint - break + service = catalog.get(service_type) + mistral_url = service[0].get('url') if service else None return mistral_url, token, project_id, user_id