From: Costas Yiotis Date: Mon, 24 Nov 2014 10:36:01 +0000 (+0200) Subject: Merge branch 'onelab' of ssh://git.onelab.eu/git/myslice into onelab X-Git-Tag: myslice-1.1~13^2~7 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=38deb95de7c5d9cad0dd75deb00b04971dbb01bc;hp=2c9a9c599775ea2ea440065a35aa6870a6d8d870;p=myslice.git Merge branch 'onelab' of ssh://git.onelab.eu/git/myslice into onelab --- diff --git a/portal/account.py b/portal/account.py new file mode 100644 index 00000000..7d08e1cf --- /dev/null +++ b/portal/account.py @@ -0,0 +1,45 @@ +from manifold.core.query import Query +from manifoldapi.manifoldapi import execute_query + +from datetime import datetime +import time +import dateutil.parser +import calendar + +import json, os, re, itertools + +class Account: + def __init__ (self, platform_id, user_id): + account_query = Query().get('local:account').select('user_id','platform_id','auth_type','config').filter_by('platform_id', '==', platform_id).filter_by('user_id', '==', user_id) + + account_details = execute_query(self.request, account_query) + self.user_id = account_details['user_id'] + self.platform_id = account_details['platform_id'] + self.auth_type = account_details['auth_type'] + self.config = account_details['config'] + account_config = json.loads(account_details['config']) + + self.usr_hrn = account_config.get('user_hrn',None) + self.pub_key = account_config.get('user_public_key',None) + self.reference = account_config.get ('reference_platform',None) + + self.user_cred = account_config.get('delegated_user_credential',None) + self.user_cred_expiration = get_expiration(self.user_cred) + + slice_creds = account_config.get('delegated_slice_credentials',None) + for slice_name, slice_cred in slice_creds.iteritems(): + self.slice_cred_expiration = get_expiration(self.slice_cred) + + self.auth_cred = account_config.get('delegated_authority_credentials',None) + self.auth_cred_expiration = get_expiration(self.auth_cred) + +def get_expiration (credential, format = 'UTC'): + exp_date = re.search('(.*)', credential) + if exp_date: + exp_date = exp_date.group(1) + if format == 'timestamp': + exp_date = calendar.timegm(dateutil.parser.parse(exp_date).utctimetuple()) + else: + exp_date = None + return exp_date + diff --git a/portal/accountview.py b/portal/accountview.py index 50483839..325796bc 100644 --- a/portal/accountview.py +++ b/portal/accountview.py @@ -16,8 +16,9 @@ from django.contrib.auth.decorators import login_required from myslice.theme import ThemeView +from portal.account import Account, get_expiration # -import json, os, re, itertools +import json, os, re, itertools, time from OpenSSL import crypto from Crypto.PublicKey import RSA @@ -210,7 +211,11 @@ class AccountView(LoginRequiredAutoLogoutView, ThemeView): if acc_user_cred == {} or acc_user_cred == 'N/A': user_cred = 'no_creds' else: - user_cred = 'has_creds' + exp_date = get_expiration(acc_user_cred, 'timestamp') + if exp_date < time.time(): + user_cred = 'creds_expired' + else: + user_cred = 'has_creds' context = super(AccountView, self).get_context_data(**kwargs) context['principal_acc'] = principal_acc_list diff --git a/portal/homeview.py b/portal/homeview.py index f1ac37cc..3e9514f3 100644 --- a/portal/homeview.py +++ b/portal/homeview.py @@ -17,9 +17,10 @@ from ui.topmenu import topmenu_items, the_user from myslice.configengine import ConfigEngine from myslice.theme import ThemeView +from portal.account import Account, get_expiration from portal.models import PendingSlice -import json +import json, time import activity.user class HomeView (FreeAccessView, ThemeView): @@ -97,8 +98,12 @@ class HomeView (FreeAccessView, ThemeView): if acc_user_cred == {} or acc_user_cred == 'N/A': user_cred = 'no_creds' else: - user_cred = 'has_creds' - + exp_date = get_expiration(acc_user_cred, 'timestamp') + if exp_date < time.time(): + user_cred = 'creds_expired' + else: + user_cred = 'has_creds' + # list the pending slices of this user pending_slices = [] for slices in PendingSlice.objects.filter(type_of_nodes__iexact=self.request.user).all(): @@ -160,7 +165,11 @@ class HomeView (FreeAccessView, ThemeView): if acc_user_cred == {} or acc_user_cred == 'N/A': user_cred = 'no_creds' else: - user_cred = 'has_creds' + exp_date = get_expiration(acc_user_cred, 'timestamp') + if exp_date < time.time(): + user_cred = 'creds_expired' + else: + user_cred = 'has_creds' # list the pending slices of this user pending_slices = [] diff --git a/portal/platform.py b/portal/platform.py new file mode 100644 index 00000000..f224056b --- /dev/null +++ b/portal/platform.py @@ -0,0 +1,21 @@ +from manifold.core.query import Query +from manifoldapi.manifoldapi import execute_query + +class Platform: + def __init__ (self, id = None, name = None): + if id is not None: + platform_query = Query().get('local:platform').select('platform_id','platform','gateway_type','disabled').filter_by('platform_id', '==', platform_id) + if name is not None: + platform_query = Query().get('local:platform').select('platform_id','platform','gateway_type','disabled').filter_by('platform', '==', platform) + + self.id = platform_query['platform_id'] + self.name = platform_query['platform'] + self.type = platform_query['gateway_type'] + self.disabled = platform_query['disabled'] + +#class Platforms: +# def __init__ (self): +# platforms_query = Query().get('local:platform').select('platform_id','platform','gateway_type','disabled') +# platforms_details = execute_query(self.request, platform_query) +# for platform_detail in platforms_details: +# Platform(id = platform_detail['platform_id']) diff --git a/portal/templates/onelab/onelab_account-view.html b/portal/templates/onelab/onelab_account-view.html index 549ec6b4..7ac95782 100644 --- a/portal/templates/onelab/onelab_account-view.html +++ b/portal/templates/onelab/onelab_account-view.html @@ -9,7 +9,10 @@ {%if 'no_creds' in user_cred %}

