Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id BDDFB200BB8 for ; Fri, 28 Oct 2016 18:45:53 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id BCAAE160AF5; Fri, 28 Oct 2016 16:45:53 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 457D7160B08 for ; Fri, 28 Oct 2016 18:45:52 +0200 (CEST) Received: (qmail 80595 invoked by uid 500); 28 Oct 2016 16:45:51 -0000 Mailing-List: contact commits-help@airavata.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@airavata.apache.org Delivered-To: mailing list commits@airavata.apache.org Received: (qmail 80371 invoked by uid 99); 28 Oct 2016 16:45:51 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 28 Oct 2016 16:45:51 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 1EE42E0FA0; Fri, 28 Oct 2016 16:45:50 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: smarru@apache.org To: commits@airavata.apache.org Date: Fri, 28 Oct 2016 16:45:55 -0000 Message-Id: In-Reply-To: <9128d98dc37b422785341693d8f2931d@git.apache.org> References: <9128d98dc37b422785341693d8f2931d@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [06/20] airavata-php-gateway git commit: AIRAVATA-2156 Allow user to set default SSH key archived-at: Fri, 28 Oct 2016 16:45:53 -0000 AIRAVATA-2156 Allow user to set default SSH key Project: http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/repo Commit: http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/commit/d75f93da Tree: http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/tree/d75f93da Diff: http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/diff/d75f93da Branch: refs/heads/develop Commit: d75f93da5967386992f3221df314ca8a059d48c9 Parents: 0b8d5f2 Author: Marcus Christie Authored: Mon Oct 24 15:20:00 2016 -0400 Committer: Marcus Christie Committed: Wed Oct 26 11:22:27 2016 -0400 ---------------------------------------------------------------------- app/controllers/AccountController.php | 31 ++++++++- app/libraries/URPUtilities.php | 80 +++++++++++++++++++---- app/routes.php | 2 + app/views/account/credential-store.blade.php | 34 ++++++++-- 4 files changed, 126 insertions(+), 21 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/d75f93da/app/controllers/AccountController.php ---------------------------------------------------------------------- diff --git a/app/controllers/AccountController.php b/app/controllers/AccountController.php index 9295f66..e93318e 100644 --- a/app/controllers/AccountController.php +++ b/app/controllers/AccountController.php @@ -470,14 +470,39 @@ class AccountController extends BaseController public function getCredentialStore() { $userResourceProfile = URPUtilities::get_or_create_user_resource_profile(); - $publicKey = AdminUtilities::get_pubkey_from_token($userResourceProfile->credentialStoreToken); + $userCredentialSummaries = URPUtilities::get_all_ssh_pub_keys_summary_for_user(); + $credentialSummaryMap = $this->create_credential_summary_map(URPUtilities::get_all_ssh_pub_keys_summary_for_user()); + $defaultCredentialSummary = $credentialSummaryMap[$userResourceProfile->credentialStoreToken]; return View::make("account/credential-store", array( - "token" => $userResourceProfile->credentialStoreToken, - "publicKey" => $publicKey + "userResourceProfile" => $userResourceProfile, + "credentialSummaries" => $userCredentialSummaries, + "defaultCredentialSummary" => $defaultCredentialSummary )); } + public function setDefaultCredential() { + + $defaultToken = Input::get("defaultToken"); + $userResourceProfile = URPUtilities::get_user_resource_profile(); + $userResourceProfile->credentialStoreToken = $defaultToken; + URPUtilities::update_user_resource_profile($userResourceProfile); + + $credentialSummaryMap = $this->create_credential_summary_map(URPUtilities::get_all_ssh_pub_keys_summary_for_user()); + $description = $credentialSummaryMap["$defaultToken"]["description"]; + + return Redirect::to("account/credential-store")->with("message", "SSH Key '$description' is now the default"); + } + + private function create_credential_summary_map($credentialSummaries) { + + $credentialSummaryMap = array(); + foreach ($credentialSummaries as $csIndex => $credentialSummary) { + $credentialSummaryMap[$credentialSummary["credentialStoreToken"]] = $credentialSummary; + } + return $credentialSummaryMap; + } + public function getComputeResources(){ $userResourceProfile = URPUtilities::get_or_create_user_resource_profile(); return View::make("account/compute-resources", array( http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/d75f93da/app/libraries/URPUtilities.php ---------------------------------------------------------------------- diff --git a/app/libraries/URPUtilities.php b/app/libraries/URPUtilities.php index 435c643..395d88f 100644 --- a/app/libraries/URPUtilities.php +++ b/app/libraries/URPUtilities.php @@ -8,28 +8,80 @@ class URPUtilities public static function get_or_create_user_resource_profile() { - $userId = Session::get('username'); - $gatewayId = Session::get('gateway_id'); try { - return Airavata::getUserResourceProfile(Session::get('authz-token'), $userId, $gatewayId); + return URPUtilities::get_user_resource_profile(); } catch (AiravataSystemException $ase) { // TODO: replace try/catch with null check once backend is updated, see AIRAVATA-2117 // Assume that exception was thrown because there is no UserResourceProfile - // Create a minimal UserResourceProfile with an SSH credential store token - $credentialStoreToken = AdminUtilities::create_ssh_token(); - $userResourceProfileData = new UserResourceProfile(array( - "userId" => $userId, - "gatewayID" => $gatewayId, - "" => $credentialStoreToken - ) - ); - Airavata::registerUserResourceProfile(Session::get('authz-token'), $userResourceProfileData); - - return Airavata::getUserResourceProfile(Session::get('authz-token'), $userId, $gatewayId); + return URPUtilities::create_user_resource_profile(); } } + public static function get_user_resource_profile() + { + $userId = Session::get('username'); + $gatewayId = Session::get('gateway_id'); + return Airavata::getUserResourceProfile(Session::get('authz-token'), $userId, $gatewayId); + } + + public static function create_user_resource_profile() + { + + $userId = Session::get('username'); + $gatewayId = Session::get('gateway_id'); + // TODO add a description to the SSH token + $credentialStoreToken = AdminUtilities::create_ssh_token(); + $userResourceProfileData = new UserResourceProfile(array( + "userId" => $userId, + "gatewayID" => $gatewayId, + "credentialStoreToken" => $credentialStoreToken + ) + ); + Airavata::registerUserResourceProfile(Session::get('authz-token'), $userResourceProfileData); + + return Airavata::getUserResourceProfile(Session::get('authz-token'), $userId, $gatewayId); + } + + public static function update_user_resource_profile($userResourceProfile) + { + + $userId = Session::get('username'); + $gatewayId = Session::get('gateway_id'); + Airavata::updateUserResourceProfile(Session::get('authz-token'), $userId, $gatewayId, $userResourceProfile); + } + + public static function get_all_ssh_pub_keys_summary_for_user() + { + + $userId = Session::get('username'); + $gatewayId = Session::get('gateway_id'); + + // TODO use the real method once it has the credentialStoreToken in it + // $credSummaries = Airavata::getAllSSHPubKeysSummaryForUserInGateway(Session::get('authz-token'), $gatewayId, $userId); + $userResourceProfile = URPUtilities::get_or_create_user_resource_profile(); + $publicKey = AdminUtilities::get_pubkey_from_token($userResourceProfile->credentialStoreToken); + $credSummaries = array( + array( + "publicKey" => $publicKey, + "description" => "Default SSH Public Key", + "credentialStoreToken" => $userResourceProfile->credentialStoreToken + ), + array( + "publicKey" => "dummy public key", + "description" => "Public Key #2", + "credentialStoreToken" => "abc123" + ), + array( + "publicKey" => "dummy public key", + "description" => "Public Key #3", + "credentialStoreToken" => "def456" + ) + ); + + return $credSummaries; + } + // Only used for testing public static function delete_user_resource_profile() { http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/d75f93da/app/routes.php ---------------------------------------------------------------------- diff --git a/app/routes.php b/app/routes.php index bb3025e..3fd11e6 100755 --- a/app/routes.php +++ b/app/routes.php @@ -49,6 +49,8 @@ Route::get("allocation-request", "AccountController@allocationRequestView"); Route::post("allocation-request", "AccountController@allocationRequestSubmit"); Route::get("account/credential-store", "AccountController@getCredentialStore"); +Route::post("account/set-default-credential", "AccountController@setDefaultCredential"); + Route::get("account/computeResources", "AccountController@getComputeResources"); // TODO: just for testing Route::get("account/deleteURP", "AccountController@deleteUserResourceProfile"); http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/d75f93da/app/views/account/credential-store.blade.php ---------------------------------------------------------------------- diff --git a/app/views/account/credential-store.blade.php b/app/views/account/credential-store.blade.php index 71f76fa..58666b0 100644 --- a/app/views/account/credential-store.blade.php +++ b/app/views/account/credential-store.blade.php @@ -6,25 +6,51 @@ @section('content')
+ @if( Session::has("message")) + + {{ Session::forget("message") }} + @endif

SSH Keys

-

Default SSH Key

+

Default SSH Key

+
+
+ + +
+ +
+

SSH Key Info

- + + @foreach ($credentialSummaries as $credentialSummary) + @endforeach
TokenDescription Public Key
- {{ $token }} + {{ $credentialSummary["description"] }} - {{ $publicKey }} + {{ $credentialSummary["publicKey"] }}