From 7ee4abdcc90b0d36d5728997cf3fd014c8acfadc Mon Sep 17 00:00:00 2001 From: "denis.fortin" Date: Fri, 17 Jun 2022 17:04:40 +0200 Subject: [PATCH 1/5] 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: ( Date: Mon, 27 Jun 2022 14:32:09 +0200 Subject: [PATCH 2/5] Update links title Signed-off-by: denis.fortin --- .../src/components/EntityVaultTable/EntityVaultTable.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/vault/src/components/EntityVaultTable/EntityVaultTable.tsx b/plugins/vault/src/components/EntityVaultTable/EntityVaultTable.tsx index 5e369ff6d0..85035c04d9 100644 --- a/plugins/vault/src/components/EntityVaultTable/EntityVaultTable.tsx +++ b/plugins/vault/src/components/EntityVaultTable/EntityVaultTable.tsx @@ -58,7 +58,7 @@ export const EntityVaultTable = ({ entity }: { entity: Entity }) => { view: ( @@ -67,7 +67,7 @@ export const EntityVaultTable = ({ entity }: { entity: Entity }) => { edit: ( From b5170119fcc0d40f2e1089e522b9062f120e2a56 Mon Sep 17 00:00:00 2001 From: "denis.fortin" Date: Tue, 28 Jun 2022 11:04:41 +0200 Subject: [PATCH 3/5] fix(vault-plugin): code factorization Signed-off-by: denis.fortin --- .changeset/moody-crabs-march.md | 4 ++-- .../EntityVaultTable/EntityVaultTable.tsx | 13 ++++++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/.changeset/moody-crabs-march.md b/.changeset/moody-crabs-march.md index 3d7bc2d290..f3ae24629a 100644 --- a/.changeset/moody-crabs-march.md +++ b/.changeset/moody-crabs-march.md @@ -1,6 +1,6 @@ --- -'@backstage/plugin-vault': minor -'@backstage/plugin-vault-backend': minor +'@backstage/plugin-vault': patch +'@backstage/plugin-vault-backend': patch --- Added a path notion in addition to secret name to allow to differentiate secrets in subpaths diff --git a/plugins/vault/src/components/EntityVaultTable/EntityVaultTable.tsx b/plugins/vault/src/components/EntityVaultTable/EntityVaultTable.tsx index 85035c04d9..5923a4db6b 100644 --- a/plugins/vault/src/components/EntityVaultTable/EntityVaultTable.tsx +++ b/plugins/vault/src/components/EntityVaultTable/EntityVaultTable.tsx @@ -32,6 +32,13 @@ export const vaultSecretPath = (entity: Entity) => { return { secretPath }; }; +function getSecretRelativeName( + secretPath: string, + secret: VaultSecret, +): string { + return `${secret.path.replace(`${secretPath}/`, '')}/${secret.name}`; +} + export const EntityVaultTable = ({ entity }: { entity: Entity }) => { const vaultApi = useApi(vaultApiRef); const { secretPath } = vaultSecretPath(entity); @@ -54,11 +61,11 @@ export const EntityVaultTable = ({ entity }: { entity: Entity }) => { const data = (value || []).map(secret => { return { - secret: `${secret.path.replace(secretPath + "/", "")}/${secret.name}`, + secret: getSecretRelativeName(secretPath, secret), view: ( @@ -67,7 +74,7 @@ export const EntityVaultTable = ({ entity }: { entity: Entity }) => { edit: ( From d1994e7ed11de5cf2c5cc6e3b764aefeceaf997f Mon Sep 17 00:00:00 2001 From: "denis.fortin" Date: Tue, 28 Jun 2022 11:43:16 +0200 Subject: [PATCH 4/5] fix(vault-plugin): rework Signed-off-by: denis.fortin --- .changeset/moody-crabs-march.md | 2 +- .../EntityVaultTable/EntityVaultTable.tsx | 17 +++++++---------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/.changeset/moody-crabs-march.md b/.changeset/moody-crabs-march.md index f3ae24629a..b5ddf12ffa 100644 --- a/.changeset/moody-crabs-march.md +++ b/.changeset/moody-crabs-march.md @@ -3,4 +3,4 @@ '@backstage/plugin-vault-backend': patch --- -Added a path notion in addition to secret name to allow to differentiate secrets in subpaths +Added a path notion in addition to secret name to allow to differentiate secrets in sub-paths diff --git a/plugins/vault/src/components/EntityVaultTable/EntityVaultTable.tsx b/plugins/vault/src/components/EntityVaultTable/EntityVaultTable.tsx index 5923a4db6b..efc345b07f 100644 --- a/plugins/vault/src/components/EntityVaultTable/EntityVaultTable.tsx +++ b/plugins/vault/src/components/EntityVaultTable/EntityVaultTable.tsx @@ -32,13 +32,6 @@ export const vaultSecretPath = (entity: Entity) => { return { secretPath }; }; -function getSecretRelativeName( - secretPath: string, - secret: VaultSecret, -): string { - return `${secret.path.replace(`${secretPath}/`, '')}/${secret.name}`; -} - export const EntityVaultTable = ({ entity }: { entity: Entity }) => { const vaultApi = useApi(vaultApiRef); const { secretPath } = vaultSecretPath(entity); @@ -60,12 +53,16 @@ export const EntityVaultTable = ({ entity }: { entity: Entity }) => { ]; const data = (value || []).map(secret => { + const secretName = `${secret.path.replace(`${secretPath}/`, '')}/${ + secret.name + }`; + return { - secret: getSecretRelativeName(secretPath, secret), + secret: secretName, view: ( @@ -74,7 +71,7 @@ export const EntityVaultTable = ({ entity }: { entity: Entity }) => { edit: ( From 8451856b2c5da091628049d0c81fcb4cf25bd8f9 Mon Sep 17 00:00:00 2001 From: "denis.fortin" Date: Tue, 28 Jun 2022 17:45:50 +0200 Subject: [PATCH 5/5] add api-report.md files Signed-off-by: denis.fortin --- plugins/vault-backend/api-report.md | 1 + plugins/vault/api-report.md | 1 + 2 files changed, 2 insertions(+) diff --git a/plugins/vault-backend/api-report.md b/plugins/vault-backend/api-report.md index 9f738b15e9..d2e9e1b177 100644 --- a/plugins/vault-backend/api-report.md +++ b/plugins/vault-backend/api-report.md @@ -70,6 +70,7 @@ export interface VaultEnvironment { // @public export type VaultSecret = { name: string; + path: string; showUrl: string; editUrl: string; }; diff --git a/plugins/vault/api-report.md b/plugins/vault/api-report.md index f6fa8d1269..b347989800 100644 --- a/plugins/vault/api-report.md +++ b/plugins/vault/api-report.md @@ -32,6 +32,7 @@ export const vaultPlugin: BackstagePlugin<{}, {}>; // @public export type VaultSecret = { name: string; + path: string; showUrl: string; editUrl: string; };