@jfvilas/plugin-kwirth-common 0.12.8 → 0.13.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,16 @@
1
+ const getPodList = (pods, selectedNamespaces) => {
2
+ return Array.from(pods.filter((m) => selectedNamespaces.includes(m.namespace)));
3
+ };
4
+ const getContainerList = (pods, selectedNamespaces, selectedPodNames) => {
5
+ if (selectedNamespaces.length === 0 || selectedPodNames.length === 0) return [];
6
+ let validpods = pods.filter((pod) => selectedNamespaces.includes(pod.namespace));
7
+ validpods = validpods.filter((p2) => selectedPodNames.includes(p2.name));
8
+ let validcontainers = [];
9
+ for (var p of validpods) {
10
+ validcontainers.push(...p.containers);
11
+ }
12
+ return Array.from(new Set(validcontainers));
13
+ };
1
14
  const getVersion = async (discoveryApi, fetchApi) => {
2
15
  try {
3
16
  const baseUrl = await discoveryApi.getBaseUrl("kwirth");
@@ -12,6 +25,20 @@ const getVersion = async (discoveryApi, fetchApi) => {
12
25
  throw new Error(`getVersion error: ${err}`);
13
26
  }
14
27
  };
28
+ const getInfo = async (discoveryApi, fetchApi) => {
29
+ try {
30
+ const baseUrl = await discoveryApi.getBaseUrl("kwirth");
31
+ const targetUrl = `${baseUrl}/info`;
32
+ const result = await fetchApi.fetch(targetUrl);
33
+ const data = await result.json();
34
+ if (!result.ok) {
35
+ throw new Error(`getInfo error: not ok`);
36
+ }
37
+ return data;
38
+ } catch (err) {
39
+ throw new Error(`getInfo error: ${err}`);
40
+ }
41
+ };
15
42
  const getResources = async (discoveryApi, fetchApi, entity) => {
16
43
  try {
17
44
  const baseUrl = await discoveryApi.getBaseUrl("kwirth");
@@ -48,5 +75,5 @@ const requestAccess = async (discoveryApi, fetchApi, entity, channel, scopes) =>
48
75
  }
49
76
  };
50
77
 
51
- export { getResources, getVersion, requestAccess };
52
- //# sourceMappingURL=Tools.esm.js.map
78
+ export { getContainerList, getInfo, getPodList, getResources, getVersion, requestAccess };
79
+ //# sourceMappingURL=ArtifactsFront.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ArtifactsFront.esm.js","sources":["../src/ArtifactsFront.ts"],"sourcesContent":["import { Entity } from '@backstage/catalog-model'\r\nimport { DiscoveryApi, FetchApi } from '@backstage/core-plugin-api'\r\nimport { InstanceConfigScopeEnum } from '@jfvilas/kwirth-common'\r\nimport { ClusterValidPods } from './Resources'\r\nimport { InstanceMessageTypeEnum, SignalMessageLevelEnum } from \"@jfvilas/kwirth-common\"\r\nimport { PodData } from \"./Resources\"\r\n\r\nexport interface ILogLine {\r\n namespace: string\r\n pod: string\r\n container: string\r\n timestamp?: Date\r\n type: string\r\n text: string\r\n}\r\n\r\nexport interface IStatusLine {\r\n type: InstanceMessageTypeEnum\r\n level: SignalMessageLevelEnum\r\n text: string\r\n}\r\n\r\nexport interface IBackendInfo {\r\n \"plugin-kwirth-backend\" : string\r\n \"plugin-kwirth-log\" : string\r\n \"plugin-kwirth-metrics\" : string\r\n \"kwirth\" : string\r\n}\r\n\r\nexport const getPodList = (pods:PodData[], selectedNamespaces:string[]) => {\r\n return Array.from(pods.filter(m => selectedNamespaces.includes(m.namespace)))\r\n}\r\n\r\nexport const getContainerList = (pods:PodData[], selectedNamespaces:string[], selectedPodNames:string[]) => {\r\n if (selectedNamespaces.length===0 || selectedPodNames.length===0) return []\r\n let validpods = pods.filter(pod => selectedNamespaces.includes(pod.namespace))\r\n validpods = validpods.filter(p => selectedPodNames.includes(p.name))\r\n let validcontainers:string[] = []\r\n for (var p of validpods) {\r\n validcontainers.push ( ...p.containers )\r\n }\r\n return Array.from(new Set(validcontainers))\r\n}\r\n\r\nexport const getVersion = async (discoveryApi:DiscoveryApi, fetchApi:FetchApi) : Promise<string> => {\r\n try {\r\n const baseUrl = await discoveryApi.getBaseUrl('kwirth')\r\n const targetUrl = `${baseUrl}/version`\r\n\r\n const result = await fetchApi.fetch(targetUrl)\r\n const data = await result.json()\r\n\r\n if (!result.ok) {\r\n throw new Error(`getVersion error: not ok`)\r\n }\r\n return data.version\r\n }\r\n catch (err) {\r\n throw new Error(`getVersion error: ${err}`)\r\n }\r\n}\r\n\r\nexport const getInfo = async (discoveryApi:DiscoveryApi, fetchApi:FetchApi) : Promise<IBackendInfo> => {\r\n try {\r\n const baseUrl = await discoveryApi.getBaseUrl('kwirth')\r\n const targetUrl = `${baseUrl}/info`\r\n\r\n const result = await fetchApi.fetch(targetUrl)\r\n const data = await result.json()\r\n\r\n if (!result.ok) {\r\n throw new Error(`getInfo error: not ok`)\r\n }\r\n return data\r\n }\r\n catch (err) {\r\n throw new Error(`getInfo error: ${err}`)\r\n }\r\n}\r\n\r\nexport const getResources = async (discoveryApi:DiscoveryApi, fetchApi: FetchApi, entity:Entity): Promise<ClusterValidPods> => {\r\n try {\r\n const baseUrl = await discoveryApi.getBaseUrl('kwirth')\r\n const targetUrl = `${baseUrl}/start`\r\n\r\n var payload=JSON.stringify(entity)\r\n const result = await fetchApi.fetch(targetUrl, {method:'POST', body:payload, headers:{'Content-Type':'application/json'}})\r\n const data = await result.json() as ClusterValidPods\r\n\r\n if (!result.ok) {\r\n throw new Error(`getResources error: not ok`)\r\n }\r\n return data\r\n }\r\n catch (err) {\r\n throw new Error(`getResources error: ${err}`)\r\n }\r\n}\r\n\r\nexport const requestAccess = async (discoveryApi:DiscoveryApi, fetchApi:FetchApi, entity:Entity, channel:string, scopes:InstanceConfigScopeEnum[]): Promise<ClusterValidPods[]> => {\r\n try {\r\n const baseUrl = await discoveryApi.getBaseUrl('kwirth')\r\n var targetUrl:URL = new URL (`${baseUrl}/access`)\r\n targetUrl.searchParams.append('scopes',scopes.join(','))\r\n targetUrl.searchParams.append('channel',channel)\r\n\r\n var payload=JSON.stringify(entity)\r\n const result = await fetchApi.fetch(targetUrl, {method:'POST', body:payload, headers:{'Content-Type':'application/json'}})\r\n const data = await result.json() as ClusterValidPods[]\r\n\r\n // we reconstruct the 'Map' from string of arrays\r\n for (var c of data) {\r\n c.accessKeys = new Map(JSON.parse(((c as any).accessKeys)))\r\n }\r\n if (!result.ok) {\r\n throw new Error(`requestAccess error: not ok`)\r\n }\r\n return data\r\n }\r\n catch (err) {\r\n throw new Error(`requestAccess error: ${err}`)\r\n }\r\n}\r\n"],"names":["p"],"mappings":"AA6BO,MAAM,UAAA,GAAa,CAAC,IAAA,EAAgB,kBAAA,KAAgC;AACvE,EAAA,OAAO,KAAA,CAAM,IAAA,CAAK,IAAA,CAAK,MAAA,CAAO,CAAA,CAAA,KAAK,mBAAmB,QAAA,CAAS,CAAA,CAAE,SAAS,CAAC,CAAC,CAAA;AAChF;AAEO,MAAM,gBAAA,GAAmB,CAAC,IAAA,EAAgB,kBAAA,EAA6B,gBAAA,KAA8B;AACxG,EAAA,IAAI,mBAAmB,MAAA,KAAS,CAAA,IAAK,iBAAiB,MAAA,KAAS,CAAA,SAAU,EAAC;AAC1E,EAAA,IAAI,SAAA,GAAY,KAAK,MAAA,CAAO,CAAA,GAAA,KAAO,mBAAmB,QAAA,CAAS,GAAA,CAAI,SAAS,CAAC,CAAA;AAC7E,EAAA,SAAA,GAAY,SAAA,CAAU,OAAO,CAAAA,EAAAA,KAAK,iBAAiB,QAAA,CAASA,EAAAA,CAAE,IAAI,CAAC,CAAA;AACnE,EAAA,IAAI,kBAA2B,EAAC;AAChC,EAAA,KAAA,IAAS,KAAK,SAAA,EAAW;AACrB,IAAA,eAAA,CAAgB,IAAA,CAAO,GAAG,CAAA,CAAE,UAAW,CAAA;AAAA,EAC3C;AACA,EAAA,OAAO,KAAA,CAAM,IAAA,CAAK,IAAI,GAAA,CAAI,eAAe,CAAC,CAAA;AAC9C;AAEO,MAAM,UAAA,GAAa,OAAO,YAAA,EAA2B,QAAA,KAAwC;AAChG,EAAA,IAAI;AACA,IAAA,MAAM,OAAA,GAAU,MAAM,YAAA,CAAa,UAAA,CAAW,QAAQ,CAAA;AACtD,IAAA,MAAM,SAAA,GAAY,GAAG,OAAO,CAAA,QAAA,CAAA;AAE5B,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AA,MAAM,IAAA,GAAO,MAAM,MAAA,CAAO,IAAA,EAAK;AAG/B,IAAA,KAAA,IAAS,KAAK,IAAA,EAAM;AAChB,MAAA,CAAA,CAAE,aAAa,IAAI,GAAA,CAAI,KAAK,KAAA,CAAQ,CAAA,CAAU,UAAW,CAAC,CAAA;AAAA,IAC9D;AACA,IAAA,IAAI,CAAC,OAAO,EAAA,EAAI;AACZ,MAAA,MAAM,IAAI,MAAM,CAAA,2BAAA,CAA6B,CAAA;AAAA,IACjD;AACA,IAAA,OAAO,IAAA;AAAA,EACX,SACO,GAAA,EAAK;AACR,IAAA,MAAM,IAAI,KAAA,CAAM,CAAA,qBAAA,EAAwB,GAAG,CAAA,CAAE,CAAA;AAAA,EACjD;AACJ;;;;"}
package/dist/index.cjs.js CHANGED
@@ -1,5 +1,18 @@
1
1
  'use strict';
2
2
 
3
+ const getPodList = (pods, selectedNamespaces) => {
4
+ return Array.from(pods.filter((m) => selectedNamespaces.includes(m.namespace)));
5
+ };
6
+ const getContainerList = (pods, selectedNamespaces, selectedPodNames) => {
7
+ if (selectedNamespaces.length === 0 || selectedPodNames.length === 0) return [];
8
+ let validpods = pods.filter((pod) => selectedNamespaces.includes(pod.namespace));
9
+ validpods = validpods.filter((p2) => selectedPodNames.includes(p2.name));
10
+ let validcontainers = [];
11
+ for (var p of validpods) {
12
+ validcontainers.push(...p.containers);
13
+ }
14
+ return Array.from(new Set(validcontainers));
15
+ };
3
16
  const getVersion = async (discoveryApi, fetchApi) => {
4
17
  try {
5
18
  const baseUrl = await discoveryApi.getBaseUrl("kwirth");
@@ -14,6 +27,20 @@ const getVersion = async (discoveryApi, fetchApi) => {
14
27
  throw new Error(`getVersion error: ${err}`);
15
28
  }
16
29
  };
30
+ const getInfo = async (discoveryApi, fetchApi) => {
31
+ try {
32
+ const baseUrl = await discoveryApi.getBaseUrl("kwirth");
33
+ const targetUrl = `${baseUrl}/info`;
34
+ const result = await fetchApi.fetch(targetUrl);
35
+ const data = await result.json();
36
+ if (!result.ok) {
37
+ throw new Error(`getInfo error: not ok`);
38
+ }
39
+ return data;
40
+ } catch (err) {
41
+ throw new Error(`getInfo error: ${err}`);
42
+ }
43
+ };
17
44
  const getResources = async (discoveryApi, fetchApi, entity) => {
18
45
  try {
19
46
  const baseUrl = await discoveryApi.getBaseUrl("kwirth");
@@ -59,6 +86,9 @@ const isKwirthAvailable = (entity) => {
59
86
 
60
87
  exports.ANNOTATION_BACKSTAGE_KUBERNETES_LABELID = ANNOTATION_BACKSTAGE_KUBERNETES_LABELID;
61
88
  exports.ANNOTATION_BACKSTAGE_KUBERNETES_LABELSELECTOR = ANNOTATION_BACKSTAGE_KUBERNETES_LABELSELECTOR;
89
+ exports.getContainerList = getContainerList;
90
+ exports.getInfo = getInfo;
91
+ exports.getPodList = getPodList;
62
92
  exports.getResources = getResources;
63
93
  exports.getVersion = getVersion;
64
94
  exports.isKwirthAvailable = isKwirthAvailable;
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs.js","sources":["../src/Tools.ts","../src/index.ts"],"sourcesContent":["import { Entity } from '@backstage/catalog-model/index'\r\nimport { DiscoveryApi, FetchApi } from '@backstage/core-plugin-api'\r\nimport { InstanceConfigScopeEnum } from '@jfvilas/kwirth-common'\r\nimport { ClusterValidPods } from './Resources'\r\n\r\nexport const getVersion = async (discoveryApi:DiscoveryApi, fetchApi:FetchApi) : Promise<string> => {\r\n try {\r\n const baseUrl = await discoveryApi.getBaseUrl('kwirth')\r\n const targetUrl = `${baseUrl}/version`\r\n\r\n const result = await fetchApi.fetch(targetUrl)\r\n const data = await result.json()\r\n\r\n if (!result.ok) {\r\n throw new Error(`getVersion error: not ok`)\r\n }\r\n return data.version\r\n }\r\n catch (err) {\r\n throw new Error(`getVersion error: ${err}`)\r\n }\r\n}\r\n\r\nexport const getResources = async (discoveryApi:DiscoveryApi, fetchApi: FetchApi, entity:Entity): Promise<ClusterValidPods> => {\r\n try {\r\n const baseUrl = await discoveryApi.getBaseUrl('kwirth')\r\n const targetUrl = `${baseUrl}/start`\r\n\r\n var payload=JSON.stringify(entity)\r\n const result = await fetchApi.fetch(targetUrl, {method:'POST', body:payload, headers:{'Content-Type':'application/json'}})\r\n const data = await result.json() as ClusterValidPods\r\n\r\n if (!result.ok) {\r\n throw new Error(`getResources error: not ok`)\r\n }\r\n return data\r\n }\r\n catch (err) {\r\n throw new Error(`getResources error: ${err}`)\r\n }\r\n}\r\n\r\nexport const requestAccess = async (discoveryApi:DiscoveryApi, fetchApi:FetchApi, entity:Entity, channel:string, scopes:InstanceConfigScopeEnum[]): Promise<ClusterValidPods[]> => {\r\n try {\r\n const baseUrl = await discoveryApi.getBaseUrl('kwirth')\r\n var targetUrl:URL = new URL (`${baseUrl}/access`)\r\n targetUrl.searchParams.append('scopes',scopes.join(','))\r\n targetUrl.searchParams.append('channel',channel)\r\n\r\n var payload=JSON.stringify(entity)\r\n const result = await fetchApi.fetch(targetUrl, {method:'POST', body:payload, headers:{'Content-Type':'application/json'}})\r\n const data = await result.json() as ClusterValidPods[]\r\n\r\n // we reconstruct the 'Map' from string of arrays\r\n for (var c of data) {\r\n c.accessKeys = new Map(JSON.parse(((c as any).accessKeys)))\r\n }\r\n if (!result.ok) {\r\n throw new Error(`requestAccess error: not ok`)\r\n }\r\n return data\r\n }\r\n catch (err) {\r\n throw new Error(`requestAccess error: ${err}`)\r\n }\r\n}\r\n","/*\r\nCopyright 2024 Julio Fernandez\r\n\r\nLicensed under the Apache License, Version 2.0 (the \"License\");\r\nyou may not use this file except in compliance with the License.\r\nYou may obtain a copy of the License at\r\n\r\n http://www.apache.org/licenses/LICENSE-2.0\r\n\r\nUnless required by applicable law or agreed to in writing, software\r\ndistributed under the License is distributed on an \"AS IS\" BASIS,\r\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\nSee the License for the specific language governing permissions and\r\nlimitations under the License.\r\n*/\r\nimport { Entity } from '@backstage/catalog-model'\r\nexport * from './Resources'\r\nexport * from './InterfacesFront'\r\nexport * from './Tools'\r\n\r\n/**\r\n * Kwirth annotation.\r\n */\r\nexport const ANNOTATION_BACKSTAGE_KUBERNETES_LABELID = 'backstage.io/kubernetes-id'\r\nexport const ANNOTATION_BACKSTAGE_KUBERNETES_LABELSELECTOR = 'backstage.io/kubernetes-label-selector'\r\n\r\n/**\r\n * Function to know if an entity has Kwirth.\r\n */\r\nexport const isKwirthAvailable = (entity: Entity) => {\r\n if (!entity.metadata.annotations) return false;\r\n return Boolean (entity.metadata.annotations[ANNOTATION_BACKSTAGE_KUBERNETES_LABELID]) || Boolean (entity.metadata.annotations[ANNOTATION_BACKSTAGE_KUBERNETES_LABELSELECTOR]);\r\n}\r\n"],"names":[],"mappings":";;AAKa,MAAA,UAAA,GAAa,OAAO,YAAA,EAA2B,QAAwC,KAAA;AAChG,EAAI,IAAA;AACA,IAAA,MAAM,OAAU,GAAA,MAAM,YAAa,CAAA,UAAA,CAAW,QAAQ,CAAA;AACtD,IAAM,MAAA,SAAA,GAAY,GAAG,OAAO,CAAA,QAAA,CAAA;AAE5B,IAAA,MAAM,MAAS,GAAA,MAAM,QAAS,CAAA,KAAA,CAAM,SAAS,CAAA;AAC7C,IAAM,MAAA,IAAA,GAAO,MAAM,MAAA,CAAO,IAAK,EAAA;AAE/B,IAAI,IAAA,CAAC,OAAO,EAAI,EAAA;AACZ,MAAM,MAAA,IAAI,MAAM,CAA0B,wBAAA,CAAA,CAAA;AAAA;AAE9C,IAAA,OAAO,IAAK,CAAA,OAAA;AAAA,WAET,GAAK,EAAA;AACR,IAAA,MAAM,IAAI,KAAA,CAAM,CAAqB,kBAAA,EAAA,GAAG,CAAE,CAAA,CAAA;AAAA;AAElD;AAEO,MAAM,YAAe,GAAA,OAAO,YAA2B,EAAA,QAAA,EAAoB,MAA6C,KAAA;AAC3H,EAAI,IAAA;AACA,IAAA,MAAM,OAAU,GAAA,MAAM,YAAa,CAAA,UAAA,CAAW,QAAQ,CAAA;AACtD,IAAM,MAAA,SAAA,GAAY,GAAG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AoB,CAAA;AACzH,IAAM,MAAA,IAAA,GAAO,MAAM,MAAA,CAAO,IAAK,EAAA;AAG/B,IAAA,KAAA,IAAS,KAAK,IAAM,EAAA;AAChB,MAAA,CAAA,CAAE,aAAa,IAAI,GAAA,CAAI,KAAK,KAAQ,CAAA,CAAA,CAAU,UAAW,CAAC,CAAA;AAAA;AAE9D,IAAI,IAAA,CAAC,OAAO,EAAI,EAAA;AACZ,MAAM,MAAA,IAAI,MAAM,CAA6B,2BAAA,CAAA,CAAA;AAAA;AAEjD,IAAO,OAAA,IAAA;AAAA,WAEJ,GAAK,EAAA;AACR,IAAA,MAAM,IAAI,KAAA,CAAM,CAAwB,qBAAA,EAAA,GAAG,CAAE,CAAA,CAAA;AAAA;AAErD;;AC1CO,MAAM,uCAA0C,GAAA;AAChD,MAAM,6CAAgD,GAAA;AAKhD,MAAA,iBAAA,GAAoB,CAAC,MAAmB,KAAA;AACnD,EAAA,IAAI,CAAC,MAAA,CAAO,QAAS,CAAA,WAAA,EAAoB,OAAA,KAAA;AACzC,EAAA,OAAO,OAAS,CAAA,MAAA,CAAO,QAAS,CAAA,WAAA,CAAY,uCAAuC,CAAC,CAAK,IAAA,OAAA,CAAS,MAAO,CAAA,QAAA,CAAS,WAAY,CAAA,6CAA6C,CAAC,CAAA;AAC9K;;;;;;;;;"}
1
+ {"version":3,"file":"index.cjs.js","sources":["../src/ArtifactsFront.ts","../src/index.ts"],"sourcesContent":["import { Entity } from '@backstage/catalog-model'\r\nimport { DiscoveryApi, FetchApi } from '@backstage/core-plugin-api'\r\nimport { InstanceConfigScopeEnum } from '@jfvilas/kwirth-common'\r\nimport { ClusterValidPods } from './Resources'\r\nimport { InstanceMessageTypeEnum, SignalMessageLevelEnum } from \"@jfvilas/kwirth-common\"\r\nimport { PodData } from \"./Resources\"\r\n\r\nexport interface ILogLine {\r\n namespace: string\r\n pod: string\r\n container: string\r\n timestamp?: Date\r\n type: string\r\n text: string\r\n}\r\n\r\nexport interface IStatusLine {\r\n type: InstanceMessageTypeEnum\r\n level: SignalMessageLevelEnum\r\n text: string\r\n}\r\n\r\nexport interface IBackendInfo {\r\n \"plugin-kwirth-backend\" : string\r\n \"plugin-kwirth-log\" : string\r\n \"plugin-kwirth-metrics\" : string\r\n \"kwirth\" : string\r\n}\r\n\r\nexport const getPodList = (pods:PodData[], selectedNamespaces:string[]) => {\r\n return Array.from(pods.filter(m => selectedNamespaces.includes(m.namespace)))\r\n}\r\n\r\nexport const getContainerList = (pods:PodData[], selectedNamespaces:string[], selectedPodNames:string[]) => {\r\n if (selectedNamespaces.length===0 || selectedPodNames.length===0) return []\r\n let validpods = pods.filter(pod => selectedNamespaces.includes(pod.namespace))\r\n validpods = validpods.filter(p => selectedPodNames.includes(p.name))\r\n let validcontainers:string[] = []\r\n for (var p of validpods) {\r\n validcontainers.push ( ...p.containers )\r\n }\r\n return Array.from(new Set(validcontainers))\r\n}\r\n\r\nexport const getVersion = async (discoveryApi:DiscoveryApi, fetchApi:FetchApi) : Promise<string> => {\r\n try {\r\n const baseUrl = await discoveryApi.getBaseUrl('kwirth')\r\n const targetUrl = `${baseUrl}/version`\r\n\r\n const result = await fetchApi.fetch(targetUrl)\r\n const data = await result.json()\r\n\r\n if (!result.ok) {\r\n throw new Error(`getVersion error: not ok`)\r\n }\r\n return data.version\r\n }\r\n catch (err) {\r\n throw new Error(`getVersion error: ${err}`)\r\n }\r\n}\r\n\r\nexport const getInfo = async (discoveryApi:DiscoveryApi, fetchApi:FetchApi) : Promise<IBackendInfo> => {\r\n try {\r\n const baseUrl = await discoveryApi.getBaseUrl('kwirth')\r\n const targetUrl = `${baseUrl}/info`\r\n\r\n const result = await fetchApi.fetch(targetUrl)\r\n const data = await result.json()\r\n\r\n if (!result.ok) {\r\n throw new Error(`getInfo error: not ok`)\r\n }\r\n return data\r\n }\r\n catch (err) {\r\n throw new Error(`getInfo error: ${err}`)\r\n }\r\n}\r\n\r\nexport const getResources = async (discoveryApi:DiscoveryApi, fetchApi: FetchApi, entity:Entity): Promise<ClusterValidPods> => {\r\n try {\r\n const baseUrl = await discoveryApi.getBaseUrl('kwirth')\r\n const targetUrl = `${baseUrl}/start`\r\n\r\n var payload=JSON.stringify(entity)\r\n const result = await fetchApi.fetch(targetUrl, {method:'POST', body:payload, headers:{'Content-Type':'application/json'}})\r\n const data = await result.json() as ClusterValidPods\r\n\r\n if (!result.ok) {\r\n throw new Error(`getResources error: not ok`)\r\n }\r\n return data\r\n }\r\n catch (err) {\r\n throw new Error(`getResources error: ${err}`)\r\n }\r\n}\r\n\r\nexport const requestAccess = async (discoveryApi:DiscoveryApi, fetchApi:FetchApi, entity:Entity, channel:string, scopes:InstanceConfigScopeEnum[]): Promise<ClusterValidPods[]> => {\r\n try {\r\n const baseUrl = await discoveryApi.getBaseUrl('kwirth')\r\n var targetUrl:URL = new URL (`${baseUrl}/access`)\r\n targetUrl.searchParams.append('scopes',scopes.join(','))\r\n targetUrl.searchParams.append('channel',channel)\r\n\r\n var payload=JSON.stringify(entity)\r\n const result = await fetchApi.fetch(targetUrl, {method:'POST', body:payload, headers:{'Content-Type':'application/json'}})\r\n const data = await result.json() as ClusterValidPods[]\r\n\r\n // we reconstruct the 'Map' from string of arrays\r\n for (var c of data) {\r\n c.accessKeys = new Map(JSON.parse(((c as any).accessKeys)))\r\n }\r\n if (!result.ok) {\r\n throw new Error(`requestAccess error: not ok`)\r\n }\r\n return data\r\n }\r\n catch (err) {\r\n throw new Error(`requestAccess error: ${err}`)\r\n }\r\n}\r\n","/*\r\nCopyright 2024 Julio Fernandez\r\n\r\nLicensed under the Apache License, Version 2.0 (the \"License\");\r\nyou may not use this file except in compliance with the License.\r\nYou may obtain a copy of the License at\r\n\r\n http://www.apache.org/licenses/LICENSE-2.0\r\n\r\nUnless required by applicable law or agreed to in writing, software\r\ndistributed under the License is distributed on an \"AS IS\" BASIS,\r\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\nSee the License for the specific language governing permissions and\r\nlimitations under the License.\r\n*/\r\nimport { Entity } from '@backstage/catalog-model'\r\nexport * from './Resources'\r\nexport * from './ArtifactsFront'\r\n\r\n/**\r\n * Kwirth annotation.\r\n */\r\nexport const ANNOTATION_BACKSTAGE_KUBERNETES_LABELID = 'backstage.io/kubernetes-id'\r\nexport const ANNOTATION_BACKSTAGE_KUBERNETES_LABELSELECTOR = 'backstage.io/kubernetes-label-selector'\r\n\r\n/**\r\n * Function to know if an entity has Kwirth.\r\n */\r\nexport const isKwirthAvailable = (entity: Entity) => {\r\n if (!entity.metadata.annotations) return false;\r\n return Boolean (entity.metadata.annotations[ANNOTATION_BACKSTAGE_KUBERNETES_LABELID]) || Boolean (entity.metadata.annotations[ANNOTATION_BACKSTAGE_KUBERNETES_LABELSELECTOR]);\r\n}\r\n"],"names":["p"],"mappings":";;AA6BO,MAAM,UAAA,GAAa,CAAC,IAAA,EAAgB,kBAAA,KAAgC;AACvE,EAAA,OAAO,KAAA,CAAM,IAAA,CAAK,IAAA,CAAK,MAAA,CAAO,CAAA,CAAA,KAAK,mBAAmB,QAAA,CAAS,CAAA,CAAE,SAAS,CAAC,CAAC,CAAA;AAChF;AAEO,MAAM,gBAAA,GAAmB,CAAC,IAAA,EAAgB,kBAAA,EAA6B,gBAAA,KAA8B;AACxG,EAAA,IAAI,mBAAmB,MAAA,KAAS,CAAA,IAAK,iBAAiB,MAAA,KAAS,CAAA,SAAU,EAAC;AAC1E,EAAA,IAAI,SAAA,GAAY,KAAK,MAAA,CAAO,CAAA,GAAA,KAAO,mBAAmB,QAAA,CAAS,GAAA,CAAI,SAAS,CAAC,CAAA;AAC7E,EAAA,SAAA,GAAY,SAAA,CAAU,OAAO,CAAAA,EAAAA,KAAK,iBAAiB,QAAA,CAASA,EAAAA,CAAE,IAAI,CAAC,CAAA;AACnE,EAAA,IAAI,kBAA2B,EAAC;AAChC,EAAA,KAAA,IAAS,KAAK,SAAA,EAAW;AACrB,IAAA,eAAA,CAAgB,IAAA,CAAO,GAAG,CAAA,CAA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ConfigScopeEnum, AccessKey, InstanceMessageTypeEnum, SignalMessageLevelEnum } from '@jfvilas/kwirth-common';
3
+ import { DiscoveryApi, FetchApi } from '@backstage/core-plugin-api';
3
4
 
4
5
  /**
5
6
  * @interface PodData contains data related on oaccessing one pod for doing someting
@@ -12,6 +13,19 @@ interface PodData {
12
13
  namespace: string;
13
14
  containers: string[];
14
15
  }
16
+ /**
17
+ * @interface MetricDefinition contains data about a specific metric
18
+ * @field metric, the name of the metric
19
+ * @field help, text explaiining what this metric is used for
20
+ * @field type, type of metric (gauge, istogram...)
21
+ * @field eval, expressions to preprocess metric befor its use
22
+ */
23
+ interface MetricDefinition {
24
+ metric: string;
25
+ help: string;
26
+ type: string;
27
+ eval: string;
28
+ }
15
29
  /**
16
30
  * @interface ClusterValidPods contains data about a cluster and all the pods found in the cluster that match required access
17
31
  * @field name is the name of the cluster
@@ -21,9 +35,10 @@ interface PodData {
21
35
  */
22
36
  interface ClusterValidPods {
23
37
  name: string;
38
+ metrics?: MetricDefinition[];
24
39
  url: string;
25
40
  title?: string;
26
- data: PodData[];
41
+ pods: PodData[];
27
42
  accessKeys: Map<InstanceConfigScopeEnum, AccessKey>;
28
43
  }
29
44
 
@@ -40,15 +55,28 @@ interface IStatusLine {
40
55
  level: SignalMessageLevelEnum;
41
56
  text: string;
42
57
  }
58
+ interface IBackendInfo {
59
+ "plugin-kwirth-backend": string;
60
+ "plugin-kwirth-log": string;
61
+ "plugin-kwirth-metrics": string;
62
+ "kwirth": string;
63
+ }
64
+ declare const getPodList: (pods: PodData[], selectedNamespaces: string[]) => PodData[];
65
+ declare const getContainerList: (pods: PodData[], selectedNamespaces: string[], selectedPodNames: string[]) => string[];
66
+ declare const getVersion: (discoveryApi: DiscoveryApi, fetchApi: FetchApi) => Promise<string>;
67
+ declare const getInfo: (discoveryApi: DiscoveryApi, fetchApi: FetchApi) => Promise<string>;
68
+ declare const getResources: (discoveryApi: DiscoveryApi, fetchApi: FetchApi, entity: Entity) => Promise<ClusterValidPods>;
69
+ declare const requestAccess: (discoveryApi: DiscoveryApi, fetchApi: FetchApi, entity: Entity, channel: string, scopes: InstanceConfigScopeEnum[]) => Promise<ClusterValidPods[]>;
43
70
 
44
71
  /**
45
72
  * Kwirth annotation.
46
73
  */
47
- declare const ANNOTATION_KWIRTH_LOCATION = "backstage.io/kubernetes-id";
74
+ declare const ANNOTATION_BACKSTAGE_KUBERNETES_LABELID = "backstage.io/kubernetes-id";
75
+ declare const ANNOTATION_BACKSTAGE_KUBERNETES_LABELSELECTOR = "backstage.io/kubernetes-label-selector";
48
76
  /**
49
77
  * Function to know if an entity has Kwirth.
50
78
  */
51
79
  declare const isKwirthAvailable: (entity: Entity) => boolean;
52
80
 
53
- export { ANNOTATION_KWIRTH_LOCATION, isKwirthAvailable };
54
- export type { ClusterValidPods, ILogLine, IStatusLine, PodData };
81
+ export { ANNOTATION_BACKSTAGE_KUBERNETES_LABELID, ANNOTATION_BACKSTAGE_KUBERNETES_LABELSELECTOR, getContainerList, getInfo, getPodList, getResources, getVersion, isKwirthAvailable, requestAccess };
82
+ export type { ClusterValidPods, IBackendInfo, ILogLine, IStatusLine, MetricDefinition, PodData };
package/dist/index.esm.js CHANGED
@@ -1,4 +1,4 @@
1
- export { getResources, getVersion, requestAccess } from './Tools.esm.js';
1
+ export { getContainerList, getInfo, getPodList, getResources, getVersion, requestAccess } from './ArtifactsFront.esm.js';
2
2
 
3
3
  const ANNOTATION_BACKSTAGE_KUBERNETES_LABELID = "backstage.io/kubernetes-id";
4
4
  const ANNOTATION_BACKSTAGE_KUBERNETES_LABELSELECTOR = "backstage.io/kubernetes-label-selector";
@@ -1 +1 @@
1
- {"version":3,"file":"index.esm.js","sources":["../src/index.ts"],"sourcesContent":["/*\r\nCopyright 2024 Julio Fernandez\r\n\r\nLicensed under the Apache License, Version 2.0 (the \"License\");\r\nyou may not use this file except in compliance with the License.\r\nYou may obtain a copy of the License at\r\n\r\n http://www.apache.org/licenses/LICENSE-2.0\r\n\r\nUnless required by applicable law or agreed to in writing, software\r\ndistributed under the License is distributed on an \"AS IS\" BASIS,\r\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\nSee the License for the specific language governing permissions and\r\nlimitations under the License.\r\n*/\r\nimport { Entity } from '@backstage/catalog-model'\r\nexport * from './Resources'\r\nexport * from './InterfacesFront'\r\nexport * from './Tools'\r\n\r\n/**\r\n * Kwirth annotation.\r\n */\r\nexport const ANNOTATION_BACKSTAGE_KUBERNETES_LABELID = 'backstage.io/kubernetes-id'\r\nexport const ANNOTATION_BACKSTAGE_KUBERNETES_LABELSELECTOR = 'backstage.io/kubernetes-label-selector'\r\n\r\n/**\r\n * Function to know if an entity has Kwirth.\r\n */\r\nexport const isKwirthAvailable = (entity: Entity) => {\r\n if (!entity.metadata.annotations) return false;\r\n return Boolean (entity.metadata.annotations[ANNOTATION_BACKSTAGE_KUBERNETES_LABELID]) || Boolean (entity.metadata.annotations[ANNOTATION_BACKSTAGE_KUBERNETES_LABELSELECTOR]);\r\n}\r\n"],"names":[],"mappings":";;AAuBO,MAAM,uCAA0C,GAAA;AAChD,MAAM,6CAAgD,GAAA;AAKhD,MAAA,iBAAA,GAAoB,CAAC,MAAmB,KAAA;AACnD,EAAA,IAAI,CAAC,MAAA,CAAO,QAAS,CAAA,WAAA,EAAoB,OAAA,KAAA;AACzC,EAAA,OAAO,OAAS,CAAA,MAAA,CAAO,QAAS,CAAA,WAAA,CAAY,uCAAuC,CAAC,CAAK,IAAA,OAAA,CAAS,MAAO,CAAA,QAAA,CAAS,WAAY,CAAA,6CAA6C,CAAC,CAAA;AAC9K;;;;"}
1
+ {"version":3,"file":"index.esm.js","sources":["../src/index.ts"],"sourcesContent":["/*\r\nCopyright 2024 Julio Fernandez\r\n\r\nLicensed under the Apache License, Version 2.0 (the \"License\");\r\nyou may not use this file except in compliance with the License.\r\nYou may obtain a copy of the License at\r\n\r\n http://www.apache.org/licenses/LICENSE-2.0\r\n\r\nUnless required by applicable law or agreed to in writing, software\r\ndistributed under the License is distributed on an \"AS IS\" BASIS,\r\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\nSee the License for the specific language governing permissions and\r\nlimitations under the License.\r\n*/\r\nimport { Entity } from '@backstage/catalog-model'\r\nexport * from './Resources'\r\nexport * from './ArtifactsFront'\r\n\r\n/**\r\n * Kwirth annotation.\r\n */\r\nexport const ANNOTATION_BACKSTAGE_KUBERNETES_LABELID = 'backstage.io/kubernetes-id'\r\nexport const ANNOTATION_BACKSTAGE_KUBERNETES_LABELSELECTOR = 'backstage.io/kubernetes-label-selector'\r\n\r\n/**\r\n * Function to know if an entity has Kwirth.\r\n */\r\nexport const isKwirthAvailable = (entity: Entity) => {\r\n if (!entity.metadata.annotations) return false;\r\n return Boolean (entity.metadata.annotations[ANNOTATION_BACKSTAGE_KUBERNETES_LABELID]) || Boolean (entity.metadata.annotations[ANNOTATION_BACKSTAGE_KUBERNETES_LABELSELECTOR]);\r\n}\r\n"],"names":[],"mappings":";;AAsBO,MAAM,uCAAA,GAA0C;AAChD,MAAM,6CAAA,GAAgD;AAKtD,MAAM,iBAAA,GAAoB,CAAC,MAAA,KAAmB;AACnD,EAAA,IAAI,CAAC,MAAA,CAAO,QAAA,CAAS,WAAA,EAAa,OAAO,KAAA;AACzC,EAAA,OAAO,OAAA,CAAS,MAAA,CAAO,QAAA,CAAS,WAAA,CAAY,uCAAuC,CAAC,CAAA,IAAK,OAAA,CAAS,MAAA,CAAO,QAAA,CAAS,WAAA,CAAY,6CAA6C,CAAC,CAAA;AAC9K;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jfvilas/plugin-kwirth-common",
3
- "version": "0.12.8",
3
+ "version": "0.13.1",
4
4
  "description": "Common functionalities for the Backstage Kwirth plugins",
5
5
  "keywords": [
6
6
  "Backstage",
@@ -1 +0,0 @@
1
- {"version":3,"file":"Tools.esm.js","sources":["../src/Tools.ts"],"sourcesContent":["import { Entity } from '@backstage/catalog-model/index'\r\nimport { DiscoveryApi, FetchApi } from '@backstage/core-plugin-api'\r\nimport { InstanceConfigScopeEnum } from '@jfvilas/kwirth-common'\r\nimport { ClusterValidPods } from './Resources'\r\n\r\nexport const getVersion = async (discoveryApi:DiscoveryApi, fetchApi:FetchApi) : Promise<string> => {\r\n try {\r\n const baseUrl = await discoveryApi.getBaseUrl('kwirth')\r\n const targetUrl = `${baseUrl}/version`\r\n\r\n const result = await fetchApi.fetch(targetUrl)\r\n const data = await result.json()\r\n\r\n if (!result.ok) {\r\n throw new Error(`getVersion error: not ok`)\r\n }\r\n return data.version\r\n }\r\n catch (err) {\r\n throw new Error(`getVersion error: ${err}`)\r\n }\r\n}\r\n\r\nexport const getResources = async (discoveryApi:DiscoveryApi, fetchApi: FetchApi, entity:Entity): Promise<ClusterValidPods> => {\r\n try {\r\n const baseUrl = await discoveryApi.getBaseUrl('kwirth')\r\n const targetUrl = `${baseUrl}/start`\r\n\r\n var payload=JSON.stringify(entity)\r\n const result = await fetchApi.fetch(targetUrl, {method:'POST', body:payload, headers:{'Content-Type':'application/json'}})\r\n const data = await result.json() as ClusterValidPods\r\n\r\n if (!result.ok) {\r\n throw new Error(`getResources error: not ok`)\r\n }\r\n return data\r\n }\r\n catch (err) {\r\n throw new Error(`getResources error: ${err}`)\r\n }\r\n}\r\n\r\nexport const requestAccess = async (discoveryApi:DiscoveryApi, fetchApi:FetchApi, entity:Entity, channel:string, scopes:InstanceConfigScopeEnum[]): Promise<ClusterValidPods[]> => {\r\n try {\r\n const baseUrl = await discoveryApi.getBaseUrl('kwirth')\r\n var targetUrl:URL = new URL (`${baseUrl}/access`)\r\n targetUrl.searchParams.append('scopes',scopes.join(','))\r\n targetUrl.searchParams.append('channel',channel)\r\n\r\n var payload=JSON.stringify(entity)\r\n const result = await fetchApi.fetch(targetUrl, {method:'POST', body:payload, headers:{'Content-Type':'application/json'}})\r\n const data = await result.json() as ClusterValidPods[]\r\n\r\n // we reconstruct the 'Map' from string of arrays\r\n for (var c of data) {\r\n c.accessKeys = new Map(JSON.parse(((c as any).accessKeys)))\r\n }\r\n if (!result.ok) {\r\n throw new Error(`requestAccess error: not ok`)\r\n }\r\n return data\r\n }\r\n catch (err) {\r\n throw new Error(`requestAccess error: ${err}`)\r\n }\r\n}\r\n"],"names":[],"mappings":"AAKa,MAAA,UAAA,GAAa,OAAO,YAAA,EAA2B,QAAwC,KAAA;AAChG,EAAI,IAAA;AACA,IAAA,MAAM,OAAU,GAAA,MAAM,YAAa,CAAA,UAAA,CAAW,QAAQ,CAAA;AACtD,IAAM,MAAA,SAAA,GAAY,GAAG,OAAO,CAAA,QAAA,CAAA;AAE5B,IAAA,MAAM,MAAS,GAAA,MAAM,QAAS,CAAA,KAAA,CAAM,SAAS,CAAA;AAC7C,IAAM,MAAA,IAAA,GAAO,MAAM,MAAA,CAAO,IAAK,EAAA;AAE/B,IAAI,IAAA,CAAC,OAAO,EAAI,EAAA;AACZ,MAAM,MAAA,IAAI,MAAM,CAA0B,wBAAA,CAAA,CAAA;AAAA;AAE9C,IAAA,OAAO,IAAK,CAAA,OAAA;AAAA,WAET,GAAK,EAAA;AACR,IAAA,MAAM,IAAI,KAAA,CAAM,CAAqB,kBAAA,EAAA,GAAG,CAAE,CAAA,CAAA;AAAA;AAElD;AAEO,MAAM,YAAe,GAAA,OAAO,YAA2B,EAAA,QAAA,EAAoB,MAA6C,KAAA;AAC3H,EAAI,IAAA;AACA,IAAA,MAAM,OAAU,GAAA,MAAM,YAAa,CAAA,UAAA,CAAW,QAAQ,CAAA;AACtD,IAAM,MAAA,SAAA,GAAY,GAAG,OAAO,CAAA,MAAA,CAAA;AAE5B,IAAI,IAAA,OAAA,GAAQ,IAAK,CAAA,SAAA,CAAU,MAAM,CAAA;AACjC,IAAA,MAAM,MAAS,GAAA,MAAM,QAAS,CAAA,KAAA,CAAM,WAAW,EAAC,MAAA,EAAO,MAAQ,EAAA,IAAA,EAAK,SAAS,OAAQ,EAAA,EAAC,cA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