Apply changes, update tests & change vault icon temporarilly
Signed-off-by: ivgo <ivgo@spreadgroup.com>
This commit is contained in:
@@ -14,10 +14,10 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { setupRequestMockHandlers } from '@backstage/backend-test-utils';
|
||||
import { setupRequestMockHandlers } from '@backstage/test-utils';
|
||||
import { rest } from 'msw';
|
||||
import { setupServer } from 'msw/node';
|
||||
import { Secret, VaultClient } from './api';
|
||||
import { VaultSecret, VaultClient } from './api';
|
||||
import { UrlPatternDiscovery } from '@backstage/core-app-api';
|
||||
|
||||
describe('api', () => {
|
||||
@@ -27,7 +27,7 @@ describe('api', () => {
|
||||
const mockBaseUrl = 'https://api-vault.com/api/vault';
|
||||
const discoveryApi = UrlPatternDiscovery.compile(mockBaseUrl);
|
||||
|
||||
const mockSecretsResult: Secret[] = [
|
||||
const mockSecretsResult: VaultSecret[] = [
|
||||
{
|
||||
name: 'secret::one',
|
||||
editUrl: `${mockBaseUrl}/ui/vault/secrets/secrets/edit/test/success/secret::one`,
|
||||
|
||||
@@ -19,20 +19,14 @@ export const vaultApiRef = createApiRef<VaultApi>({
|
||||
id: 'plugin.vault.service',
|
||||
});
|
||||
|
||||
export type VaultSecretList = {
|
||||
data: {
|
||||
keys: string[];
|
||||
};
|
||||
};
|
||||
|
||||
export type Secret = {
|
||||
export type VaultSecret = {
|
||||
name: string;
|
||||
showUrl: string;
|
||||
editUrl: string;
|
||||
};
|
||||
|
||||
export interface VaultApi {
|
||||
listSecrets(secretPath: string): Promise<Secret[]>;
|
||||
listSecrets(secretPath: string): Promise<VaultSecret[]>;
|
||||
}
|
||||
|
||||
export class VaultClient implements VaultApi {
|
||||
@@ -61,8 +55,8 @@ export class VaultClient implements VaultApi {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
async listSecrets(secretPath: string): Promise<Secret[]> {
|
||||
const result = await this.callApi<Secret[]>('v1/secrets', {
|
||||
async listSecrets(secretPath: string): Promise<VaultSecret[]> {
|
||||
const result = await this.callApi<VaultSecret[]>('v1/secrets', {
|
||||
path: secretPath,
|
||||
});
|
||||
if (!result) {
|
||||
|
||||
@@ -24,7 +24,7 @@ import { ComponentEntity } from '@backstage/catalog-model';
|
||||
import { renderInTestApp } from '@backstage/test-utils';
|
||||
import { EntityVaultTable } from './EntityVaultTable';
|
||||
import { ApiProvider, UrlPatternDiscovery } from '@backstage/core-app-api';
|
||||
import { Secret, vaultApiRef, VaultClient } from '../../api';
|
||||
import { VaultSecret, vaultApiRef, VaultClient } from '../../api';
|
||||
import { rest } from 'msw';
|
||||
|
||||
describe('EntityVautTable', () => {
|
||||
@@ -68,7 +68,7 @@ describe('EntityVautTable', () => {
|
||||
},
|
||||
};
|
||||
|
||||
const mockSecretsResult: Secret[] = [
|
||||
const mockSecretsResult: VaultSecret[] = [
|
||||
{
|
||||
name: 'secret::one',
|
||||
editUrl: `${mockBaseUrl}/ui/vault/secrets/secrets/edit/test/success/secret::one`,
|
||||
|
||||
@@ -22,7 +22,7 @@ import Edit from '@material-ui/icons/Edit';
|
||||
import Visibility from '@material-ui/icons/Visibility';
|
||||
import Alert from '@material-ui/lab/Alert';
|
||||
import useAsync from 'react-use/lib/useAsync';
|
||||
import { Secret, vaultApiRef } from '../../api';
|
||||
import { VaultSecret, vaultApiRef } from '../../api';
|
||||
import { VAULT_SECRET_PATH_ANNOTATION } from '../../constants';
|
||||
|
||||
export const vaultSecretPath = (entity: Entity) => {
|
||||
@@ -35,7 +35,9 @@ export const vaultSecretPath = (entity: Entity) => {
|
||||
export const EntityVaultTable = ({ entity }: { entity: Entity }) => {
|
||||
const vaultApi = useApi(vaultApiRef);
|
||||
const { secretPath } = vaultSecretPath(entity);
|
||||
const { value, loading, error } = useAsync(async (): Promise<Secret[]> => {
|
||||
const { value, loading, error } = useAsync(async (): Promise<
|
||||
VaultSecret[]
|
||||
> => {
|
||||
return vaultApi.listSecrets(secretPath);
|
||||
}, []);
|
||||
|
||||
|
||||
@@ -23,6 +23,10 @@ import {
|
||||
|
||||
import { VaultClient, vaultApiRef } from './api';
|
||||
|
||||
/**
|
||||
* The vault plugin.
|
||||
* @public
|
||||
*/
|
||||
export const vaultPlugin = createPlugin({
|
||||
id: 'vault',
|
||||
apis: [
|
||||
@@ -37,6 +41,10 @@ export const vaultPlugin = createPlugin({
|
||||
],
|
||||
});
|
||||
|
||||
/**
|
||||
* Card used to show the list of Vault secrets.
|
||||
* @public
|
||||
*/
|
||||
export const EntityVaultCard = vaultPlugin.provide(
|
||||
createComponentExtension({
|
||||
name: 'EntityVaultCard',
|
||||
|
||||
Reference in New Issue
Block a user