Skip to main content

高级输入配置

高级输入设置可让您为执行自助操作的用户创建更多可定制的体验。 具体方法是创建自适应输入,根据实体、用户和其他输入的相关数据进行更改。

常见被用于情况​

  • 过滤下拉输入中的可用选项。
  • 在输入之间创建依赖关系,允许用户根据另一个输入的值选择一个值。
  • 根据登录的用户属性(如团队、电子邮件、角色)或正在执行操作的实体(仅限第 2 天或删除操作)定义动态默认值。
Pulumi 示例的语言 除非另有说明,所有Pulumi配置示例均以 Python 语言提供。 有关其他语言的用法,请参阅 Pulumi Provider 文档here 。

Usage​

目前仅支持以 JSON 模式定义高级输入。

创建动作后,第二步是定义输入。 至少定义一个输入后,表单底部会出现 "高级配置 "部分。 单击 "编辑 JSON",然后添加 JSON 格式的配置。

编写配置模式​

Port 提供了一个 jqQuery 属性,可用于从实体、登录用户或当前操作的表单输入中提取数据。 它还可用于执行数据操作。

例如,下面的 jqQuery 检查另一个属性(language)的值,并据此确定 SDK 属性的可能值:

{
"properties": {
"language": {
"type": "string",
"enum": ["javascript", "python"]
},
"SDK": {
"type": "string",
"enum": {
"jqQuery": "if .form.language == \"javascript\" then [\"Node 16\", \"Node 18\"] else [\"Python 3.8\"] end"
}
}
}
}

使用 "jqQuery "对象可以访问的属性​

当前操作表单中的输入值。

Usage:

{
"jqQuery": ".form.input1"
}

可用的 form 对象(每个输入都是动作userInputs 对象中的一个键) :

{
"input1": "...",
"input2": "...",
"input3": "..."
}

jqQuery 表达式支持的键:

KeyDescription
enumany enum of a property
defaultthe default value of any property
requiredthe properties which will be required in the form
valuethe value inside a "dataset" rule
visiblethe condition to display any property in the form

其他可用房产​

您可以使用这些附加属性创建更复杂的输入:

可见 "属性用于动态隐藏/显示表单中的输入。 可见 "值可以设置为一个布尔值("true "值总是显示,"false "值总是隐藏),也可以设置为一个评估为布尔值的 "jqQuery"。

在本例中,"runArguments "属性配置为 "visible",因此只有在 "language "输入框中选择匹配值时,它们才会显示在表单中:

{
"properties": {
"language": {
"type": "string",
"enum": ["javascript", "python"]
},
"pythonRunArguments": {
"type": "string",
"visible": {
"jqQuery": ".form.language == \"python\""
}
},
"nodeRunArguments": {
"type": "string",
"visible": {
"jqQuery": ".form.language == \"javascript\""
}
}
}
}

模式示例​

在两个表单输入之间创建依赖关系​

此示例中,"language "输入和 "SDK "输入之间存在依赖关系,"SDK "输入的可用选项是根据所选语言定义的(参见 "jqQuery "键)。

{
"properties": {
"language": {
"type": "string",
"enum": ["javascript", "python"]
},
"SDK": {
"type": "string",
"enum": {
"jqQuery": "if .form.language == \"javascript\" then [\"Node 16\", \"Node 18\"] else [\"Python 3.8\"] end"
},
"dependsOn": ["language"]
}
}
}

Cluster And Namespace Action

###根据执行用户的角色隐藏属性

在此示例中,"visible "会检查执行用户是否具有 "admin "角色,如果不具有该角色,则会隐藏高级选项。 默认值仍会被填写并发送到后端:

{
"properties": {
"simpleOption": {
"type": "string",
"enum": ["option1", "option2"]
},
"advancedOption": {
"type": "string",
"default": "default advanced value",
"visible": {
"jqQuery": ".user.roles | any(.name == \"Admin\")"
}
}
}
}

非管理员用户的运行表单显示如下: !What Non-Admins See

管理员用户的表单显示如下: !What Admins See

###根据属性过滤下拉菜单中的可用选项

此示例包含一个过滤器,只显示related to 在 Cluster 输入中所选集群的 namespace:

{
"env": {
"type": "string",
"format": "entity",
"blueprint": "environment",
"dataset": {
"combinator": "and",
"rules": [
{
"property": "type",
"operator": "!=",
"value": "production"
}
]
}
}
}

Only Production Envs

☝ 只有类型不是 "生产 "的环境才会出现在下拉菜单中。 ☝

###根据之前的输入过滤下拉菜单中的可用选项

