/*
 * Copyright (c) 2018, 2026, Oracle and/or its affiliates.
 * Licensed under The Universal Permissive License (UPL), Version 1.0
 * as shown at https://oss.oracle.com/licenses/upl/
 */
const NetUtils=require("../../lib/NetUtils");const EXCHANGE_URL_OPTION="exchangeURL";function checkForExchangeConfiguration(auditContext){const{msgLib}=auditContext.utils;let exchangeURL=auditContext.userDefs?.[EXCHANGE_URL_OPTION]??auditContext.rulePack.getRuleCustomOption(EXCHANGE_URL_OPTION);if((!exchangeURL||exchangeURL.length===0)&&auditContext.rulePack.getExtension()){exchangeURL=auditContext.rulePack.getExtension()[EXCHANGE_URL_OPTION]}if(exchangeURL&&exchangeURL.length>0){exchangeURL=exchangeURL.endsWith("/")?exchangeURL:`${exchangeURL}/`;const netUtils=new NetUtils;const statusResp=netUtils.loadUrl(`${exchangeURL}status`);if(statusResp.statusCode===200){return exchangeURL}else{msgLib.error(`The supplied ${EXCHANGE_URL_OPTION} value '${this.exchangeURL}' for the rule ${auditContext.ruleName} does not appear to be valid, the rule will be disabled`);auditContext.rulePack.disableRule();return}}else{msgLib.error(`The ${EXCHANGE_URL_OPTION} configuration option has not been defined for rule ${auditContext.ruleName}, the rule will be disabled`);auditContext.rulePack.disableRule();return}}module.exports={checkForExchangeConfiguration};