From 33e6515749ae73664d0af402cfafaaa0c2b47f9d Mon Sep 17 00:00:00 2001 From: Randall Morey Date: Wed, 23 Jun 2021 16:36:05 -0400 Subject: [PATCH] feature: decode session credentials and save onto session instances --- addons/api/addon/models/session.js | 36 ++++++++++++ addons/api/mirage/scenarios/ipc.js | 58 +++++++++++++++++++ .../routes/scopes/scope/projects/targets.js | 5 +- .../scopes/scope/projects/targets.hbs | 2 +- 4 files changed, 99 insertions(+), 2 deletions(-) diff --git a/addons/api/addon/models/session.js b/addons/api/addon/models/session.js index 8c81b8a5a..ab2511f2f 100644 --- a/addons/api/addon/models/session.js +++ b/addons/api/addon/models/session.js @@ -2,14 +2,46 @@ import GeneratedSessionModel from '../generated/models/session'; import { computed } from '@ember/object'; import { equal } from '@ember/object/computed'; import { tracked } from '@glimmer/tracking'; +import { A } from '@ember/array'; + +class SessionCredential { + // =attributes + rawCredential; + credential_library_id; + credential_library_name; + credential_library_description; + credential_library_type; + purpose; + #secret; + + get secret() { + return atob(this.#secret); + } + + // =methods + + constructor(cred) { + this.rawCredential = cred; + this.credential_library_id = cred.credential_library.id; + this.credential_library_name = cred.credential_library.name; + this.credential_library_description = cred.credential_library.description; + this.credential_library_type = cred.credential_library.type; + this.purpose = cred.purpose; + this.#secret = cred.secret; + } +} export default class SessionModel extends GeneratedSessionModel { // =attributes + // These transient attributes are used for values that come from the CLI + // `connect` command as triggered by Desktop. These attributes represent + // transient read-only values. @tracked acknowledged; @tracked started_desktop_client; @tracked proxy_address; @tracked proxy_port; + credentials = A(); @equal('status', 'active') isActive; @equal('status', 'pending') isPending; @@ -43,6 +75,10 @@ export default class SessionModel extends GeneratedSessionModel { // =methods + addCredential(cred) { + this.credentials.pushObject(new SessionCredential(cred)); + } + /** * Cancels the session via the `cancel` method. * See serializer and adapter for more information. diff --git a/addons/api/mirage/scenarios/ipc.js b/addons/api/mirage/scenarios/ipc.js index f8fdf6fde..0920fd963 100644 --- a/addons/api/mirage/scenarios/ipc.js +++ b/addons/api/mirage/scenarios/ipc.js @@ -58,6 +58,64 @@ export default function initializeMockIPC(server) { port: datatype.number(), protocol: type, session_id: newSession.id, + credentials: [ + { + credential_library: { + id: 'clvlt_4cvscMTl0N', + name: 'Library Name', + description: 'Library Description', + credential_store_id: 'csvlt_Q1HFGt7Jpm', + type: 'vault' + }, + purpose: 'application', + secret: btoa('just-a-random-string') + }, + { + credential_library: { + id: 'clvlt_4cvscMTl0N', + name: 'Library Name', + description: 'Library Description', + credential_store_id: 'csvlt_Q1HFGt7Jpm', + type: 'vault' + }, + purpose: 'ingress', + secret: btoa(JSON.stringify({ + key1: 'value 1', + key2: true, + key3: { + description: 'nested values' + } + })) + }, + { + credential_library: { + id: 'clvlt_9KWscxpcY7', + name: 'Library Name', + description: 'Library Description', + credential_store_id: 'csvlt_Q1HFGt7Jpm', + type: 'vault' + }, + purpose: 'application', + secret: btoa('just-a-random-string') + }, + { + credential_library: { + id: 'clvlt_9KWscxpcY7', + name: 'Library Name', + description: 'Library Description', + credential_store_id: 'csvlt_Q1HFGt7Jpm', + type: 'vault' + }, + purpose: 'egress', + secret: btoa(JSON.stringify({ + key1: 'value 1', + key2: true, + key3: { + description: 'nested values' + } + })) + }, + ] }; } diff --git a/ui/desktop/app/routes/scopes/scope/projects/targets.js b/ui/desktop/app/routes/scopes/scope/projects/targets.js index 87773dc2b..682ee0c25 100644 --- a/ui/desktop/app/routes/scopes/scope/projects/targets.js +++ b/ui/desktop/app/routes/scopes/scope/projects/targets.js @@ -109,7 +109,7 @@ export default class ScopesScopeProjectsTargetsRoute extends Route { const connectionDetails = await this.ipc.invoke('connect', options); // Associate the connection details with the session - const { session_id, address, port } = connectionDetails; + const { session_id, address, port, credentials } = connectionDetails; const session = await this.store.findRecord('session', session_id); // Flag the session has been open in the desktop client @@ -119,6 +119,9 @@ export default class ScopesScopeProjectsTargetsRoute extends Route { // we don't have to manually persist the proxy details. session.proxy_address = address; session.proxy_port = port; + if (credentials) { + credentials.forEach(cred => session.addCredential(cred)); + } } catch(e) { this.confirm.confirm(e.message, { isConnectError: true }) // Retry diff --git a/ui/desktop/app/templates/scopes/scope/projects/targets.hbs b/ui/desktop/app/templates/scopes/scope/projects/targets.hbs index fb0d61f56..d9066001a 100644 --- a/ui/desktop/app/templates/scopes/scope/projects/targets.hbs +++ b/ui/desktop/app/templates/scopes/scope/projects/targets.hbs @@ -109,4 +109,4 @@ {{/each}} {{/each}} -{{outlet}} \ No newline at end of file +{{outlet}}