airavata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sma...@apache.org
Subject [06/20] airavata-php-gateway git commit: AIRAVATA-2156 Allow user to set default SSH key
Date Fri, 28 Oct 2016 16:45:55 GMT
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 <machrist@iu.edu>
Authored: Mon Oct 24 15:20:00 2016 -0400
Committer: Marcus Christie <machrist@iu.edu>
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')
 <div class="container">
+    @if( Session::has("message"))
+    <div class="alert alert-success alert-dismissible" role="alert">
+        <button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">&times;</span><span
+                class="sr-only">Close</span></button>
+        {{{ Session::get("message") }}}
+    </div>
+    {{ Session::forget("message") }}
+    @endif
     <h1>SSH Keys</h1>
-    <h2>Default SSH Key</h2>
+    <h3>Default SSH Key</h3>
+    <form class="form-inline" action="{{ URL::to('/') }}/account/set-default-credential"
method="post">
+        <div class="form-group">
+            <label for="defaultToken" class="sr-only">Select default SSH key</label>
+            <select class="form-control" id="defaultToken" name="defaultToken">
+                @foreach ($credentialSummaries as $credentialSummary)
+                <option
+                @if ($credentialSummary["credentialStoreToken"] == $defaultCredentialSummary["credentialStoreToken"])
+                selected
+                @endif
+                value="{{ $credentialSummary["credentialStoreToken"] }}">{{ $credentialSummary["description"]
}}</option>
+                @endforeach
+            </select>
+        </div>
+        <button type="submit" class="btn btn-default">Update default</button>
+    </form>
 
+    <h3>SSH Key Info</h3>
     <table class="table table-bordered table-condensed" style="word-wrap: break-word;
table-layout: fixed; width: 100%;">
         <thead>
             <tr>
-                <th>Token</th>
+                <th>Description</th>
                 <th>Public Key</th>
             </tr>
         </thead>
         <tbody>
+            @foreach ($credentialSummaries as $credentialSummary)
             <tr>
                 <td>
-                    {{ $token }}
+                    {{ $credentialSummary["description"] }}
                 </td>
                 <td>
-                    {{ $publicKey }}
+                    {{ $credentialSummary["publicKey"] }}
                 </td>
             </tr>
+            @endforeach
         </tbody>
     </table>
 </div>


Mime
View raw message