(feat): kubernetes add new backend endpoints to api interface

Signed-off-by: Matthew Clarke <mclarke@spotify.com>
This commit is contained in:
Matthew Clarke
2022-09-15 21:59:57 -04:00
parent 535ca54f0e
commit b87a88776d
5 changed files with 47 additions and 11 deletions
@@ -16,10 +16,13 @@
import { KubernetesApi } from './types';
import {
KubernetesRequestAuth,
KubernetesRequestBody,
ObjectsByEntityResponse,
CustomResourceMatcher,
} from '@backstage/plugin-kubernetes-common';
import { DiscoveryApi, IdentityApi } from '@backstage/core-plugin-api';
import { Entity, stringifyEntityRef } from '@backstage/catalog-model';
export class KubernetesBackendClient implements KubernetesApi {
private readonly discoveryApi: DiscoveryApi;
@@ -51,10 +54,7 @@ export class KubernetesBackendClient implements KubernetesApi {
return await response.json();
}
private async postRequired(
path: string,
requestBody: KubernetesRequestBody,
): Promise<any> {
private async postRequired(path: string, requestBody: any): Promise<any> {
const url = `${await this.discoveryApi.getBaseUrl('kubernetes')}${path}`;
const { token: idToken } = await this.identityApi.getCredentials();
const response = await fetch(url, {
@@ -78,6 +78,28 @@ export class KubernetesBackendClient implements KubernetesApi {
);
}
async getWorkloadsByEntity(
auth: KubernetesRequestAuth,
entity: Entity,
): Promise<ObjectsByEntityResponse> {
return await this.postRequired('/resources/workloads/query', {
auth,
entityRef: stringifyEntityRef(entity),
});
}
async getCustomObjectsByEntity(
auth: KubernetesRequestAuth,
customResources: CustomResourceMatcher[],
entity: Entity,
): Promise<ObjectsByEntityResponse> {
return await this.postRequired(`/resources/custom/query`, {
entityRef: stringifyEntityRef(entity),
auth,
customResources,
});
}
async getClusters(): Promise<{ name: string; authProvider: string }[]> {
const { token: idToken } = await this.identityApi.getCredentials();
const url = `${await this.discoveryApi.getBaseUrl('kubernetes')}/clusters`;
+12
View File
@@ -15,10 +15,13 @@
*/
import {
KubernetesRequestAuth,
KubernetesRequestBody,
ObjectsByEntityResponse,
CustomResourceMatcher,
} from '@backstage/plugin-kubernetes-common';
import { createApiRef } from '@backstage/core-plugin-api';
import { Entity } from '@backstage/catalog-model';
export const kubernetesApiRef = createApiRef<KubernetesApi>({
id: 'plugin.kubernetes.service',
@@ -35,4 +38,13 @@ export interface KubernetesApi {
oidcTokenProvider?: string | undefined;
}[]
>;
getWorkloadsByEntity(
auth: KubernetesRequestAuth,
entity: Entity,
): Promise<ObjectsByEntityResponse>;
getCustomObjectsByEntity(
auth: KubernetesRequestAuth,
customResources: CustomResourceMatcher[],
entity: Entity,
): Promise<ObjectsByEntityResponse>;
}