UNPKG

@jfvilas/plugin-kwirth-log

Version:

Frontend plugin for viewing real-time Kubernetes logs in Backstage

66 lines (64 loc) 2.23 kB
class KwirthLogClient { 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("kwirth"); 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("kwirth"); 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, channel, scopes) { try { const baseUrl = await this.discoveryApi.getBaseUrl("kwirth"); var targetUrl = new URL(`${baseUrl}/access`); targetUrl.searchParams.append("scopes", scopes.join(",")); targetUrl.searchParams.append("channel", channel); 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(); for (var c of data) { c.accessKeys = new Map(JSON.parse(c.accessKeys)); } if (!result.ok) { throw new Error(`requestAccess error: not ok`); } return data; } catch (err) { throw new Error(`requestAccess error: ${err}`); } } } export { KwirthLogClient }; //# sourceMappingURL=KwirthLogClient.esm.js.map