Merge pull request #634 from hashicorp/chore-update-secret-schema

chore:  update to reflect secret { raw, decoded } schema, where decod…
This commit is contained in:
Susmitha Girumala authored and GitHub committed 2021-06-30 18:13:32 -04:00
commit 3a96aadb99
2 files changed
+41 -25

No files matched your search

+16 -8
View File
@@ -3,7 +3,6 @@ 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';
/**
*
@@ -44,20 +43,29 @@ class SessionCredential {
// =attributes
rawCredential;
library;
#rawSecretValue;
#payloadSecret;
/**
* The incoming payload may contain a JSON object under the `decoded` key only
* if it can be JSON-decoded. Some credential stores may not provide JSON,
* however, in which case we may have only the raw base64-encoded secret
* string. In the former case, we convert the key/value pairs of the JSON to
* an array of `SecretItem` instances. In the latter case, we return an
* array containing a single `SecretItem` instance with key `secret` and a
* string value equal to the base64-decoded raw 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])
if (this.#payloadSecret?.decoded) {
const secretJSON = this.#payloadSecret.decoded;
return Object.keys(secretJSON).map(
(key) => new SessionCredential.SecretItem(key, secretJSON[key])
);
} else {
return [new SessionCredential.SecretItem('secret', this.#rawSecretValue)];
// decode from base64
const decodedString = atob(this.#payloadSecret.raw);
return [new SessionCredential.SecretItem('secret', decodedString)];
}
}
@@ -66,7 +74,7 @@ class SessionCredential {
constructor(cred) {
const { id, name, description, type } = cred.credential_library;
this.library = new SessionCredential.Library(id, name, description, type);
this.#rawSecretValue = cred.secret;
this.#payloadSecret = cred.secret;
this.rawCredential = cred;
}
}
+25 -17
View File
@@ -53,6 +53,12 @@ export default function initializeMockIPC(server) {
type,
created_time: new Date().toISOString(),
});
const decoded = {
key1: 'value 1',
key2: true,
key3: 'test',
};
const raw = btoa(JSON.stringify(decoded));
return {
address: window.location.hostname,
port: datatype.number(),
@@ -67,7 +73,9 @@ export default function initializeMockIPC(server) {
credential_store_id: 'csvlt_Q1HFGt7Jpm',
type: 'vault',
},
secret: 'just-a-random-string',
secret: {
raw: btoa('just-a-random-string'),
},
},
{
credential_library: {
@@ -78,21 +86,10 @@ export default function initializeMockIPC(server) {
type: 'vault',
},
secret: {
key1: 'value 1',
key2: true,
key3: 'test',
raw,
decoded,
},
},
{
credential_library: {
id: 'clvlt_9KWscxpcY7',
name: 'Library Name',
description: 'Library Description',
credential_store_id: 'csvlt_Q1HFGt7Jpm',
type: 'vault',
},
secret: 'just-a-random-string',
},
{
credential_library: {
id: 'clvlt_9KWscxpcY7',
@@ -102,9 +99,20 @@ export default function initializeMockIPC(server) {
type: 'vault',
},
secret: {
key1: 'value 1',
key2: true,
key3: 'test',
raw: btoa('just-a-random-string'),
},
},
{
credential_library: {
id: 'clvlt_9KWscxpcY7',
name: 'Library Name',
description: 'Library Description',
credential_store_id: 'csvlt_Q1HFGt7Jpm',
type: 'vault',
},
secret: {
raw,
decoded,
},
},
],