feature: decode session credentials and save onto session instances
This commit is contained in:
4 files changed
+99
-2
No files matched your search
@@ -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.
|
||||
|
||||
@@ -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'
|
||||
}
|
||||
}))
|
||||
},
|
||||
]
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -109,4 +109,4 @@
|
||||
{{/each}}
|
||||
{{/each}}
|
||||
|
||||
{{outlet}}
|
||||
{{outlet}}
|
||||
Reference in new issue
Block a user