OverriddenLogic 覆写逻辑
1. 结构声明
- TS Declaration
- JSON Schema
class OverriddenLogic extends BaseNode {
overriddenModule: string;
name: string = '';
description: string;
triggerType?: string;
cron?: string;
transactional?: Transactional;
typeParams?: Array<TypeParam>;
params: Array<Param>;
returns: Array<Return>;
variables: Array<Variable>;
body: Array<LogicItem>;
playground: Array<LogicItem>;
}
{
"type": "object",
"properties": {
"composedBy": {
"type": "array",
"items": {
"type": "string"
}
},
"changedTime": {
"$ref": "#/definitions/long"
},
"overriddenModule": {
"type": "string"
},
"name": {
"type": "string"
},
"description": {
"type": "string"
},
"triggerType": {
"type": "string"
},
"cron": {
"type": "string"
},
"transactional": {
"$ref": "#/definitions/Transactional"
},
"typeParams": {
"type": "array",
"items": {
"$ref": "#/definitions/TypeParam"
}
},
"params": {
"type": "array",
"items": {
"$ref": "#/definitions/Param"
}
},
"returns": {
"type": "array",
"items": {
"$ref": "#/definitions/Return"
}
},
"variables": {
"type": "array",
"items": {
"$ref": "#/definitions/Variable"
}
},
"body": {
"type": "array",
"items": {
"$ref": "#/definitions/LogicItem"
}
},
"playground": {
"type": "array",
"items": {
"$ref": "#/definitions/LogicItem"
}
}
},
"required": [
"overriddenModule",
"name",
"description",
"params",
"returns",
"variables",
"body",
"playground"
],
"additionalProperties": false
}
2. 节点示例
(1) 示例
AST 如下:
- JSON
- YAML
{
"concept": "OverriddenLogic",
"overriddenModule": "lcap_permission",
"name": "checkPermission",
"description": "校验用户访问资源的权限",
"triggerType": "",
"cron": "",
"transactional": {
"concept": "Transactional",
"enabled": false
},
"params": [
{
"concept": "Param",
"name": "userId",
"description": "用户唯一标识",
"typeAnnotation": {
"concept": "TypeAnnotation",
"typeKind": "primitive",
"typeNamespace": "nasl.core",
"typeName": "String",
"inferred": false,
"ruleMap": {}
}
},
{
"concept": "Param",
"name": "resourceValue",
"description": "资源值(通常为浏览器上的访问路径)",
"typeAnnotation": {
"concept": "TypeAnnotation",
"typeKind": "primitive",
"typeNamespace": "nasl.core",
"typeName": "String",
"inferred": false,
"ruleMap": {}
}
},
{
"concept": "Param",
"name": "resourceType",
"description": "资源的类型(表示当前资源是页面还是组件)",
"typeAnnotation": {
"concept": "TypeAnnotation",
"typeKind": "primitive",
"typeNamespace": "nasl.core",
"typeName": "String",
"inferred": false,
"ruleMap": {}
}
},
{
"concept": "Param",
"name": "clientType",
"description": "资源所属的端标识(多端场景下存在重名资源)",
"typeAnnotation": {
"concept": "TypeAnnotation",
"typeKind": "primitive",
"typeNamespace": "nasl.core",
"typeName": "String",
"inferred": false,
"ruleMap": {}
}
}
],
"returns": [
{
"concept": "Return",
"name": "result",
"description": "用户是否能访问指定资源",
"typeAnnotation": {
"concept": "TypeAnnotation",
"typeKind": "primitive",
"typeNamespace": "nasl.core",
"typeName": "Boolean",
"inferred": false,
"ruleMap": {}
},
"defaultValue": {
"concept": "DefaultValue",
"expression": {
"concept": "BooleanLiteral",
"value": "false"
},
"playground": []
}
}
],
"variables": [],
"body": [
{
"concept": "Start",
"label": "开始"
},
{
"concept": "IfStatement",
"test": {
"concept": "BinaryExpression",
"left": {
"concept": "Identifier",
"namespace": "",
"name": "resourceValue"
},
"right": {
"concept": "StringLiteral",
"value": "/index"
},
"operator": "=="
},
"consequent": [
{
"concept": "Assignment",
"left": {
"concept": "Identifier",
"namespace": "",
"name": "result"
},
"right": {
"concept": "BooleanLiteral",
"value": "true"
}
}
],
"alternate": [],
"label": "条件分支"
},
{
"concept": "End",
"label": "结束"
}
],
"playground": []
}
concept: OverriddenLogic
overriddenModule: lcap_permission
name: checkPermission
description: 校验用户访问资源的权限
triggerType: ""
cron: ""
transactional:
concept: Transactional
enabled: false
params:
- concept: Param
name: userId
description: 用户唯一标识
typeAnnotation:
concept: TypeAnnotation
typeKind: primitive
typeNamespace: nasl.core
typeName: String
inferred: false
ruleMap: {}
- concept: Param
name: resourceValue
description: 资源值(通常为浏览器上的访问路径)
typeAnnotation:
concept: TypeAnnotation
typeKind: primitive
typeNamespace: nasl.core
typeName: String
inferred: false
ruleMap: {}
- concept: Param
name: resourceType
description: 资源的类型(表示当前资源是页面还是组件)
typeAnnotation:
concept: TypeAnnotation
typeKind: primitive
typeNamespace: nasl.core
typeName: String
inferred: false
ruleMap: {}
- concept: Param
name: clientType
description: 资源所属的端标识(多端场景下存在重名资源)
typeAnnotation:
concept: TypeAnnotation
typeKind: primitive
typeNamespace: nasl.core
typeName: String
inferred: false
ruleMap: {}
returns:
- concept: Return
name: result
description: 用户是否能访问指定资源
typeAnnotation:
concept: TypeAnnotation
typeKind: primitive
typeNamespace: nasl.core
typeName: Boolean
inferred: false
ruleMap: {}
defaultValue:
concept: DefaultValue
expression:
concept: BooleanLiteral
value: "false"
playground: []
variables: []
body:
- concept: Start
label: 开始
- concept: IfStatement
test:
concept: BinaryExpression
left:
concept: Identifier
namespace: ""
name: resourceValue
right:
concept: StringLiteral
value: /index
operator: ==
consequent:
- concept: Assignment
left:
concept: Identifier
namespace: ""
name: result
right:
concept: BooleanLiteral
value: "true"
alternate: []
label: 条件分支
- concept: End
label: 结束
playground: []
对应的代码如下:
- 文本化 NASL
- Natural TS
@override(lcap_permission)
logic checkPermission(userId: String, resourceValue: String, resourceType: String, clientType: String) => result: Boolean {
if (resourceValue == '/index') {
result = true
} else {
}
end
}
function checkPermission(userId: String, resourceValue: String, resourceType: String, clientType: String): Boolean {
let result: Boolean;
if (resourceValue == '/index') {
result = true
} else {
}
return;
}