Skip to main content

字符串

字符串是一种原语数据类型,被用于来保存文本数据。

💡 常用字符串 Usage

字符串属性类型可被用于来存储任何基于文本的数据,例如:

  • 镜像标签;
  • 可变密钥
  • 提交 SHA;
  • 文件名;
  • 等等。

live demo 这个示例中,我们可以看到 Language 字符串属性。

应用程序接口定义

{
"myStringProp": {
"title": "My string",
"icon": "My icon",
"description": "My string property",
"type": "string",
"default": "My default"
}
}

Check out Port's API reference to learn more.

Terraform 定义

resource "port_blueprint" "myBlueprint" {
# ...blueprint properties
properties = {
string_props = {
"myStringProp" = {
title = "My string"
required = false
}
}
}
}

Pulumi 的定义

"""A Python Pulumi program"""

import pulumi
from port_pulumi import Blueprint,BlueprintPropertiesArgs,BlueprintPropertiesStringPropsArgs

blueprint = Blueprint(
"myBlueprint",
identifier="myBlueprint",
title="My Blueprint",
properties=BlueprintPropertiesArgs(
string_props={
"myStringProp": BlueprintPropertiesStringPropsArgs(
title="My string", required=False
)
),
relations={}
)

验证字符串

字符串验证支持以下操作符:

  • minLength - 执行最小字符串长度;
  • maxLength - 执行最大字符串长度;
  • pattern - 执行 Regex 模式。
{
"myStringProp": {
"title": "My string",
"icon": "My icon",
"description": "My string property",
"type": "string",
"minLength": 1,
"maxLength": 32,
"pattern": "^[a-zA-Z0-9-]*-service$"
}
}