node_modules/snyk/dist/lib/iac/iac-parser.js
// The function return true if the yaml is a valid k8s one, or false otherwise
The function return true if the yaml is a valid k8s one, or false otherwise
The function return true if the yaml is a valid k8s one or false otherwise
function validateK8sFile(fileContent, filePath, fileName) {
    const k8sObjects = parseFileContent(fileContent, filePath);
    if (!k8sObjects) {
        return { isValidFile: false, reason: errors_1.IllegalIacFileErrorMsg(fileName) };
    }
    let numOfSupportedKeyDocs = 0;
    for (let i = 0; i < k8sObjects.length; i++) {
        const k8sObject = k8sObjects[i];
        if (!k8sObject || !k8sObject.kind) {
            continue;
        }
        numOfSupportedKeyDocs++;
        for (const key of requiredK8SObjectFields) {
            if (!k8sObject[key]) {
                debug(`Missing required field (${key})`);
                return {
                    isValidFile: false,
                    reason: errors_1.IllegalIacFileErrorMsg(fileName),
                };
            }
        }
    }
    if (numOfSupportedKeyDocs === 0) {
        return {
            isValidFile: false,
            reason: errors_1.NotSupportedIacFileErrorMsg(fileName),
        };
    }
    debug(`k8s config found (${filePath})`);
    return { isValidFile: true, reason: '' };
}
function validateK8sFile ( fileContent , filePath , fileName ) { const k8sObjects = parseFileContent ( fileContent , filePath ) ; if ( ! k8sObjects ) { return { isValidFile : false , reason : errors_1 . IllegalIacFileErrorMsg ( fileName ) } ; } let numOfSupportedKeyDocs = 0 ; for ( let i = 0 ; i < k8sObjects . length ; i ++ ) { const k8sObject = k8sObjects [ i ] ; if ( ! k8sObject || ! k8sObject . kind ) { continue ; } numOfSupportedKeyDocs ++ ; for ( const key of requiredK8SObjectFields ) { if ( ! k8sObject [ key ] ) { debug ( ` ${ key } ` ) ; return { isValidFile : false , reason : errors_1 . IllegalIacFileErrorMsg ( fileName ) , } ; } } } if ( numOfSupportedKeyDocs === 0 ) { return { isValidFile : false , reason : errors_1 . NotSupportedIacFileErrorMsg ( fileName ) , } ; } debug ( ` ${ filePath } ` ) ; return { isValidFile : true , reason : '' } ; }
The function return true if the yaml is a valid k8s one, or false otherwise
The function return true if the yaml is a valid k8s one or false otherwise