88 lines
4.4 KiB
JavaScript
88 lines
4.4 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.getConfig = void 0;
|
|
const assert_1 = require("oak-domain/lib/utils/assert");
|
|
const Exception_1 = require("oak-domain/lib/types/Exception");
|
|
const oak_external_sdk_1 = require("oak-external-sdk");
|
|
/**
|
|
* @param systemConfig
|
|
* @param service
|
|
* @param origin
|
|
* @returns
|
|
*/
|
|
function getConfig(systemConfig, service, origin) {
|
|
const serviceConfig = systemConfig[service];
|
|
let originConfig = serviceConfig && serviceConfig[origin];
|
|
let originCloudAccounts = originConfig && systemConfig.Account && systemConfig.Account[origin];
|
|
if (!originConfig) {
|
|
throw new Exception_1.OakDataException(`调用的服务${service}源${origin}找不到相应的配置,请联系管理员`);
|
|
}
|
|
switch (origin) {
|
|
case 'ali': {
|
|
const aliAccount = originCloudAccounts.find((ele) => ele.accessKeyId === originConfig.accessKeyId);
|
|
(0, assert_1.assert)(aliAccount, `调用的服务${service}源${origin}找不到相应的平台帐号,请联系管理员`);
|
|
const aliyunInstance = oak_external_sdk_1.ALiYunSDK.getInstance(aliAccount.accessKeyId, aliAccount.accessKeySecret);
|
|
return {
|
|
instance: aliyunInstance,
|
|
config: originConfig,
|
|
};
|
|
}
|
|
case 'tencent': {
|
|
const tencentAccount = originCloudAccounts.find((ele) => ele.secretId === originConfig.secretId);
|
|
(0, assert_1.assert)(tencentAccount, `调用的服务${service}源${origin}找不到相应的平台帐号,请联系管理员`);
|
|
const tencentInstance = oak_external_sdk_1.TencentYunSDK.getInstance(tencentAccount.secretId, tencentAccount.secretKey);
|
|
return {
|
|
instance: tencentInstance,
|
|
config: originConfig,
|
|
};
|
|
}
|
|
case 'qiniu': {
|
|
const qiniuAccount = originCloudAccounts.find((ele) => ele.accessKey === originConfig.accessKey);
|
|
(0, assert_1.assert)(qiniuAccount, `调用的服务${service}源${origin}找不到相应的平台帐号,请联系管理员`);
|
|
const qiniuInstance = oak_external_sdk_1.QiniuSDK.getInstance(qiniuAccount.accessKey, qiniuAccount.secretKey);
|
|
return {
|
|
instance: qiniuInstance,
|
|
config: originConfig,
|
|
};
|
|
}
|
|
case 'ctyun': {
|
|
const ctyunAccount = originCloudAccounts.find((ele) => ele.accessKey === originConfig.accessKey);
|
|
(0, assert_1.assert)(ctyunAccount, `调用的服务${service}源${origin}找不到相应的平台帐号,请联系管理员`);
|
|
const ctyunInstance = oak_external_sdk_1.CTYunSDK.getInstance(ctyunAccount.accessKey, ctyunAccount.securityKey);
|
|
return {
|
|
instance: ctyunInstance,
|
|
config: originConfig,
|
|
};
|
|
}
|
|
case 'local': {
|
|
const localAccount = originCloudAccounts.find((ele) => ele.accessKey === originConfig.accessKey);
|
|
(0, assert_1.assert)(localAccount, `调用的服务${service}源${origin}找不到相应的平台帐号,请联系管理员`);
|
|
const localInstance = oak_external_sdk_1.LocalSDK.getInstance(localAccount.accessKey, localAccount.secretKey);
|
|
return {
|
|
instance: localInstance,
|
|
config: originConfig,
|
|
};
|
|
}
|
|
case 's3': {
|
|
const s3Account = originCloudAccounts.find((ele) => ele.accessKey === originConfig.accessKey);
|
|
(0, assert_1.assert)(s3Account, `调用的服务${service}源${origin}找不到相应的平台帐号,请联系管理员`);
|
|
const s3Instance = oak_external_sdk_1.S3SDK.getInstance(s3Account.accessKey, s3Account.secretKey);
|
|
return {
|
|
instance: s3Instance,
|
|
config: originConfig,
|
|
};
|
|
}
|
|
default: {
|
|
(0, assert_1.assert)(origin === 'amap');
|
|
const amapAccount = originCloudAccounts.find((ele) => ele.webApiKey === originConfig.webApiKey);
|
|
(0, assert_1.assert)(amapAccount, `调用的服务${service}源${origin}找不到相应的平台帐号,请联系管理员`);
|
|
const amapInstance = oak_external_sdk_1.AmapSDK.getInstance(amapAccount.webApiKey);
|
|
return {
|
|
instance: amapInstance,
|
|
config: originConfig,
|
|
};
|
|
}
|
|
}
|
|
}
|
|
exports.getConfig = getConfig;
|