Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function isOpenShift(): Promise {
const kubectl = await k8s.extension.kubectl.v1;
if (kubectl.available) {
const sr = await kubectl.api.invokeCommand('api-versions');
if (!sr || sr.code !== 0) {
return false;
}
return sr.stdout.includes("apps.openshift.io/v1"); // Naive check to keep example simple!
}
}
async function isTekton(): Promise {
const kubectl = await k8s.extension.kubectl.v1;
if (kubectl.available) {
const sr = await kubectl.api.invokeCommand('api-versions');
if (!sr || sr.code !== 0) {
return false;
}
return sr.stdout.includes("tekton.dev/v1alpha1"); // Naive check to keep example simple!
}
}
export async function getChildrenNode(command: string, kind: string, abbreviation: string): Promise {
const kubectl = await k8s.extension.kubectl.v1;
if (kubectl.available) {
const result = await kubectl.api.invokeCommand(`${command}`);
const builds = result.stdout.split('\n')
.filter((value) => value !== '')
.map((item: string) => new Node(item.split(',')[0], item.split(',')[1], Number.parseInt(item.split(',')[2]), kind, abbreviation));
return builds;
}
return [];
}
async function PipelineResourceReturn(name: string): Promise {
let pipeR: any[] = [];
const element = context[0].resources.find(e => e.name === name);
const kubectl = await k8s.extension.kubectl.v1;
if (kubectl.available) {
const k8output = await kubectl.api.invokeCommand('get pipelineresources -o json');
try {
pipeR = JSON.parse(k8output.stdout).items;
} catch (ignore) {
}
}
let pipeResources = pipeR.map(value => ({
name: value.metadata.name,
type: value.spec.type,
})).filter(function (obj) {
return obj.type === element.type;
});
return pipeResources;