From 7ee4abdcc90b0d36d5728997cf3fd014c8acfadc Mon Sep 17 00:00:00 2001 From: "denis.fortin" Date: Fri, 17 Jun 2022 17:04:40 +0200 Subject: [PATCH] fix(vault-plugin): display full secret name relative to the secret path Only secret name was displayed in the table. It could be a problem when secret path has multiple subpath containing secrets with the same name. Displaying the relative path from secret path configured in the entity annotation allows to differentiate the secrets in this case. Signed-off-by: denis.fortin --- .changeset/moody-crabs-march.md | 6 ++++++ plugins/vault-backend/src/service/vaultApi.test.ts | 2 ++ plugins/vault-backend/src/service/vaultApi.ts | 2 ++ plugins/vault/dev/index.tsx | 2 ++ plugins/vault/src/api.test.ts | 2 ++ plugins/vault/src/api.ts | 1 + .../components/EntityVaultTable/EntityVaultTable.test.tsx | 2 ++ .../src/components/EntityVaultTable/EntityVaultTable.tsx | 2 +- 8 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 .changeset/moody-crabs-march.md diff --git a/.changeset/moody-crabs-march.md b/.changeset/moody-crabs-march.md new file mode 100644 index 0000000000..3d7bc2d290 --- /dev/null +++ b/.changeset/moody-crabs-march.md @@ -0,0 +1,6 @@ +--- +'@backstage/plugin-vault': minor +'@backstage/plugin-vault-backend': minor +--- + +Added a path notion in addition to secret name to allow to differentiate secrets in subpaths diff --git a/plugins/vault-backend/src/service/vaultApi.test.ts b/plugins/vault-backend/src/service/vaultApi.test.ts index 5a29633933..a407138e1e 100644 --- a/plugins/vault-backend/src/service/vaultApi.test.ts +++ b/plugins/vault-backend/src/service/vaultApi.test.ts @@ -46,11 +46,13 @@ describe('VaultApi', () => { const mockSecretsResult: VaultSecret[] = [ { name: 'secret::one', + path: 'test/success', editUrl: `${mockBaseUrl}/ui/vault/secrets/secrets/edit/test/success/secret::one`, showUrl: `${mockBaseUrl}/ui/vault/secrets/secrets/show/test/success/secret::one`, }, { name: 'secret::two', + path: 'test/success', editUrl: `${mockBaseUrl}/ui/vault/secrets/secrets/edit/test/success/secret::two`, showUrl: `${mockBaseUrl}/ui/vault/secrets/secrets/show/test/success/secret::two`, }, diff --git a/plugins/vault-backend/src/service/vaultApi.ts b/plugins/vault-backend/src/service/vaultApi.ts index 0623780654..5fc8c78149 100644 --- a/plugins/vault-backend/src/service/vaultApi.ts +++ b/plugins/vault-backend/src/service/vaultApi.ts @@ -34,6 +34,7 @@ export type VaultSecretList = { */ export type VaultSecret = { name: string; + path: string; showUrl: string; editUrl: string; }; @@ -131,6 +132,7 @@ export class VaultClient implements VaultApi { } else { secrets.push({ name: secret, + path: secretPath, editUrl: `${this.vaultConfig.baseUrl}/ui/vault/secrets/${this.vaultConfig.secretEngine}/edit/${secretPath}/${secret}`, showUrl: `${this.vaultConfig.baseUrl}/ui/vault/secrets/${this.vaultConfig.secretEngine}/show/${secretPath}/${secret}`, }); diff --git a/plugins/vault/dev/index.tsx b/plugins/vault/dev/index.tsx index f5056cd057..8d902e14c5 100644 --- a/plugins/vault/dev/index.tsx +++ b/plugins/vault/dev/index.tsx @@ -45,11 +45,13 @@ const mockedApi: VaultApi = { return [ { name: 'a::b', + path: '', editUrl: 'https://example.com', showUrl: 'https://example.com', }, { name: 'c::d', + path: '', editUrl: 'https://example.com', showUrl: 'https://example.com', }, diff --git a/plugins/vault/src/api.test.ts b/plugins/vault/src/api.test.ts index 70c6a553df..fb52cfbfdc 100644 --- a/plugins/vault/src/api.test.ts +++ b/plugins/vault/src/api.test.ts @@ -30,11 +30,13 @@ describe('api', () => { const mockSecretsResult: VaultSecret[] = [ { name: 'secret::one', + path: 'test/success', editUrl: `${mockBaseUrl}/ui/vault/secrets/secrets/edit/test/success/secret::one`, showUrl: `${mockBaseUrl}/ui/vault/secrets/secrets/show/test/success/secret::one`, }, { name: 'secret::two', + path: 'test/success', editUrl: `${mockBaseUrl}/ui/vault/secrets/secrets/edit/test/success/secret::two`, showUrl: `${mockBaseUrl}/ui/vault/secrets/secrets/show/test/success/secret::two`, }, diff --git a/plugins/vault/src/api.ts b/plugins/vault/src/api.ts index 74b212429f..ce51b4fcf9 100644 --- a/plugins/vault/src/api.ts +++ b/plugins/vault/src/api.ts @@ -21,6 +21,7 @@ export const vaultApiRef = createApiRef({ export type VaultSecret = { name: string; + path: string; showUrl: string; editUrl: string; }; diff --git a/plugins/vault/src/components/EntityVaultTable/EntityVaultTable.test.tsx b/plugins/vault/src/components/EntityVaultTable/EntityVaultTable.test.tsx index f2b181562a..c063166dbf 100644 --- a/plugins/vault/src/components/EntityVaultTable/EntityVaultTable.test.tsx +++ b/plugins/vault/src/components/EntityVaultTable/EntityVaultTable.test.tsx @@ -71,11 +71,13 @@ describe('EntityVaultTable', () => { const mockSecretsResult: VaultSecret[] = [ { name: 'secret::one', + path: 'test/success', editUrl: `${mockBaseUrl}/ui/vault/secrets/secrets/edit/test/success/secret::one`, showUrl: `${mockBaseUrl}/ui/vault/secrets/secrets/show/test/success/secret::one`, }, { name: 'secret::two', + path: 'test/success', editUrl: `${mockBaseUrl}/ui/vault/secrets/secrets/edit/test/success/secret::two`, showUrl: `${mockBaseUrl}/ui/vault/secrets/secrets/show/test/success/secret::two`, }, diff --git a/plugins/vault/src/components/EntityVaultTable/EntityVaultTable.tsx b/plugins/vault/src/components/EntityVaultTable/EntityVaultTable.tsx index 197c82c5b8..fddfc8ef25 100644 --- a/plugins/vault/src/components/EntityVaultTable/EntityVaultTable.tsx +++ b/plugins/vault/src/components/EntityVaultTable/EntityVaultTable.tsx @@ -49,7 +49,7 @@ export const EntityVaultTable = ({ entity }: { entity: Entity }) => { const data = (value || []).map(secret => { return { - secret: secret.name, + secret: `${secret.path.replace(secretPath + "/", "")}/${secret.name}`, view: (