Skip to content

Commit

Permalink
feat: 云函数支持 http和停启控制;新增函数编辑历史规则;
Browse files Browse the repository at this point in the history
  • Loading branch information
maslow committed Jun 15, 2021
1 parent 3cd5277 commit 56cfa8e
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion init/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#! /usr/bin/env node

const Config = require('../dist/config').default
const { hash } = require('../dist/lib/token')
const { hash } = require('../dist/lib/utils/token')
const assert = require('assert')
const { MongoAccessor, getDb } = require('less-api')
const adminRules = require('./rules/admin.json')
Expand Down
6 changes: 4 additions & 2 deletions init/permissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ exports.permissions = [
{ name: 'function.delete', label: '删除云函数' },
{ name: 'function.publish', label: '发布云函数' },
{ name: 'function.debug', label: '调试云函数' },
{ name: 'function.triggers', label: '调试云函数' },

{ name: 'function_logs.read', label: '查看云函数日志' },
{ name: 'function_logs.delete', label: '查看云函数日志' },
{ name: 'function_logs.delete', label: '删除云函数日志' },

{ name: 'function_history.read', label: '查看云函数历史' },
{ name: 'function_history.create', label: '创建云函数历史' },

{ name: 'trigger.create', label: '创建触发器' },
{ name: 'trigger.read', label: '获取触发器' },
Expand Down
5 changes: 5 additions & 0 deletions init/rules/admin.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@
"remove": "$has('function_logs.remove')",
"count": "$has('function_logs.read')"
},
"function_history": {
"read": "$has('function_history.read')",
"add": "$has('function_history.create')",
"count": "$has('function_history.read')"
},
"triggers": {
"read": "$has('trigger.read')",
"update": "$has('trigger.edit')",
Expand Down
2 changes: 1 addition & 1 deletion src/lib/faas/engine2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class FunctionEngine {
return {
__context__: incomingCtx.context,
module: _module,
exports: module.exports,
exports: _module.exports,
__runtime_promise: null,
console: fconsole,
less: incomingCtx.less,
Expand Down
2 changes: 2 additions & 0 deletions src/lib/faas/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ export interface CloudFunctionStruct {
_id: string,
name: string,
code: string,
enableHTTP: boolean,
status: number,
time_usage: number,
created_by: number,
created_at: number
Expand Down
8 changes: 8 additions & 0 deletions src/router/function/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ async function handleInvokeFunction(req: Request, res: Response) {
return res.send({ code: 1, error: 'function not found', requestId })
}

if (!func.enableHTTP && !debug) {
return res.status(404).send('Not Found')
}

if (1 !== func.status && !debug) {
return res.status(404).send('Not Found')
}

// 调用函数
const ctx: FunctionContext = {
query: req.query,
Expand Down

0 comments on commit 56cfa8e

Please sign in to comment.