fix vault brokered credentials display (#2583)

* fix: 🐛 brokered credential display in credential panel
This commit is contained in:
Dharini Jeeva authored and GitHub committed 2024-11-26 14:34:10 -08:00
1 parent b049635d28
commit 36c2aee271
6 files changed
+188 -4

No files matched your search

+21 -4
View File
@@ -8,6 +8,8 @@ import { equal } from '@ember/object/computed';
import { tracked } from '@glimmer/tracking';
import { A } from '@ember/array';
import { inject as service } from '@ember/service';
import { flattenObject } from '../utils/flatten-nested-object';
import { TYPES_CREDENTIAL_LIBRARY } from 'api/models/credential-library';
export const STATUS_SESSION_ACTIVE = 'active';
export const STATUS_SESSION_PENDING = 'pending';
@@ -23,7 +25,7 @@ export const statusTypes = [
/**
*
*/
class SessionCredential {
export class SessionCredential {
// =classes
/**
@@ -75,9 +77,7 @@ class SessionCredential {
get secrets() {
if (this.#payloadSecret?.decoded) {
const secretJSON = this.#payloadSecret.decoded;
return Object.keys(secretJSON).map(
(key) => new SessionCredential.SecretItem(key, secretJSON[key]),
);
return this.extractSecrets(secretJSON, this.source.type);
} else {
// decode from base64
const decodedString = atob(this.#payloadSecret.raw);
@@ -85,6 +85,23 @@ class SessionCredential {
}
}
/**
* Extracts secrets from the payload secret JSON object.
* We only need to flatten the object if the type is vault-generic
* or vault-ssh-certificate and we only need the data object.
* @param {object} secretJSON - The payload secret JSON object.
* @returns {SessionCredential.SecretItem[]} - The array of secret items.
*/
extractSecrets(secretJSON, type) {
const source =
TYPES_CREDENTIAL_LIBRARY.includes(type) && secretJSON?.data
? flattenObject(secretJSON?.data)
: secretJSON;
return Object.entries(source).map(
([key, value]) => new SessionCredential.SecretItem(key, value),
);
}
// =methods
constructor(cred) {