diff --git a/.changeset/rude-llamas-lie.md b/.changeset/rude-llamas-lie.md new file mode 100644 index 0000000000..918d61da6d --- /dev/null +++ b/.changeset/rude-llamas-lie.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-vault': patch +--- + +Export missing parameters and added them to the api-report. Also adapted the API to the expected response from the backend diff --git a/.changeset/sharp-planes-turn.md b/.changeset/sharp-planes-turn.md new file mode 100644 index 0000000000..cc7045a9f7 --- /dev/null +++ b/.changeset/sharp-planes-turn.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-vault-backend': patch +--- + +Throw exceptions instead of swallow them, remove some exported types from the `api-report`, small changes in the API responses & expose the vault `baseUrl` to the frontend as well diff --git a/plugins/vault-backend/package.json b/plugins/vault-backend/package.json index 080398ea52..d0e3990aee 100644 --- a/plugins/vault-backend/package.json +++ b/plugins/vault-backend/package.json @@ -46,6 +46,7 @@ "express": "^4.17.1", "express-promise-router": "^4.1.0", "helmet": "^5.0.2", + "p-limit": "^3.1.0", "winston": "^3.7.2", "yn": "^5.0.0" }, diff --git a/plugins/vault-backend/src/service/vaultApi.ts b/plugins/vault-backend/src/service/vaultApi.ts index ad399dc6ac..14607a694f 100644 --- a/plugins/vault-backend/src/service/vaultApi.ts +++ b/plugins/vault-backend/src/service/vaultApi.ts @@ -17,6 +17,7 @@ import { Config } from '@backstage/config'; import { NotFoundError } from '@backstage/errors'; import fetch from 'cross-fetch'; +import plimit from 'p-limit'; import { getVaultConfig, VaultConfig } from '../config'; /** @@ -75,6 +76,7 @@ export interface VaultApi { */ export class VaultClient implements VaultApi { private vaultConfig: VaultConfig; + private readonly limit = plimit(5); constructor({ config }: { config: Config }) { this.vaultConfig = getVaultConfig(config); @@ -115,14 +117,19 @@ export class VaultClient implements VaultApi { this.vaultConfig.kvVersion === 2 ? `v1/${this.vaultConfig.secretEngine}/metadata/${secretPath}` : `v1/${this.vaultConfig.secretEngine}/${secretPath}`; - const result = await this.callApi(listUrl, { list: true }); + const result = await this.limit(() => + this.callApi(listUrl, { list: true }), + ); const secrets: VaultSecret[] = []; + await Promise.all( result.data.keys.map(async secret => { if (secret.endsWith('/')) { secrets.push( - ...(await this.listSecrets(`${secretPath}/${secret.slice(0, -1)}`)), + ...(await this.limit(() => + this.listSecrets(`${secretPath}/${secret.slice(0, -1)}`), + )), ); } else { secrets.push({ diff --git a/plugins/vault/api-report.md b/plugins/vault/api-report.md index 215ee274ec..f6fa8d1269 100644 --- a/plugins/vault/api-report.md +++ b/plugins/vault/api-report.md @@ -12,8 +12,6 @@ import { Entity } from '@backstage/catalog-model'; // @public export const EntityVaultCard: () => JSX.Element; -// Warning: (ae-missing-release-tag) "isVaultAvailable" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) -// // @public export function isVaultAvailable(entity: Entity): boolean;