async function cvePost()

in default/cve5/portal.js [633:730]


async function cvePost() {
    // ASF
    var j = await mainTabGroup.getValue();
    res = await fetch('/publishcve', {
        method: 'POST',
        credentials: 'include',
        headers: {
            'Accept': 'application/json, text/plain, */*',
            'Content-Type': 'application/json',
            'X-CSRF-Token': csrfToken,
        },
        redirect: 'error',
        body: JSON.stringify({cve:j.cveMetadata.cveId})
    });
    const out = await res.json();
    cveShowError(out.body);
    return;
    // END ASF

    if (docEditor.validation_results && docEditor.validation_results.length == 0) {
        /*if (save != undefined) {
            await save();
        }*/
        try {
            //if (csCache.portalType === 'test') {
                //console.log('uploading...');
                var j = await mainTabGroup.getValue();
                var j = textUtil.reduceJSON(j);
                /*var pts = j.containers.cna.problemTypes;
                if(pts && pts.length == 1 && pts[0].descriptions && pts[0].descriptions[0].description == undefined) {
                    delete j.containers.cna.problemTypes;
                } 
                var ims = j.containers.cna.impacts;
                if(ims && ims.length == 1 && ims[0].descriptions && ims[0].descriptions[0].value == undefined) {
                    delete j.containers.cna.impacts;
                }*/
                var ret = null;
                try {
                    var latestId = await csClient.getCveId(j.cveMetadata.cveId);
                    if (latestId.state == 'RESERVED') {
                        //console.log('Creating');
                        if (j.cveMetadata.state == 'PUBLISHED') {
                            ret = await csClient.createCve(j.cveMetadata.cveId, { cnaContainer: j.containers.cna });
                        } else if (j.cveMetadata.state == 'REJECTED') {
                            ret = await csClient.createRejectedCve(j.cveMetadata.cveId, { cnaContainer: j.containers.cna });
                        }
                    } else {
                        //console.log('uploading');
                        if (j.cveMetadata.state == 'PUBLISHED') {
                            ret = await csClient.updateCve(j.cveMetadata.cveId, { cnaContainer: j.containers.cna });
                        } else if (j.cveMetadata.state == 'REJECTED') {
                            ret = await csClient.updateRejectedCve(j.cveMetadata.cveId, { cnaContainer: j.containers.cna });
                        }
                    }
                } catch (e) {
                    //console.log('Got error');
                    //console.log(e);
                    if (e.error) {
                        infoMsg.innerText = "";
                        errMsg.innerText = "Error publishing CVE";
                        if (e.details && e.details.errors) {
                            showJSONerrors(e.details.errors.map(
                                a => {
                                    return ({
                                        path: a.instancePath,
                                        message: a.message
                                    });
                                }
                            ));
                        } else {
                            //console.log(e);
                            cveShowError(e);
                        }
                        //cveShowError(e);
                    } else {
                        showAlert('Error publishing! Got error ' + e)
                    }
                }
                //console.log(ret);
                if (ret != null && ret.message) {
                    var a = document.createElement('a');
                    a.setAttribute('href', 'https://www.cve.org/cverecord?id='+j.cveMetadata.cveId);
                    a.setAttribute('target', '_blank');
                    a.innerText = ret.message;
                    infoMsg.innerText = '';
                    infoMsg.appendChild(a);
                    hideJSONerrors();
                }
            //} else {
            //    showAlert('CVE posting is not currently supported by production CVE services! Try Logging to Test Portal instance');
            //}
        } catch (e) {
            portalErrorHandler(e);
        }
    } else {
        showAlert('Please fix errors before posting');
    }
}