You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by ma...@apache.org on 2018/09/25 23:27:41 UTC

[airavata-django-portal] 02/02: AIRAVATA-2840 UI for creating, delete SSH credentials

This is an automated email from the ASF dual-hosted git repository.

machristie pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/airavata-django-portal.git

commit 416dd7c0e91c72edf5fc89019275c69867f31852
Author: Marcus Christie <ma...@iu.edu>
AuthorDate: Tue Sep 25 19:27:26 2018 -0400

    AIRAVATA-2840 UI for creating, delete SSH credentials
---
 .../src/components/commons/ClipboardCopyLink.vue   |  2 +-
 .../credentials/NewSSHCredentialModal.vue          | 32 ++++++++++++++
 .../dashboards/CredentialStoreDashboard.vue        | 50 ++++++++++++++--------
 .../django_airavata_api/js/service_config.js       |  6 +++
 django_airavata/apps/api/views.py                  | 29 +++++++------
 5 files changed, 86 insertions(+), 33 deletions(-)

diff --git a/django_airavata/apps/admin/static/django_airavata_admin/src/components/commons/ClipboardCopyLink.vue b/django_airavata/apps/admin/static/django_airavata_admin/src/components/commons/ClipboardCopyLink.vue
index 0cf6946..8f216ed 100644
--- a/django_airavata/apps/admin/static/django_airavata_admin/src/components/commons/ClipboardCopyLink.vue
+++ b/django_airavata/apps/admin/static/django_airavata_admin/src/components/commons/ClipboardCopyLink.vue
@@ -28,7 +28,7 @@ export default {
     let clipboard = new ClipboardJS(this.$refs.copyLink);
     clipboard.on("success", this.onCopySuccess);
   },
