Authored by 毕凯

腾讯云接口调用

... ... @@ -11,15 +11,15 @@ const rp = require('request-promise');
const ws = require('../../lib/ws');
const Capi = require('qcloudapi-sdk');
const qiniu = require('qiniu')
const cdnConfig = require('../../config/cdn_config').main;
const cdnConfig = require('../../config/cdn_config');
const capi = new Capi({
SecretId: 'AKIDKXZR8e2JNGhy9AogEdZKuJXaSAot7X7W',
SecretKey: 'Mhuw11qY5KPK5fBYxDHAsQnzzpU4Xqzx',
const qiniuCOnfig = cdnConfig.main
const capi = new Capi(Object.assign({
serviceType: 'cdn'
});
}, cdnConfig.qcloud));
const mac = new qiniu.auth.digest.Mac(cdnConfig.accessKey, cdnConfig.secretKey);
const mac = new qiniu.auth.digest.Mac(qiniuCOnfig.accessKey, qiniuCOnfig.secretKey);
const qiniuCdn = new qiniu.cdn.CdnManager(mac);
... ...
... ... @@ -21,6 +21,7 @@ const DegradeModel = require('./degrade');
const DegradeServerModel = require('./degrade_server');
const ChecklistModel = require('./checklist');
const ChecklogsModel = require('./checklogs');
const LogsModel = require('./logs');
shelljs.mkdir('-p', config.dbDir);
... ... @@ -42,6 +43,7 @@ const Degrade = new DegradeModel();
const DegradeServer = new DegradeServerModel();
const Checklist = new ChecklistModel();
const Checklogs = new ChecklogsModel();
const Logs = new LogsModel();
User.init();
PageCache.init();
... ... @@ -68,5 +70,6 @@ module.exports = {
Degrade,
DegradeServer,
Checklist,
Checklogs
Checklogs,
Logs
};
\ No newline at end of file
... ...
'use strict';
// const capi = new Capi({
// SecretId: 'AKIDKXZR8e2JNGhy9AogEdZKuJXaSAot7X7W',
// SecretKey: 'Mhuw11qY5KPK5fBYxDHAsQnzzpU4Xqzx',
// serviceType: 'logset'
// });
const moment = require('moment');
const rp = require('request-promise');
const Model = require('./model');
const qcloud = require('../../lib/qcloud');
class Logs extends Model {
constructor() {
super('logs');
}
async init(query = 'yoho') {
const result = await rp(qcloud.sign({
method: 'get',
baseUrl: 'http://ap-beijing.cls.myqcloud.com',
uri: '/searchlog',
qs: {
logset_id: '3a292186-9241-4d2c-98de-a13896ed7b25',
topic_ids: '3cb90ed6-0f92-40cb-b064-42f36d13b11a',
start_time: moment(Date.now() - 3600 * 1000).format('YYYY-MM-DD HH:mm:ss'),
end_time: moment().format('YYYY-MM-DD HH:mm:ss'),
query,
limit: '10'
},
headers: {}
}))
return result
}
}
module.exports = Logs;
\ No newline at end of file
... ...
'use strict';
const Router = require('koa-router');
const {Logs} = require('../../models');
const r = new Router;
const logs = {
async query(ctx) {
let logs = await Logs.init();
ctx.body = logs
}
};
r.get('/query', logs.query);
module.exports = r;
\ No newline at end of file
... ...
... ... @@ -28,6 +28,7 @@ const noAuth = new Router();
const base = new Router();
const file = require('./actions/file');
const riskManagement = require('./actions/risk_management');
const logs = require('./actions/logs');
const spa = require('./actions/spa');
... ... @@ -76,7 +77,7 @@ module.exports = function(app) {
// base.use('', index.routes(), index.allowedMethods());
base.use('/risk_management', riskManagement.routes(), riskManagement.allowedMethods());
base.use('/logs', logs.routes(), logs.allowedMethods());
base.use('', spa.routes(), spa.allowedMethods());
app.use(base.routes(), base.allowedMethods());
... ...
... ... @@ -13,6 +13,11 @@ const CDNCONFIG = {
feature: {
origin: 'https://feature.yoho.cn',
bucket: 'yohogirlzine'
},
qcloud: {
SecretId: 'AKIDKXZR8e2JNGhy9AogEdZKuJXaSAot7X7W',
SecretKey: 'Mhuw11qY5KPK5fBYxDHAsQnzzpU4Xqzx'
}
}
... ...
const moment = require('moment')
const crypto = require('crypto')
const qs = require('querystring')
const url = require('url')
const _ = require('lodash')
const cdn_config = require('../config/cdn_config')
const config = cdn_config.qcloud;
module.exports = {
SHA1(str) {
return crypto.createHash('sha1').update(str).digest('hex')
},
HMACSHA1(str, secret) {
return crypto.createHmac('sha1', secret).update(str).digest('hex')
},
sort(obj){
const newData = {};
Object.keys(obj).sort().forEach(key => {
newData[key] = String(obj[key]);
});
return newData
},
sign(data) {
// https://cloud.tencent.com/document/product/614/12445
data.headers = data.headers || {}
data.headers.host = url.parse(data.baseUrl).host
data.headers = this.sort(data.headers) || {}
data.qs = this.sort(data.qs) || {}
const formatedParameters = qs.stringify(data.qs)
const formatedHeaders = qs.stringify(data.headers)
const httpRequestInfo = [data.method, data.uri, formatedParameters, formatedHeaders].join('\n') + '\n'
const qSignTime = `${moment().unix()};${moment(Date.now() + 60 * 1000).unix()}`
const stringToSign = ['sha1', qSignTime, this.SHA1(httpRequestInfo)].join('\n') + '\n'
const qKeyTime = qSignTime
const signKey = this.HMACSHA1(qKeyTime, config.SecretKey)
const signature = this.HMACSHA1(stringToSign, signKey)
const authorization = `q-sign-algorithm=sha1&q-ak=${config.SecretId}&q-sign-time=${qSignTime}&q-key-time=${qKeyTime}&q-header-list=${Object.keys(data.headers).join(';')}&q-url-param-list=${Object.keys(data.qs).join(';')}&q-signature=${signature}`
data.headers.Authorization = authorization
return data
}
}
... ...
... ... @@ -2,4 +2,9 @@
<div>
Node logs
</div>
</template>
\ No newline at end of file
</template>
<script>
export default {
}
</script>
\ No newline at end of file
... ...