perf: 支持京东云dns申请证书

This commit is contained in:
xiaojunnuo
2025-04-02 23:13:55 +08:00
parent 8145808c43
commit 04d79f9117
280 changed files with 421914 additions and 51 deletions
@@ -0,0 +1,28 @@
var NC = require('../src/services/nc')
var config = require('config')
var global = config.get('global')
var expec = require('chai').expect
describe('JDCloud.CallStyle', function () {
var nc = new NC({
credentials: {
accessKeyId: global.accessKeyId,
secretAccessKey: global.secretAccessKey
}
})
it('use Promise style', function () {
return nc.describeContainers(
{
},
'cn-north-1'
)
})
it('use callback style', function (done) {
nc.describeContainers({}, 'cn-north-1', function (err, data) {
if (err) {
done(err)
} else {
done()
}
})
})
})
@@ -0,0 +1,85 @@
var JDCloud = require('../src/lib/jc')
var config = require('config')
var global = config.get('global')
var expect = require('chai').expect
describe('JDCloud.Config', function () {
describe('constructor', function () {
it('should be able to bass in a Config object as parameter', function () {
var config = new JDCloud.Config({
apiVersions: '1',
vm: {
apiVersions: '2'
}
})
var copyConfig = new JDCloud.Config(config)
expect(copyConfig).not.to.equal(config)
expect(config.apiVersions).to.equal('1')
expect(copyConfig.apiVersions).to.equal('1')
})
it('should be able to pass credential values directly', function () {
var config = new JDCloud.Config({
accessKeyId: 'akid',
secretAccessKey: 'secret'
})
expect(config.credentials.accessKeyId).to.equal('akid')
expect(config.credentials.secretAccessKey).to.equal('secret')
})
it('should use right config value', function () {
var NC = require('../src/services/nc')
var nc = new NC()
expect(nc.config.endpoint.host).to.not.be.empty
var config = new JDCloud.Config({
endpoint: {
host: 'globalHost.com'
}
})
JDCloud.config.update(config)
var ncUseGlobal = new NC()
expect(ncUseGlobal.config.endpoint.host).to.equal('globalHost.com')
config = new JDCloud.Config({
endpoint: {
host: 'globalHost.com'
},
nc: {
endpoint: {
host: 'globalNCHost.com'
}
}
})
JDCloud.config.update(config)
var ncUseGlobalNCConfig = new NC()
expect(ncUseGlobalNCConfig.config.endpoint.host).to.equal(
'globalNCHost.com'
)
var ncUseSelf = new NC({
endpoint: {
host: 'ncSelfHost.com'
}
})
expect(ncUseSelf.config.endpoint.host).to.equal('ncSelfHost.com')
})
})
describe('usage', function () {
it('should use default regionId', function () {
JDCloud.config = new JDCloud.Config()
var nc = new JDCloud.NC({
regionId: 'cn-north-1',
credentials: {
accessKeyId: global.accessKeyId,
secretAccessKey: global.secretAccessKey
},
logger: function (str, level = 'INFO') {
if (level === 'INFO') {
console.log(str)
}
}
})
return nc.describeContainers()
})
})
})
@@ -0,0 +1,3 @@
global:
accessKeyId : ak
secretAccessKey: sk
@@ -0,0 +1,122 @@
var MONITOR = require('../../src/services/monitor')
var config = require('config')
var global = config.get('global')
var expect = require('chai').expect
describe('JDCloud.MONITOR', function () {
var monitor = new MONITOR({
credentials: {
accessKeyId: global.accessKeyId,
secretAccessKey: global.secretAccessKey
},
version: {
monitor: 'v1'
},
regionId: 'cn-north-1'
})
it('describeMetrics', function () {
return monitor.describeMetrics({
serviceCode: 'vm',
})
.then(function (data) {
console.log(data)
})
})
it('describeMetricData', function () {
return monitor.describeMetricData({
serviceCode: 'vm',
resourceId: 'i-p1jskbki8',
metric: 'cpu_util',
timeInterval: '1h'
}, 'cn-north-1')
.then(function (data) {
console.log(data)
})
})
it('createAlarm', function () {
return monitor.createAlarm({
createAlarmSpec: {
serviceCode: 'vm',
resourceIds: ['i-p1jskbki8'],
metric: 'cpu_util',
period: 2,
calculation: 'max',
operation: '==',
threshold: 100.0,
times: 1
},
clientToken: 'dsf4safd6hjsfssdf567jaf'
}, 'cn-north-1')
.then(function (data) {
console.log(data)
})
})
it('updateAlarm', function () {
return monitor.updateAlarm({
alarmId: '265945',
serviceCode: 'vm',
resourceIds: ['i-p1jskbki8'],
metric: 'cpu_util',
period: 2,
calculation: 'max',
operation: '==',
threshold: 99.0,
times: 1
}, 'cn-north-1')
.then(function (data) {
console.log(data)
})
})
it('disableAlarm', function () {
return monitor.disableAlarm({
alarmId: '265945',
}, 'cn-north-1')
.then(function (data) {
console.log(data)
})
})
it('enableAlarm', function () {
return monitor.enableAlarm({
alarmId: '265945',
}, 'cn-north-1')
.then(function (data) {
console.log(data)
})
})
it('describeAlarmsByID', function () {
return monitor.describeAlarmsByID({
alarmId: '265945',
}, 'cn-north-1')
.then(function (data) {
console.log(data)
})
})
it('describeAlarms', function () {
return monitor.describeAlarms({
pageNumber: 1,
pageSize: 50
}, 'cn-north-1')
.then(function (data) {
console.log(data)
})
})
it('deleteAlarms', function () {
return monitor.deleteAlarms({
ids: '265945',
}, 'cn-north-1')
.then(function (data) {
console.log(data)
})
})
})
@@ -0,0 +1,33 @@
var NC = require('../../src/services/nativecontainer')
var config = require('config')
var global = config.get('global')
describe('JDCloud.NC', function () {
var nc = new NATIVECONTAINER({
credentials: {
accessKeyId: global.accessKeyId,
secretAccessKey: global.secretAccessKey
},
endpoint: {
host: 'nativecontainer.internal.cn-north-1.jdcloud-api.com', //指定非默认Endpoint
protocol: 'http' //设置使用HTTP而不是HTTPSvpc专用域名不支持HTTPS
},
'x-extra-header': { //指定额外header
"x-jdcloud-security-token" : "xxx", //要调用开启了MFA操作保护的接口需要传递
"x-jdcloud-content-sha256" : "xxx", //body过大,希望用此value替代对body进行哈希的过程
"MyOwn" : "xxx"
},
version: {
nativecontainer: 'v1'
}
})
// var nc = new NC();
describe('describeContainers', function () {
it('should be able to get nc list', function () {
return nc.describeContainers({
filters: [
{name: 'containerId', values: ['c-rxjwzysxu', 'c-73woiy7iz']}
],
}, 'cn-north-1')
})
})
})
@@ -0,0 +1,61 @@
var OSS = require('../../src/services/oss')
var config = require('config')
var global = config.get('global')
var expect = require('chai').expect
describe('JDCloud.OSS', function () {
var oss = new OSS({
credentials: {
accessKeyId: global.accessKeyId,
secretAccessKey: global.secretAccessKey
},
version: {
oss: 'v1'
},
basePath : '/v1', //默认要设为空""
})
describe('listBucket', function () {
it('should be able to get bucket list', function () {
return oss.listBuckets({
},'cn-east-1')
.then(function (data) {
console.log(data)
})
})
})
describe('putBucket', function () {
it('should be able to put bucket', function () {
return oss.putBucket({
bucketname : "apitest"
},'cn-east-1')
.then(function (data) {
console.log(data)
})
})
})
describe('headBucket', function () {
it('should be able to get head', function () {
return oss.headBucket({
bucketname : "apitest"
},'cn-east-1')
.then(function (data) {
console.log(data)
})
})
})
describe('deleteBucket', function () {
it('should be able to get head', function () {
return oss.deleteBucket({
bucketname : "apitest"
},'cn-east-1')
.then(function (data) {
console.log(data)
})
})
})
})
@@ -0,0 +1,70 @@
var VM = require('../../src/services/vm')
var config = require('config')
var global = config.get('global')
var expect = require('chai').expect
describe('JDCloud.VM', function () {
var vm = new VM({
credentials: {
accessKeyId: global.accessKeyId,
secretAccessKey: global.secretAccessKey
},
regionId: 'cn-north-1',
version: {
vm: 'v1'
}
})
it('describeInstances', function () {
console.log("========DescribeInstances=======");
return vm.describeInstances({
filters: [{ name: "name" , values:[ "i-6za0ovr24v",
"i-rj5ve7jegu",
"i-rj5ve7jegu1",
"i-rj5ve7jegu2",
"i-rj5ve7jegu3",
"i-rj5ve7jegu4",
"i-rj5ve7jegdu"] ,operator: "eq"}]
}, 'cn-north-1')
.then(function (data) {
console.log(data)
})
})
describe('should create and delete a instance', function () {
var instanceId = null
it('createInstances', function () {
return vm
.createInstances({
instanceSpec: {
instanceType: 'g.s1.micro',
az: 'cn-north-1a',
imageId: '9d44a0f-88c1-451a-8971-f1f769073b6c',
name: 'node-sdk-test',
elasticIp: { bandwidthMbps: 2, provider: 'BGP' },
primaryNetworkInterface: {
networkInterface: {
subnetId: 'subnet-3dm3k30gh',
az: 'cn-north-1a'
}
},
systemDisk: { diskCategory: 'local' },
description: 'sdk'
},
maxCount: 1
}, 'cn-north-1')
.then(function (data) {
// instanceIds = data.data.instanceIds
// return expec(instanceIds[0]).to.not.be.empty
})
})
it('deleteInstance', function () {
if (instanceId) {
return vm.deleteInstance({
instanceId: instanceId
})
} else {
this.skip()
}
})
})
})