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 729b9fa25..86ffbe83e 100644 --- a/addons/api/mirage/scenarios/ipc.js +++ b/addons/api/mirage/scenarios/ipc.js @@ -68,7 +68,7 @@ export default function initializeMockIPC(server) { type: 'vault', }, purpose: 'application', - secret: btoa('just-a-random-string'), + secret: 'just-a-random-string', }, { credential_library: { @@ -79,15 +79,11 @@ export default function initializeMockIPC(server) { type: 'vault', }, purpose: 'ingress', - secret: btoa( - JSON.stringify({ - key1: 'value 1', - key2: true, - key3: { - description: 'nested values', - }, - }) - ), + secret: { + key1: 'value 1', + key2: true, + key3: 'test', + }, }, { credential_library: { @@ -98,7 +94,7 @@ export default function initializeMockIPC(server) { type: 'vault', }, purpose: 'application', - secret: btoa('just-a-random-string'), + secret: 'just-a-random-string', }, { credential_library: { @@ -109,15 +105,11 @@ export default function initializeMockIPC(server) { type: 'vault', }, purpose: 'egress', - secret: btoa( - JSON.stringify({ - key1: 'value 1', - key2: true, - key3: { - description: 'nested values', - }, - }) - ), + secret: { + key1: 'value 1', + key2: true, + key3: 'test', + }, }, ], };