FIX: show cred: shows only creds from myslice platform
[myslice.git] / portal / accountview.py
index 73b55fd..5447bce 100644 (file)
@@ -86,43 +86,44 @@ class AccountView(LoginRequiredAutoLogoutView):
                     account_pub_key = account_config.get('user_public_key','N/A')
                     account_reference = account_config.get ('reference_platform','N/A')
                     # credentials
-                    acc_user_cred = account_config.get('delegated_user_credential','N/A')
-                    acc_slice_cred = account_config.get('delegated_slice_credentials','N/A')
-                    acc_auth_cred = account_config.get('delegated_authority_credentials','N/A')
+                    if 'myslice' in platform_detail['platform']:
+                        acc_user_cred = account_config.get('delegated_user_credential','N/A')
+                        acc_slice_cred = account_config.get('delegated_slice_credentials','N/A')
+                        acc_auth_cred = account_config.get('delegated_authority_credentials','N/A')
 
-                    if 'N/A' not in acc_user_cred:
-                        exp_date = re.search('<expires>(.*)</expires>', acc_user_cred)
-                        if exp_date:
-                            user_exp_date = exp_date.group(1)
-                            user_cred_exp_list.append(user_exp_date)
+                        if 'N/A' not in acc_user_cred:
+                            exp_date = re.search('<expires>(.*)</expires>', acc_user_cred)
+                            if exp_date:
+                                user_exp_date = exp_date.group(1)
+                                user_cred_exp_list.append(user_exp_date)
 
-                        my_users = [{'cred_exp': t[0]}
-                            for t in zip(user_cred_exp_list)]
+                            my_users = [{'cred_exp': t[0]}
+                                for t in zip(user_cred_exp_list)]
                        
 
-                    if 'N/A' not in acc_slice_cred:
-                        for key, value in acc_slice_cred.iteritems():
-                            slice_list.append(key)
-                            # get cred_exp date
-                            exp_date = re.search('<expires>(.*)</expires>', value)
-                            if exp_date:
-                                exp_date = exp_date.group(1)
-                                slice_cred_exp_list.append(exp_date)
+                        if 'N/A' not in acc_slice_cred:
+                            for key, value in acc_slice_cred.iteritems():
+                                slice_list.append(key)
+                                # get cred_exp date
+                                exp_date = re.search('<expires>(.*)</expires>', value)
+                                if exp_date:
+                                    exp_date = exp_date.group(1)
+                                    slice_cred_exp_list.append(exp_date)
 
-                        my_slices = [{'slice_name': t[0], 'cred_exp': t[1]}
-                            for t in zip(slice_list, slice_cred_exp_list)]
+                            my_slices = [{'slice_name': t[0], 'cred_exp': t[1]}
+                                for t in zip(slice_list, slice_cred_exp_list)]
 
-                    if 'N/A' not in acc_auth_cred:
-                        for key, value in acc_auth_cred.iteritems():
-                            auth_list.append(key)
-                        #get cred_exp date
-                            exp_date = re.search('<expires>(.*)</expires>', value)
-                            if exp_date:
-                                exp_date = exp_date.group(1)
-                                auth_cred_exp_list.append(exp_date)
+                        if 'N/A' not in acc_auth_cred:
+                            for key, value in acc_auth_cred.iteritems():
+                                auth_list.append(key)
+                                #get cred_exp date
+                                exp_date = re.search('<expires>(.*)</expires>', value)
+                                if exp_date:
+                                    exp_date = exp_date.group(1)
+                                    auth_cred_exp_list.append(exp_date)
 
-                        my_auths = [{'auth_name': t[0], 'cred_exp': t[1]}
-                            for t in zip(auth_list, auth_cred_exp_list)]
+                            my_auths = [{'auth_name': t[0], 'cred_exp': t[1]}
+                                for t in zip(auth_list, auth_cred_exp_list)]
 
 
                     # for reference accounts
@@ -328,7 +329,7 @@ def account_process(request):
                         public_key = public_key.replace('"', '');
                         user_pub_key = {'keys': public_key}
                         sfa_update_user(request, user_hrn, user_pub_key)
-                        messages.success(request, 'Sucess: New Keypair Generated!')
+                        messages.success(request, 'Sucess: New Keypair Generated! Delegation of your credentials will be automatic.')
                         return HttpResponseRedirect("/portal/account/")
         else:
             messages.error(request, 'Account error: You need an account in myslice platform to perform this action')
@@ -413,6 +414,7 @@ def account_process(request):
                             user_params = { 'config': updated_config, 'auth_type':'user'}
                             manifold_update_account(request,user_params)
                             messages.success(request, 'Private Key deleted. You need to delegate credentials manually once it expires.')
+                            messages.success(request, 'Once your credentials expire, Please delegate manually using SFA: http://trac.myslice.info/wiki/DelegatingCredentials')
                             return HttpResponseRedirect("/portal/account/")
                         else:
                             messages.error(request, 'Delete error: Private key is not stored in the server')
@@ -432,10 +434,9 @@ def account_process(request):
                         user_cred = account_config.get('delegated_user_credential','N/A')
                         if 'N/A' not in user_cred:
                             user_hrn = account_config.get('user_hrn','N/A')
-                            user_pub_key = account_config.get('user_public_key','N/A')         
-                            user_priv_key = account_config.get('user_private_key','N/A')
-                            updated_config = '{"user_public_key":"'+ user_pub_key + '", "user_private_key":"'+ user_priv_key + '", "user_hrn":"'+ user_hrn + '"}'
-                            updated_config = ''.join(updated_config.split()) 
+                            user_pub_key = json.dumps(account_config.get('user_public_key','N/A'))
+                            user_priv_key = json.dumps(account_config.get('user_private_key','N/A'))
+                            updated_config = '{"user_public_key":'+ user_pub_key + ', "user_private_key":'+ user_priv_key + ', "user_hrn":"'+ user_hrn + '"}'
                             user_params = { 'config': updated_config}
                             manifold_update_account(request,user_params)
                             messages.success(request, 'All Credentials cleared')