此示例包含一个过滤器,只显示related to 在 Cluster 输入中所选集群的 namespace:

{
"Cluster": {
"type": "string",
"format": "entity",
"blueprint": "Cluster",
"title": "Cluster",
"description": "The cluster to create the namespace in"
},
"namespace": {
"type": "string",
"format": "entity",
"blueprint": "namespace",
"dependsOn": ["Cluster"],
"dataset": {
"combinator": "and",
"rules": [
{
"blueprint": "Cluster",
"operator": "relatedTo",
"value": {
"jqQuery": ".form.Cluster.identifier"
}
}
]
},
"title": "namespace",
"description": "The namespace to create the cluster in"
}
}

Cluster And Namespace Action

point_up: 用户需要选择一个集群,然后`namespace'输入列表将填充与所选集群相关的 namespace 实体:

###根据执行操作的用户属性过滤下拉菜单的可用选项

此示例包含一个过滤器,只显示属于用户团队的 namespace(注意规则对象中的值键):

{
"namespace": {
"type": "string",
"format": "entity",
"blueprint": "namespace",
"dataset": {
"combinator": "and",
"rules": [
{
"property": "$team",
"operator": "containsAny",
"value": {
"jqQuery": "[.user.teams[].name]"
}
}
]
}
}
}

Cluster And Namespace Action

☝ 这些是唯一与登录用户的团队相关联的 namespace:

###根据执行操作的实体属性过滤下拉菜单的可用选项

此示例包含一个过滤器,只显示与执行操作的实体具有相似标记的 namespace:

{
"namespace": {
"type": "string",
"format": "entity",
"blueprint": "namespace",
"dataset": {
"combinator": "and",
"rules": [
{
"property": "tags",
"operator": "containsAny",
"value": {
"jqQuery": "[.entity.properties.tags[]]"
}
}
]
}
}
}

使用 jqQuery 设置默认值​

此示例包含一个数组输入,其默认值将等于执行操作的实体的标记:

{
"some_input": {
"type": "array",
"default": {
"jqQuery": ".entity.properties.tags"
}
}
}

entity tags action

☝ 命名空间标记已插入表单中。 ☝

使用 jqQuery 设置所需输入内容​

此示例包含两个用户输入: 一个始终为必填项,另一个根据实体属性为必填项。

{
"properties": {
"alwaysRequiredInput": {
"type": "string"
},
"inputRequiredBasedOnData": {
"type": "string"
}
},
"required": {
"jqQuery": "if .entity.properties.conditionBooleanProperty then [\"alwaysRequiredInput\", \"inputRequiredBasedOnData\"] else [\"alwaysRequiredInput\"] end"
}
}

完整示例​

在这个示例中,我们将创建一个操作,让用户选择一个集群和该集群中的一个命名空间。 用户还可以选择一个已在集群中运行的服务。 然后,该操作将把选定的服务部署到集群中选定的命名空间。 用户只能选择与他的团队相关联的服务。

Port 中的现有模型:​

Developer PortalCreate New Blueprint

动作配置:​

{
"identifier": "createRunningService",
"title": "Deploy running service to a cluster",
"icon": "Cluster",
"userInputs": {
"properties": {
"Cluster": {
"type": "string",
"format": "entity",
"blueprint": "Cluster",
"title": "Cluster",
"description": "The cluster to create the namespace in"
},
"namespace": {
"type": "string",
"format": "entity",
"blueprint": "namespace",
"dependsOn": ["Cluster"],
"dataset": {
"combinator": "and",
"rules": [
{
"blueprint": "Cluster",
"operator": "relatedTo",
"value": {
"jqQuery": ".form.Cluster.identifier"
}
}
]
},
"title": "namespace",
"description": "The namespace to create the cluster in"
},
"service": {
"type": "string",
"format": "entity",
"blueprint": "Service",
"dataset": {
"combinator": "and",
"rules": [
{
"blueprint": "$team",
"operator": "containsAny",
"value": {
"jqQuery": "[.user.teams[].name]"
}
}
]
},
"title": "Service"
}
},
"required": ["Cluster", "namespace", "service"]
},
"invocationMethod": {
"type": "WEBHOOK",
"url": "https://example.com"
},
"trigger": "CREATE",
"description": "This will deploy a running service to a cluster"
}

开发人员门户网站中的操作:​

Cluster And Namespace Action

point_up: 用户需要选择一个集群,然后在名称空间输入列表中填入与所选集群相关的名称空间实体。 用户只能部署与其团队相关的服务。请注意 "team "前的"$",这表示这是一个metadata property 。