编号
Number 是一种原语数据类型,用于保存数值数据。
💡 常用数字用法
例如,数字属性类型可被用于来存储任何数值数据:
- 关键漏洞数量;
- 内存/存储分配;
- 副本数量;
- 未决问题的数量;
- 等等。
在live demo 示例中,我们可以看到 "JIRA 问题 "编号属性。
应用程序接口定义
- Basic
- Enum
- Array
- Enum Array
{
"myNumberProp": {
"title": "My number",
"icon": "My icon",
"description": "My number property",
"type": "number",
"default": 7
}
}
{
"myNumberEnum": {
"title": "My number enum",
"icon": "My icon",
"description": "My number enum",
"type": "number",
"enum": [1, 2, 3, 4]
}
}
{
"myNumberArray": {
"title": "My number array",
"icon": "My icon",
"description": "My number array",
"type": "array",
"items": {
"type": "number"
}
}
}
{
"myNumberArray": {
"title": "My number enum array",
"icon": "My icon",
"description": "My number enum array",
"type": "array",
"items": {
"type": "number",
"enum": [1, 2, 3, 4],
"enumColors": {
"1": "red",
"2": "green",
"3": "blue"
}
}
}
}
Check out Port's API reference to learn more.
Terraform 定义
- Basic
- Enum
- Array
resource "port_blueprint" "myBlueprint" {
# ...blueprint properties
properties = {
number_props = {
"myNumberProp" = {
title = "My number"
description = "My number property"
default = 7
}
}
}
}
resource "port_blueprint" "myBlueprint" {
# ...blueprint properties
properties = {
number_props = {
"myNumberProp" = {
title = "My number"
description = "My number property"
enum = [1, 2, 3, 4]
}
}
}
}
resource "port_blueprint" "myBlueprint" {
# ...blueprint properties
properties = {
"myNumberArray" = {
title = "My number array"
description = "My number array"
number_items = {}
}
"myNumberArrayWithDefault" = {
title = "My number array with default"
description = "My number array"
number_items = {
default = [1, 2, 3, 4]
}
}
}
}
Pulumi 的定义
- Basic
- Enum - coming soon
- Array - coming soon
- Python
- TypeScript
- JavaScript
- GO
"""A Python Pulumi program"""
import pulumi
from port_pulumi import Blueprint,BlueprintPropertiesArgs,BlueprintPropertiesNumberPropsArgs
blueprint = Blueprint(
"myBlueprint",
identifier="myBlueprint",
title="My Blueprint",
properties=BlueprintPropertiesArgs(
number_props={
"myNumberProp": BlueprintPropertiesNumberPropsArgs(
title="My number", required=False,
)
},
),
relations={}
)
import * as pulumi from "@pulumi/pulumi";
import * as port from "@port-labs/port";
export const blueprint = new port.Blueprint("myBlueprint", {
identifier: "myBlueprint",
title: "My Blueprint",
properties: {
numberProps: {
myNumberProp: {
title: "My number",
required: false,
},
},
},
});
"use strict";
const pulumi = require("@pulumi/pulumi");
const port = require("@port-labs/port");
const entity = new port.Blueprint("myBlueprint", {
title: "My Blueprint",
identifier: "myBlueprint",
properties: {
numberProps: {
myNumberProp: {
title: "My number",
required: false,
},
},
},
relations: {},
});
exports.title = entity.title;
package main
import (
"github.com/port-labs/pulumi-port/sdk/go/port"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
blueprint, err := port.NewBlueprint(ctx, "myBlueprint", &port.BlueprintArgs{
Identifier: pulumi.String("myBlueprint"),
Title: pulumi.String("My Blueprint"),
Properties: port.BlueprintPropertiesArgs{
NumberProps: port.BlueprintPropertiesNumberPropsMap{
"myNumberProp": port.BlueprintPropertiesNumberPropsArgs{
Title: pulumi.String("My number"),
Required: pulumi.Bool(false),
},
},
},
})
ctx.Export("blueprint", blueprint.Title)
if err != nil {
return err
}
return nil
})
}
验证号码
数字验证支持以下操作符:
- 范围
使用 "最小值 "和 "最大值 "关键字(或 "独占最小值 "和 "独占最大值 "表达独占范围)的组合指定数字范围。
如果 x 是要验证的值,则以下条件必须成立:
- x ≥ `最小值
- x > `专属最小值
- x ≤ `最大值
- x < `独占最大值
- Basic
- Array
- Terraform
- Pulumi - comfing soon
{
"myNumberProp": {
"title": "My number",
"icon": "My icon",
"description": "My number property",
"type": "number",
"minimum": 0,
"maximum": 50
}
}
{
"myNumberArray": {
"title": "My number array",
"icon": "My icon",
"description": "My number array",
"type": "array",
"items": {
"type": "number",
"exclusiveMinimum": 0,
"exclusiveMaximum": 50
}
}
}
resource "port_blueprint" "myBlueprint" {
properties = {
"number_props" = {
"myNumberProp" = {
title = "My number"
icon = "My icon"
description = "My number property"
minimum = 0
maximum = 50
}
}
}
}