From ac4d50c6fff1af8a06fdccbad916cd8d4d2200d1 Mon Sep 17 00:00:00 2001 From: Loic Baron Date: Tue, 7 Feb 2017 07:18:23 +0100 Subject: [PATCH] CLoudLab integration --- myslice/urls.py | 2 ++ portal/cloudlabview.py | 53 ++++++++++++++++++++++++++++++++++ portal/templates/cloudlab.html | 33 +++++++++++++++++++++ 3 files changed, 88 insertions(+) create mode 100644 portal/cloudlabview.py create mode 100644 portal/templates/cloudlab.html diff --git a/myslice/urls.py b/myslice/urls.py index 8f108280..59397e5b 100644 --- a/myslice/urls.py +++ b/myslice/urls.py @@ -37,6 +37,7 @@ import portal.platformsview import portal.dashboardview import portal.homeview import portal.newsview +import portal.cloudlabview import portal.loginwidget platforms_view=portal.platformsview.PlatformsView.as_view() @@ -109,6 +110,7 @@ urls = [ # # Portal (r'^news/?$', portal.newsview.NewsView.as_view()), + (r'^cloudlab/?$', portal.cloudlabview.CloudView.as_view()), (r'^resources/(?P[^/]+)/?$', portal.sliceresourceview.SliceResourceView.as_view()), (r'^users/(?P[^/]+)/?$', portal.slicetabusers.SliceUserView.as_view()), (r'^my_url/?$', portal.omn.OMNView.as_view()), diff --git a/portal/cloudlabview.py b/portal/cloudlabview.py new file mode 100644 index 00000000..aabc3969 --- /dev/null +++ b/portal/cloudlabview.py @@ -0,0 +1,53 @@ +import json +from django.core.context_processors import csrf +from django.http import HttpResponseRedirect +from django.contrib.auth import authenticate, login, logout +from django.template import RequestContext +from django.shortcuts import render_to_response +from django.shortcuts import render + +from unfold.loginrequired import LoginRequiredAutoLogoutView +from manifold.core.query import Query +from manifoldapi.manifoldapi import execute_query + +from manifoldapi.manifoldresult import ManifoldResult +from myslice.configengine import ConfigEngine + +from myslice.theme import ThemeView +from myslice.settings import logger + +class CloudView (LoginRequiredAutoLogoutView, ThemeView): + template_name = 'cloudlab.html' + + def get (self, request, state=None): + env = {} + pkey = None + cert = None + account_query = Query().get('local:account').select('user_id','platform_id','auth_type','config') + account_details = execute_query(self.request, account_query) + # Get the accounts of the current logged in user + for account_detail in account_details: + try: + account_config = json.loads(account_detail['config']) + if 'user_private_key' in account_config: + pkey = account_config['user_private_key'] + if 'gid' in account_config: + cert = account_config['gid'] + except ValueError as e: + print('not a JSON') + + env['supername'] = 'Amira' + env['cert'] = cert + env['key'] = pkey + if request.user.is_authenticated(): + env['person'] = self.request.user + env['username'] = self.request.user + else: + env['person'] = None + env['username'] = None + + env['theme'] = self.theme + env['section'] = "" + + return render_to_response(self.template_name, env, context_instance=RequestContext(request)) + diff --git a/portal/templates/cloudlab.html b/portal/templates/cloudlab.html new file mode 100644 index 00000000..4133cb93 --- /dev/null +++ b/portal/templates/cloudlab.html @@ -0,0 +1,33 @@ +{% extends "layout_wide.html" %} +{% block content %} +

Your name is : {{username}}

+ + + + + +
+


+ A tool has requested your private certificate. +

+

If you accept, the tool will be able to act on your behalf. Click confirm below if you wish to proceed or close this window to cancel. +

+ +
+ + +
+ + + +{% endblock %} + -- 2.43.0