@jfvilas/plugin-kubelog
Version:
Frontend plugin for viewing Kubernetes logs in Backstage
62 lines (60 loc) • 2.07 kB
JavaScript
class KubelogClient {
discoveryApi;
fetchApi;
constructor(options) {
this.discoveryApi = options.discoveryApi;
this.fetchApi = options.fetchApi;
}
/**
*
* @param entity
* @returns an array of clusters (with their correpsonding info) and a pod list for each, where the entity has been dicovered
*/
async getVersion() {
try {
const baseUrl = await this.discoveryApi.getBaseUrl("kubelog");
const targetUrl = `${baseUrl}/version`;
const result = await this.fetchApi.fetch(targetUrl);
const data = await result.json();
if (!result.ok) {
throw new Error(`getVersion error: not ok`);
}
return data.version;
} catch (err) {
throw new Error(`getVersion error: ${err}`);
}
}
async getResources(entity) {
try {
const baseUrl = await this.discoveryApi.getBaseUrl("kubelog");
const targetUrl = `${baseUrl}/start`;
var payload = JSON.stringify(entity);
const result = await this.fetchApi.fetch(targetUrl, { method: "POST", body: payload, headers: { "Content-Type": "application/json" } });
const data = await result.json();
if (!result.ok) {
throw new Error(`getResources error: not ok`);
}
return data;
} catch (err) {
throw new Error(`getResources error: ${err}`);
}
}
async requestAccess(entity, scopes) {
try {
const baseUrl = await this.discoveryApi.getBaseUrl("kubelog");
var targetUrl = new URL(`${baseUrl}/access`);
targetUrl.searchParams.append("scopes", scopes.join(","));
var payload = JSON.stringify(entity);
const result = await this.fetchApi.fetch(targetUrl, { method: "POST", body: payload, headers: { "Content-Type": "application/json" } });
const data = await result.json();
if (!result.ok) {
throw new Error(`requestAccess error: not ok`);
}
return data;
} catch (err) {
throw new Error(`requestAccess error: ${err}`);
}
}
}
export { KubelogClient };
//# sourceMappingURL=KubelogClient.esm.js.map