feat: adopt vault api signature calls based on proposal
Signed-off-by: Ilya Katlinski <ilya.katlinsky@gmail.com>
This commit is contained in:
@@ -115,7 +115,7 @@ In case you need to support different secret engines for entities of the catalog
|
||||
# ...
|
||||
annotations:
|
||||
vault.io/secrets-path: path/to/secrets
|
||||
+ vault.io/secrets-engine: customSecretEngine # Optional. By default it uses 'secertEngine' value from configuration.
|
||||
+ vault.io/secrets-engine: customSecretEngine # Optional. By default it uses the 'secretEngine' value from your app-config.
|
||||
```
|
||||
|
||||
That will overwrite the default secret engine from the configuration.
|
||||
@@ -152,7 +152,7 @@ export default async function createPlugin(
|
||||
## Features
|
||||
|
||||
- List the secrets present in a certain path
|
||||
- Use different secret engines for different components
|
||||
- Use different secret engines for different entities
|
||||
- Open a link to view the secret
|
||||
- Open a link to edit the secret
|
||||
- Renew the token automatically with a defined periodicity
|
||||
|
||||
@@ -149,7 +149,9 @@ export class VaultBuilder {
|
||||
throw new InputError(`Invalid engine: ${engine}`);
|
||||
}
|
||||
|
||||
const secrets = await vaultApi.listSecrets(path, engine);
|
||||
const secrets = await vaultApi.listSecrets(path, {
|
||||
secretEngine: engine,
|
||||
});
|
||||
res.json({ items: secrets });
|
||||
});
|
||||
|
||||
|
||||
@@ -98,7 +98,9 @@ describe('VaultApi', () => {
|
||||
});
|
||||
|
||||
it('should return secrets for custom engine', async () => {
|
||||
const secrets = await api.listSecrets('test/success', 'kv');
|
||||
const secrets = await api.listSecrets('test/success', {
|
||||
secretEngine: 'kv',
|
||||
});
|
||||
expect(secrets).toEqual(mockSecretsResult('kv'));
|
||||
});
|
||||
|
||||
|
||||
@@ -63,11 +63,13 @@ export interface VaultApi {
|
||||
/**
|
||||
* Returns a list of secrets used to show in a table.
|
||||
* @param secretPath - The path where the secrets are stored in Vault
|
||||
* @param secretMount - The mount point of the secrets engine, optional, overrides default secret engine
|
||||
* @param options - Additional options to be passed to the Vault API, allows to override vault default settings in app config file
|
||||
*/
|
||||
listSecrets(
|
||||
secretPath: string,
|
||||
secretMount?: string | undefined,
|
||||
options?: {
|
||||
secretEngine?: string;
|
||||
},
|
||||
): Promise<VaultSecret[]>;
|
||||
|
||||
/**
|
||||
@@ -123,9 +125,11 @@ export class VaultClient implements VaultApi {
|
||||
|
||||
async listSecrets(
|
||||
secretPath: string,
|
||||
secretEngine?: string | undefined,
|
||||
options?: {
|
||||
secretEngine?: string;
|
||||
},
|
||||
): Promise<VaultSecret[]> {
|
||||
const mount = secretEngine || this.vaultConfig.secretEngine;
|
||||
const mount = options?.secretEngine || this.vaultConfig.secretEngine;
|
||||
|
||||
const listUrl =
|
||||
this.vaultConfig.kvVersion === 2
|
||||
@@ -142,7 +146,9 @@ export class VaultClient implements VaultApi {
|
||||
if (secret.endsWith('/')) {
|
||||
secrets.push(
|
||||
...(await this.limit(() =>
|
||||
this.listSecrets(`${secretPath}/${secret.slice(0, -1)}`, mount),
|
||||
this.listSecrets(`${secretPath}/${secret.slice(0, -1)}`, {
|
||||
secretEngine: mount,
|
||||
}),
|
||||
)),
|
||||
);
|
||||
} else {
|
||||
|
||||
@@ -67,7 +67,7 @@ metadata:
|
||||
# ...
|
||||
annotations:
|
||||
vault.io/secrets-path: path/to/secrets
|
||||
vault.io/secret-engine: customSecretEngine # Optional. By default it uses 'secertEngine' value from configuration.
|
||||
vault.io/secrets-engine: customSecretEngine # Optional. By default it uses the 'secretEngine' value from your app-config.
|
||||
```
|
||||
|
||||
The path is relative to your secrets engine folder. So if you want to get the secrets for backstage and you have the following directory structure:
|
||||
|
||||
@@ -87,9 +87,9 @@ describe('api', () => {
|
||||
});
|
||||
|
||||
it('should return secrets with custom engine', async () => {
|
||||
expect(await api.listSecrets('test/success', 'kv')).toEqual(
|
||||
mockSecretsResult.items,
|
||||
);
|
||||
expect(
|
||||
await api.listSecrets('test/success', { secretEngine: 'kv' }),
|
||||
).toEqual(mockSecretsResult.items);
|
||||
expect(fetchApiSpy).toHaveBeenCalledWith(
|
||||
`${mockBaseUrl}/v1/secrets/test%2Fsuccess?engine=kv`,
|
||||
expect.anything(),
|
||||
|
||||
@@ -46,11 +46,13 @@ export interface VaultApi {
|
||||
/**
|
||||
* Returns a list of secrets used to show in a table.
|
||||
* @param secretPath - The path where the secrets are stored in Vault
|
||||
* @param secretMount - The mount point of the secrets engine, optional, overrides default secret engine
|
||||
* @param options - Additional options to be passed to the Vault API, allows to override vault default settings in app config file
|
||||
*/
|
||||
listSecrets(
|
||||
secretPath: string,
|
||||
secretMount?: string | undefined,
|
||||
options?: {
|
||||
secretEngine?: string;
|
||||
},
|
||||
): Promise<VaultSecret[]>;
|
||||
}
|
||||
|
||||
@@ -96,11 +98,14 @@ export class VaultClient implements VaultApi {
|
||||
|
||||
async listSecrets(
|
||||
secretPath: string,
|
||||
secretMount?: string | undefined,
|
||||
options?: {
|
||||
secretEngine?: string;
|
||||
},
|
||||
): Promise<VaultSecret[]> {
|
||||
const query: { [key in string]: any } = {};
|
||||
if (secretMount) {
|
||||
query.engine = secretMount;
|
||||
const { secretEngine } = options || {};
|
||||
if (secretEngine) {
|
||||
query.engine = secretEngine;
|
||||
}
|
||||
|
||||
const result = await this.callApi<{ items: VaultSecret[] }>(
|
||||
|
||||
@@ -49,7 +49,7 @@ export const EntityVaultTable = ({ entity }: { entity: Entity }) => {
|
||||
const { value, loading, error } = useAsync(async (): Promise<
|
||||
VaultSecret[]
|
||||
> => {
|
||||
return vaultApi.listSecrets(secretPath, secretEngine);
|
||||
return vaultApi.listSecrets(secretPath, { secretEngine });
|
||||
}, []);
|
||||
|
||||
const columns: TableColumn[] = [
|
||||
|
||||
Reference in New Issue
Block a user