Skip to content

Commit

Permalink
feat: update secret resource viewer (#270)
Browse files Browse the repository at this point in the history
This change updates the Secret Resource Viewer to display the secrets in the string data field, and the base64 decoded secrets in the data field.
  • Loading branch information
ChristopherFry committed May 28, 2023
1 parent a02d941 commit c06e5c5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,43 @@
* limitations under the License.
*/

import { KubernetesResource } from '../../../../../../types/KubernetesResource';
import {
KubernetesKeyValueObject,
KubernetesResource,
} from '../../../../../../types/KubernetesResource';
import { Secret } from '../../../../../../types/Secret';
import { Metadata } from '../StructuredMetadata';

const getSecrets = (
data: KubernetesKeyValueObject | undefined,
stringData: KubernetesKeyValueObject | undefined,
): KubernetesKeyValueObject | undefined => {
const secretData: KubernetesKeyValueObject = {};

if (data) {
const keys = Object.keys(data);
for (const key of keys) {
secretData[key] = Buffer.from(data[key], 'base64').toString();
}
}

if (stringData) {
const keys = Object.keys(stringData);
for (const key of keys) {
secretData[key] = stringData[key];
}
}

return Object.keys(secretData).length > 0 ? secretData : undefined;
};

export const getSecretStructuredMetadata = (
resource: KubernetesResource,
): Metadata => {
const secret = resource as Secret;

return {
type: `${secret.type} ${secret.immutable ? '(immutable)' : ''}`,
secrets: secret.data ?? 'none',
secrets: getSecrets(secret.data, secret.stringData) ?? 'none',
};
};
1 change: 1 addition & 0 deletions plugins/cad/src/types/Secret.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export type Secret = {
apiVersion: string;
metadata: SecretMetadata;
type: string;
stringData?: KubernetesKeyValueObject;
data: KubernetesKeyValueObject;
immutable?: boolean;
};
Expand Down

0 comments on commit c06e5c5

Please sign in to comment.