-  destroyed() {
+  beforeDestroy() {
     let clipboard = new ClipboardJS(this.$refs.copyLink);
     clipboard.destroy();
   },
diff --git a/django_airavata/apps/admin/static/django_airavata_admin/src/components/credentials/NewSSHCredentialModal.vue b/django_airavata/apps/admin/static/django_airavata_admin/src/components/credentials/NewSSHCredentialModal.vue
new file mode 100644
index 0000000..e2e7dde
--- /dev/null
+++ b/django_airavata/apps/admin/static/django_airavata_admin/src/components/credentials/NewSSHCredentialModal.vue
@@ -0,0 +1,32 @@
+<template>
+  <b-modal title="New SSH Credential" ref="modal" @ok="okClicked" ok-title="Create" :ok-disabled="!valid">
+    <b-form-input type="text" placeholder="Description" required v-model="description" />
+  </b-modal>
+</template>
+
+<script>
+import { models } from "django-airavata-api";
+
+export default {
+  name: "new-ssh-credential-modal",
+  data() {
+    return {
+      description: null
+    };
+  },
+  computed: {
+    valid() {
+      return this.description != null && this.description.trim() !== "";
+    }
+  },
+  methods: {
+    okClicked() {
+      this.$emit("new", { description: this.description });
+    },
+    show() {
+      this.$refs.modal.show();
+    }
+  }
+};
+</script>
+
diff --git a/django_airavata/apps/admin/static/django_airavata_admin/src/components/dashboards/CredentialStoreDashboard.vue b/django_airavata/apps/admin/static/django_airavata_admin/src/components/dashboards/CredentialStoreDashboard.vue
index 7dca361..30798ff 100644
--- a/django_airavata/apps/admin/static/django_airavata_admin/src/components/dashboards/CredentialStoreDashboard.vue
+++ b/django_airavata/apps/admin/static/django_airavata_admin/src/components/dashboards/CredentialStoreDashboard.vue
@@ -1,17 +1,20 @@
 <template>
-  <list-layout @add-new-item="addNewSSHCredential" :items="sshKeys" title="SSH Credentials" new-item-button-text="New SSH Credential">
-    <template slot="item-list" slot-scope="slotProps">
+  <div>
+    <list-layout @add-new-item="addNewSSHCredential" :items="sshKeys" title="SSH Credentials" new-item-button-text="New SSH Credential">
+      <template slot="item-list" slot-scope="slotProps">
 
-      <b-table striped hover :fields="fields" :items="slotProps.items">
-        <template slot="action" slot-scope="data">
-          <clipboard-copy-link :text="data.item.publicKey" class="mr-1" />
-          <delete-link v-if="data.item.userHasWriteAccess" @delete="deleteSSHCredential(data.item)">
-            Are you sure you want to delete this SSH credential?
-          </delete-link>
-        </template>
-      </b-table>
-    </template>
-  </list-layout>
+        <b-table striped hover :fields="fields" :items="slotProps.items">
+          <template slot="action" slot-scope="data">
+            <clipboard-copy-link :text="data.item.publicKey" class="mr-1" />
+            <delete-link v-if="data.item.userHasWriteAccess" @delete="deleteSSHCredential(data.item)">
+              Are you sure you want to delete this SSH credential?
+            </delete-link>
+          </template>
+        </b-table>
+      </template>
+    </list-layout>
+    <new-ssh-credential-modal ref="newSSHCredentialModal" @new="createNewSSHCredential" />
+  </div>
 </template>
 
 <script>
@@ -19,12 +22,14 @@ import { services } from "django-airavata-api";
 import { components, layouts } from "django-airavata-common-ui";
 import moment from "moment";
 import ClipboardCopyLink from "../commons/ClipboardCopyLink.vue";
+import NewSSHCredentialModal from "../credentials/NewSSHCredentialModal.vue";
 
 export default {
   components: {
     "delete-link": components.DeleteLink,
     "list-layout": layouts.ListLayout,
-    ClipboardCopyLink
+    ClipboardCopyLink,
+    "new-ssh-credential-modal": NewSSHCredentialModal
   },
   created: function() {
     this.fetchSSHKeys();
@@ -60,15 +65,22 @@ export default {
   methods: {
     fetchSSHKeys() {
       services.CredentialSummaryService.allSSHCredentials().then(sshCreds => {
-        console.log(
-          "loaded SSH Credentials",
-          JSON.stringify(sshCreds, null, 4)
-        );
         this.sshKeys = sshCreds;
       });
     },
-    addNewSSHCredentials() {},
-    deleteSSHCredential() {}
+    addNewSSHCredential() {
+      this.$refs.newSSHCredentialModal.show();
+    },
+    createNewSSHCredential(data) {
+      services.CredentialSummaryService.createSSH({ data: data }).then(cred =>
+        this.fetchSSHKeys()
+      );
+    },
+    deleteSSHCredential(cred) {
+      services.CredentialSummaryService.delete({ lookup: cred.token }).then(
+        () => this.fetchSSHKeys()
+      );
+    }
   }
 };
 </script>
diff --git a/django_airavata/apps/api/static/django_airavata_api/js/service_config.js b/django_airavata/apps/api/static/django_airavata_api/js/service_config.js
index 1a707fd..63bb0fc 100644
--- a/django_airavata/apps/api/static/django_airavata_api/js/service_config.js
+++ b/django_airavata/apps/api/static/django_airavata_api/js/service_config.js
@@ -158,12 +158,18 @@ export default {
         name: "createSSH",
         url: "/api/credential-summaries/create_ssh/",
         requestType: "post",
+        bodyParams: {
+          name: "data"
+        },
         modelClass: CredentialSummary
       },
       {
         name: "createPassword",
         url: "/api/credential-summaries/create_password/",
         requestType: "post",
+        bodyParams: {
+          name: "data"
+        },
         modelClass: CredentialSummary
       }
     ],
diff --git a/django_airavata/apps/api/views.py b/django_airavata/apps/api/views.py
index a375e6b..aec34a9 100644
--- a/django_airavata/apps/api/views.py
+++ b/django_airavata/apps/api/views.py
@@ -779,11 +779,7 @@ class SharedEntityViewSet(mixins.RetrieveModelMixin,
         return Response(merged_serializer.data)
 
 
-
-
-
-class CredentialSummaryViewSet(mixins.ListModelMixin,
-                               GenericAPIBackedViewSet):
+class CredentialSummaryViewSet(APIBackedViewSet):
     serializer_class = serializers.CredentialSummarySerializer
 
     def get_list(self):
@@ -793,6 +789,11 @@ class CredentialSummaryViewSet(mixins.ListModelMixin,
             self.authz_token, SummaryType.PASSWD)
         return ssh_creds + pwd_creds
 
+    def get_instance(self, lookup_value):
+        # FIXME: assuming SSH type, need to remove type from signature
+        return self.request.airavata_client.getCredentialSummary(
+            self.authz_token, SummaryType.SSH, lookup_value)
+
     @action(detail=False)
     def ssh(self, request):
         summaries = self.request.airavata_client.getAllCredentialSummaries(
@@ -811,9 +812,9 @@ class CredentialSummaryViewSet(mixins.ListModelMixin,
 
     @action(methods=['post'], detail=False)
     def create_ssh(self, request):
-        description = request.POST.get('description')
-        if description is None:
+        if 'description' not in request.data:
             raise ParseError("'description' is required in request")
+        description = request.data.get('description')
         token_id = self.request.airavata_client.generateAndRegisterSSHKeys(
             request.authz_token, description)
         credential_summary = self.request.airavata_client.getCredentialSummary(
@@ -823,12 +824,14 @@ class CredentialSummaryViewSet(mixins.ListModelMixin,
 
     @action(methods=['post'], detail=False)
     def create_password(self, request):
-        username = request.POST.get('username')
-        password = request.POST.get('password')
-        description = request.POST.get('description')
-        if username is None or password is None or description is None:
+        if ('username' not in request.data or
+            'password' not in request.data or
+                'description' not in request.data):
             raise ParseError("'username', 'password' and 'description' "
                              "are all required in request")
+        username = request.data.get('username')
+        password = request.data.get('password')
+        description = request.data.get('description')
         token_id = self.request.airavata_client.registerPwdCredential(
             request.authz_token, username, password, description)
         credential_summary = self.request.airavata_client.getCredentialSummary(
@@ -839,7 +842,7 @@ class CredentialSummaryViewSet(mixins.ListModelMixin,
     def perform_destroy(self, instance):
         if instance.type == SummaryType.SSH:
             self.request.airavata_client.deleteSSHPubKey(
-                self.authz_token, instance.token)
+                self.authz_token, instance.token, settings.GATEWAY_ID)
         elif instance.type == SummaryType.PASSWD:
             self.request.airavata_client.deletePWDCredential(
-                self.authz_token, instance.token)
+                self.authz_token, instance.token, settings.GATEWAY_ID)