diff --git a/addons/api/addon/models/session.js b/addons/api/addon/models/session.js index ab2511f2f..7ec468630 100644 --- a/addons/api/addon/models/session.js +++ b/addons/api/addon/models/session.js @@ -3,31 +3,73 @@ import { computed } from '@ember/object'; import { equal } from '@ember/object/computed'; import { tracked } from '@glimmer/tracking'; import { A } from '@ember/array'; +import { typeOf } from '@ember/utils'; +/** + * + */ class SessionCredential { + // =classes + + /** + * + */ + static Library = class Library { + id; + name; + description; + type; + + constructor(id, name, description, type) { + this.id = id; + this.name = name; + this.description = description; + this.type = type; + } + }; + + /** + * + */ + static SecretItem = class SecretItem { + key; + value; + + constructor(key, value) { + this.key = key; + this.value = value; + } + }; + // =attributes rawCredential; - credential_library_id; - credential_library_name; - credential_library_description; - credential_library_type; + library; purpose; - #secret; + #rawSecretValue; - get secret() { - return atob(this.#secret); + /** + * The credential secret as an array of key/value objects. + * @type {SessionCredential.SecretItem[]} + */ + get secrets() { + if (typeOf(this.#rawSecretValue) === 'object') { + return Object.keys(this.#rawSecretValue).map( + (key) => + new SessionCredential.SecretItem(key, this.#rawSecretValue[key]) + ); + } else { + return [new SessionCredential.SecretItem('secret', this.#rawSecretValue)]; + } } // =methods constructor(cred) { + const { id, name, description, type } = cred.credential_library; + this.library = new SessionCredential.Library(id, name, description, type); + this.#rawSecretValue = cred.secret; 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; } } @@ -75,6 +117,9 @@ export default class SessionModel extends GeneratedSessionModel { // =methods + /** + * + */ addCredential(cred) { this.credentials.pushObject(new SessionCredential(cred)); } diff --git a/addons/api/mirage/scenarios/ipc.js b/addons/api/mirage/scenarios/ipc.js index 0920fd963..86ffbe83e 100644 --- a/addons/api/mirage/scenarios/ipc.js +++ b/addons/api/mirage/scenarios/ipc.js @@ -65,10 +65,10 @@ export default function initializeMockIPC(server) { name: 'Library Name', description: 'Library Description', credential_store_id: 'csvlt_Q1HFGt7Jpm', - type: 'vault' + type: 'vault', }, purpose: 'application', - secret: btoa('just-a-random-string') + secret: 'just-a-random-string', }, { credential_library: { @@ -76,16 +76,14 @@ export default function initializeMockIPC(server) { name: 'Library Name', description: 'Library Description', credential_store_id: 'csvlt_Q1HFGt7Jpm', - type: 'vault' + type: 'vault', }, purpose: 'ingress', - secret: btoa(JSON.stringify({ + secret: { key1: 'value 1', key2: true, - key3: { - description: 'nested values' - } - })) + key3: 'test', + }, }, { credential_library: { @@ -93,10 +91,10 @@ export default function initializeMockIPC(server) { name: 'Library Name', description: 'Library Description', credential_store_id: 'csvlt_Q1HFGt7Jpm', - type: 'vault' + type: 'vault', }, purpose: 'application', - secret: btoa('just-a-random-string') + secret: 'just-a-random-string', }, { credential_library: { @@ -104,18 +102,16 @@ export default function initializeMockIPC(server) { name: 'Library Name', description: 'Library Description', credential_store_id: 'csvlt_Q1HFGt7Jpm', - type: 'vault' + type: 'vault', }, purpose: 'egress', - secret: btoa(JSON.stringify({ + secret: { key1: 'value 1', key2: true, - key3: { - description: 'nested values' - } - })) + key3: 'test', + }, }, - ] + ], }; }