tencentcloud-edgeone-migration-nodejs-v2
Version:
tencentcloud cdn config copy to edgeone
92 lines (84 loc) • 2.27 kB
JavaScript
const { t } = require("../../i18n/trans");
const genLog = require("../../logGenerator");
function Authentication(domain, domainConfig, ruleTransferLog) {
const keyConfig = domainConfig.Authentication;
if (!keyConfig || keyConfig.Switch !== 'on') {
ruleTransferLog.push({
config: t('鉴权配置(Authentication)'),
result: t('未配置'),
detail: ''
});
genLog.defaultLog(`${t('鉴权配置(Authentication)')}${t('未配置')}`)
return null;
}
const type = keyConfig.TypeA ? 'TypeA' : keyConfig.TypeB ? 'TypeB' : keyConfig.TypeC ? 'TypeC' : 'TypeD';
const Parameters = [
{
'Name': 'AuthType',
'Values': [type]
},
{
'Name': 'ExpireTime',
'Values': [String(keyConfig[type].ExpireTime)]
},
]
if(type !== 'TypeB') {
Parameters.push( {
'Name': 'SignParam',
'Values': [keyConfig[type].SignParam]
})
}
if(keyConfig[type]?.BackupSecretKey) {
Parameters.push({
'Name': 'BackupSecretKey',
'Values': [keyConfig[type].BackupSecretKey]
})
}
if(keyConfig[type]?.SecretKey) {
Parameters.push({
'Name': 'SecretKey',
'Values': [keyConfig[type].SecretKey]
},)
}
const eoRule = {
'Rules': [
{
'Conditions': [{
'Conditions': [
{
'Operator': keyConfig[type].FilterType === 'whitelist' ? 'notequal' : 'equal',
'Target': 'extension',
'IgnoreCase': false,
'Values': keyConfig[type].FileExtensions
}
]
}],
'Actions': [
{
'NormalAction': {
'Action': 'Authentication',
'Parameters': Parameters
}
}
]
}
]
};
if (type === 'TypeD') {
eoRule.Rules[0].Actions[0].NormalAction.Parameters.push({
'Name': 'TimeParam',
'Values': [keyConfig[type].TimeParam]
}, {
'Name': 'TimeFormat',
'Values': [keyConfig[type].TimeFormat]
});
}
ruleTransferLog.push({
config: t('鉴权配置(Authentication)'),
result: t('成功'),
detail: ''
});
genLog.successLog(`${t('鉴权配置(Authentication)')}${t('成功')}`)
return eoRule;
}
module.exports = Authentication;