Use p-limit to list secrets, update api-report & add changesets

Signed-off-by: ivgo <ivgo@spreadgroup.com>
This commit is contained in:
ivgo
2022-06-16 12:42:56 +02:00
parent cec1cd4578
commit 5ebf2c7023
5 changed files with 20 additions and 4 deletions
+5
View File
@@ -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
+5
View File
@@ -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
+1
View File
@@ -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"
},
@@ -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<VaultSecretList>(listUrl, { list: true });
const result = await this.limit(() =>
this.callApi<VaultSecretList>(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({
-2
View File
@@ -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;