Skip to content

Commit

Permalink
feat(system-server): add policy CRUD routers;
Browse files Browse the repository at this point in the history
  • Loading branch information
maslow committed Sep 3, 2021
1 parent c8c4fb2 commit 8456aab
Show file tree
Hide file tree
Showing 14 changed files with 446 additions and 129 deletions.
63 changes: 56 additions & 7 deletions packages/system-client/src/api/func.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import store from '@/store'
import request from '@/utils/request'

/**
* 分页获取云函数列表
* Get cloud function list
* @param {*} query
* @param {*} page
* @param {*} pageSize
*/
export function getFunctions(appid, query, page, pageSize) {
export function getFunctions(query, page, pageSize) {
const appid = store.state.app.appid
return request({
url: `/apps/${appid}/function`,
method: 'get',
Expand All @@ -18,34 +20,81 @@ export function getFunctions(appid, query, page, pageSize) {
})
}

/**
* Get a cloud function
* @param {*} query
* @param {*} page
* @param {*} pageSize
*/
export function getFunctionById(func_id) {
const appid = store.state.app.appid
return request({
url: `/apps/${appid}/function/${func_id}`,
method: 'get'
})
}

/**
* Create a cloud function
* @param {string} appid
* @param {object} function_data
* @returns
*/
export function createFunction(appid, function_data) {
export function createFunction(function_data) {
const appid = store.state.app.appid
return request({
url: `/apps/${appid}/function/create`,
method: 'post',
data: function_data
})
}

export function updateFunction(appid, function_data) {
/**
* Update the basic info of cloud function
* @param {string} func_id
* @param {object} function_data
* @returns
*/
export function updateFunction(func_id, function_data) {
const appid = store.state.app.appid
return request({
url: `/apps/${appid}/function/create`,
url: `/apps/${appid}/function/${func_id}/info`,
method: 'post',
data: function_data
})
}

/**
* 运行云函数
* Delete a cloud function
* @param {*} func_id
* @returns
*/
export function deleteFunction(func_id) {
const appid = store.state.app.appid
return request({
url: `/apps/${appid}/function/${func_id}`,
method: 'delete'
})
}

/**
* Publish functions
*/
export function publishFunctions() {
const appid = store.state.app.appid
return request({
url: `/apps/${appid}/function/publish`,
method: 'post'
})
}

/**
* Debug cloud function
*/
export function launchFunction(functionName, data, debug = false) {
const appid = store.state.app.appid
return request({
url: `/app/func/invoke/${functionName}`,
url: `/apps/${appid}/function/debug/${functionName}`,
method: 'post',
data: data,
headers: {
Expand Down
90 changes: 90 additions & 0 deletions packages/system-client/src/api/policy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import store from '@/store'
import request from '@/utils/request'

/**
* Get policy list
* @param {*} query
* @param {*} page
* @param {*} pageSize
*/
export function getPolicies(query, page, pageSize) {
const appid = store.state.app.appid
return request({
url: `/apps/${appid}/policy`,
method: 'get',
params: {
...query,
page,
limit: pageSize
}
})
}

/**
* Get a policy
* @param {*} query
* @param {*} page
* @param {*} pageSize
*/
export function getPolicyById(policy_id) {
const appid = store.state.app.appid
return request({
url: `/apps/${appid}/policy/${policy_id}`,
method: 'get'
})
}

/**
* Create a policy
* @param {string} appid
* @param {object} data
* @returns
*/
export function createPolicy(data) {
const appid = store.state.app.appid
return request({
url: `/apps/${appid}/policy/create`,
method: 'post',
data: data
})
}

/**
* Update a policy
* @param {*} policy_id
* @param {*} data
* @returns
*/
export function updatePolicy(policy_id, data) {
const appid = store.state.app.appid
return request({
url: `/apps/${appid}/policy/${policy_id}/info`,
method: 'post',
data: data
})
}

/**
* Delete a policy
* @param {*} policy_id
* @param {*} data
* @returns
*/
export function deletePolicy(policy_id) {
const appid = store.state.app.appid
return request({
url: `/apps/${appid}/policy/${policy_id}`,
method: 'delete'
})
}

/**
* Publish policies
*/
export function publishPolicies() {
const appid = store.state.app.appid
return request({
url: `/apps/${appid}/policy/publish`,
method: 'post'
})
}
20 changes: 0 additions & 20 deletions packages/system-client/src/api/publish.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,5 @@
import request from '@/utils/request'

/**
* 发布访问策略
*/
export function publishPolicy() {
return request({
url: '/publish/policy',
method: 'post'
})
}

/**
* 发布云函数
*/
export function publishFunctions() {
return request({
url: '/publish/functions',
method: 'post'
})
}

/**
* 发布触发器
*/
Expand Down
3 changes: 3 additions & 0 deletions packages/system-client/src/store/modules/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const state = {
* 当前应用对象
*/
application: null,
appid: null,
/**
* 用户在当前应用的角色
*/
Expand All @@ -19,6 +20,7 @@ const state = {
const mutations = {
SET_APPLICATION: (state, payload) => {
state.application = payload
state.appid = payload?.appid
},
SET_APP_ROLES: (state, payload) => {
state.roles = payload || []
Expand All @@ -28,6 +30,7 @@ const mutations = {
},
CLEAR_STATE: (state) => {
state.application = null
state.appid = null
state.roles = []
state.permissions = []
}
Expand Down
7 changes: 0 additions & 7 deletions packages/system-client/src/views/application/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
</el-table-column>
<el-table-column fixed="right" label="服务启停" align="center" width="380" class-name="small-padding">
<template slot-scope="{row}">

<el-button v-if="row.status !== 'running'" plain type="warning" size="mini" @click="startApp(row)">
启动
</el-button>
Expand All @@ -52,12 +51,6 @@
<el-button plain type="default" size="mini" @click="showUpdateForm(row)">
编辑
</el-button>
<el-button v-if="row.status !== 'running'" plain type="warning" size="mini" @click="startApp(row)">
启动应用
</el-button>
<el-button v-if="row.status === 'running'" plain type="danger" size="mini" @click="stopApp(row)">
停止应用
</el-button>
<el-button plain size="mini" type="info" @click="deleteApp(row,$index)">
删除
</el-button>
Expand Down
Loading

0 comments on commit 8456aab

Please sign in to comment.