NO CREDENTIALS are delegated to the portal!

-{%endif%} + {%endif%} + {%if 'creds_expired' in user_cred %} +

EXPIRED CREDENTIALS Please delegate again your credentials to the portal!

+ {%endif%} {% if messages %} diff --git a/portal/templates/onelab/onelab_home-view.html b/portal/templates/onelab/onelab_home-view.html index 944bcbe6..9170b4af 100644 --- a/portal/templates/onelab/onelab_home-view.html +++ b/portal/templates/onelab/onelab_home-view.html @@ -51,6 +51,9 @@ {%if 'no_creds' in user_cred %}

NO CREDENTIALS are delegated to the portal!

{%endif%} + {%if 'creds_expired' in user_cred %} +

EXPIRED CREDENTIALS Please delegate again your credentials to the portal!

+ {%endif%}
{%if 'is_pi' in pi %} @@ -232,11 +235,31 @@ $('button#slicerequestbtn').click(function() { window.location="/portal/slice_request/"; }); -/*------- -List of slices has been moved in -portal/templates/base.html -This should go into session ---------*/ + + /* + Launch queries to get the resources and leases in Manifold Cache + */ + + $.post("/rest/resource/", function( data ) { + }); + $.post("/rest/lease/", function( data ) { + }); + + /*------- + List of slices has been moved in + portal/templates/base.html + This is now in localStorage + --------*/ + // myslice.user is in LocalStorage + if(myslice.user.slices.length>0){ + $.each( myslice.user.slices, function(i, val) { + /* + Launch a Query for each slice to get resources and leases in Manifold Cache + */ + $.post("/rest/slice/", { 'filters': { 'slice_hrn' : val } }, function(data) { + }); + }); + } }); {# widget "_widget-monitor.html" #}