当前位置: 首页>>代码示例>>Golang>>正文


Golang constraints.PropertyExists函数代码示例

本文整理汇总了Golang中github.com/jagregory/cfval/constraints.PropertyExists函数的典型用法代码示例。如果您正苦于以下问题:Golang PropertyExists函数的具体用法?Golang PropertyExists怎么用?Golang PropertyExists使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了PropertyExists函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: TestResourcePropertyConflictValidation

func TestResourcePropertyConflictValidation(t *testing.T) {
	template := &parse.Template{}
	res := Resource{
		Properties: Properties{
			"Option1": Schema{
				Type:      ValueString,
				Conflicts: constraints.PropertyExists("Option2"),
			},

			"Option2": Schema{
				Type:      ValueString,
				Conflicts: constraints.PropertyExists("Option1"),
			},
		},
	}
	ctx := NewInitialContext(template, NewResourceDefinitions(map[string]Resource{
		"TestResource": res,
	}), ValidationOptions{})

	nothingSet := ResourceWithDefinition{
		parse.NewTemplateResource("TestResource", map[string]interface{}{}),
		res,
	}
	option1Set := ResourceWithDefinition{
		parse.NewTemplateResource("TestResource", map[string]interface{}{
			"Option1": "value",
		}),
		res,
	}
	option2Set := ResourceWithDefinition{
		parse.NewTemplateResource("TestResource", map[string]interface{}{
			"Option2": "value",
		}),
		res,
	}
	bothSet := ResourceWithDefinition{
		parse.NewTemplateResource("TestResource", map[string]interface{}{
			"Option1": "value",
			"Option2": "value",
		}),
		res,
	}

	if _, errs := res.Validate(NewResourceContext(ctx, nothingSet)); errs != nil {
		t.Error("Resource should pass if both neither Option1 or Option2 are set", errs)
	}

	if _, errs := res.Validate(NewResourceContext(ctx, option1Set)); errs != nil {
		t.Error("Resource should pass if only Option1 set", errs)
	}

	if _, errs := res.Validate(NewResourceContext(ctx, option2Set)); errs != nil {
		t.Error("Resource should pass if only Option2 set", errs)
	}

	if _, errs := res.Validate(NewResourceContext(ctx, bothSet)); errs == nil {
		t.Error("Resource should fail if both Option1 or Option2 are set")
	}
}
开发者ID:jagregory,项目名称:cfval,代码行数:59,代码来源:resource_test.go

示例2:

	ReturnValue: Schema{
		Type: ARN,
	},

	Properties: Properties{
		"Cluster": Schema{
			Type: ValueString,
		},

		"DesiredCount": Schema{
			Type:     ValueString,
			Required: constraints.Always,
		},

		"LoadBalancers": Schema{
			Type: Multiple(loadBalancer),
		},

		"Role": Schema{
			Type:     ValueString,
			Required: constraints.PropertyExists("LoadBalancers"),
		},

		"TaskDefinition": Schema{
			Type:     ValueString,
			Required: constraints.Always,
		},
	},
}
开发者ID:jagregory,项目名称:cfval,代码行数:29,代码来源:service.go

示例3:

package cloud_front

import (
	"github.com/jagregory/cfval/constraints"
	. "github.com/jagregory/cfval/schema"
)

var viewerCertificate = NestedResource{
	Description: "CloudFront DistributionConfiguration ViewerCertificate",
	Properties: Properties{
		"CloudFrontDefaultCertificate": Schema{
			Type:      ValueBool,
			Conflicts: constraints.PropertyExists("IamCertificateId"),
			Required:  constraints.PropertyNotExists("IamCertificateId"),
		},

		"IamCertificateId": Schema{
			Type:      ValueString,
			Conflicts: constraints.PropertyExists("CloudFrontDefaultCertificate"),
			Required:  constraints.PropertyNotExists("CloudFrontDefaultCertificate"),
		},

		"MinimumProtocolVersion": Schema{
			Type: ValueString,
			// TODO: If you specify the IamCertificateId property and specify SNI only
			//       for the SslSupportMethod property, you must use TLSv1 for the
			//       minimum protocol version. If you don't specify a value, AWS
			//       CloudFormation specifies SSLv3.
		},

		"SslSupportMethod": Schema{
开发者ID:jagregory,项目名称:cfval,代码行数:31,代码来源:viewer_certificate.go

示例4:

)

// see: http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-security-group-egress.html
var SecurityGroupEgress = Resource{
	AwsType: "AWS::EC2::SecurityGroupEgress",

	// Name
	ReturnValue: Schema{
		Type: ValueString,
	},

	Properties: Properties{
		"CidrIp": Schema{
			Type:      CIDR,
			Required:  constraints.PropertyNotExists("DestinationSecurityGroupId"),
			Conflicts: constraints.PropertyExists("DestinationSecurityGroupId"),
		},

		"DestinationSecurityGroupId": Schema{
			Type:      SecurityGroupID,
			Required:  constraints.PropertyNotExists("CidrIp"),
			Conflicts: constraints.PropertyExists("CidrIp"),
		},

		"FromPort": Schema{
			Type:     ValueNumber,
			Required: constraints.Always,
		},

		"GroupId": Schema{
			Type:     SecurityGroupID,
开发者ID:jagregory,项目名称:cfval,代码行数:31,代码来源:security_group_egress.go

示例5:

package ec2

import (
	"github.com/jagregory/cfval/constraints"
	. "github.com/jagregory/cfval/schema"
)

// see: http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-security-group-ingress.html
var SecurityGroupIngress = Resource{
	AwsType: "AWS::EC2::SecurityGroupIngress",

	Properties: Properties{
		"CidrIp": Schema{
			Type: CIDR,
			Conflicts: constraints.Any{
				constraints.PropertyExists("SourceSecurityGroupName"),
				constraints.PropertyExists("SourceSecurityGroupId"),
			},
		},

		"FromPort": Schema{
			Type:     ValueNumber,
			Required: constraints.Always,
		},

		"GroupId": Schema{
			Type:     SecurityGroupID,
			Required: constraints.PropertyNotExists("GroupName"),
		},

		"GroupName": Schema{
开发者ID:jagregory,项目名称:cfval,代码行数:31,代码来源:security_group_ingress.go

示例6:

	},

	Properties: Properties{
		"Enabled": Schema{
			Type:    ValueBool,
			Default: true,
		},

		"EventCategories": Schema{
			Type: Multiple(ValueString),
		},

		"SnsTopicArn": Schema{
			Type:     ARN,
			Required: constraints.Always,
		},

		"SourceIds": Schema{
			Type: Multiple(ValueString),
		},

		"SourceType": Schema{
			Type: ValueString,
			Required: constraints.Any{
				constraints.PropertyExists("SourceIds"),
				constraints.PropertyExists("EventCategories"),
			},
		},
	},
}
开发者ID:jagregory,项目名称:cfval,代码行数:30,代码来源:event_subscription.go

示例7:

	. "github.com/jagregory/cfval/schema"
)

// see: http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-s3-websiteconfiguration-routingrules-redirectrule.html
var websiteConfigurationRoutingRuleRedirectRule = NestedResource{
	Description: "S3 Website Configuration Routing Rules Redirect Rule",
	Properties: Properties{
		"HostName": Schema{
			Type: ValueString,
		},

		"HttpRedirectCode": Schema{
			Type: ValueString,
		},

		"Protocol": Schema{
			Type: ValueString,
		},

		"ReplaceKeyPrefixWith": Schema{
			Type:      ValueString,
			Conflicts: constraints.PropertyExists("ReplaceKeyWith"),
		},

		"ReplaceKeyWith": Schema{
			Type:      ValueString,
			Conflicts: constraints.PropertyExists("ReplaceKeyPrefixWith"),
		},
	},
}
开发者ID:jagregory,项目名称:cfval,代码行数:30,代码来源:website_configuration_routing_rule_redirect_rule.go

示例8:

	ReturnValue: Schema{
		Type: ValueString,
	},

	Properties: Properties{
		"AccessLoggingPolicy": Schema{
			Type: accessLoggingPolicy,
		},

		"AppCookieStickinessPolicy": Schema{
			Type: Multiple(appCookieStickinessPolicy),
		},

		"AvailabilityZones": Schema{
			Type:      Multiple(AvailabilityZone),
			Conflicts: constraints.PropertyExists("Subnets"),
		},

		"ConnectionDrainingPolicy": Schema{
			Type: connectionDrainingPolicy,
		},

		"ConnectionSettings": Schema{
			Type: connectionSettings,
		},

		"CrossZone": Schema{
			Type:    ValueBool,
			Default: false,
		},
开发者ID:jagregory,项目名称:cfval,代码行数:30,代码来源:load_balancer.go

示例9:

		"EngineVersion": Schema{
			Type: ValueString,
		},

		"KmsKeyId": Schema{
			Type: ARN,
		},

		"MasterUsername": Schema{
			Type: ValueString,
			ValidateFunc: RegexpValidate(
				`^[a-zA-Z][a-zA-Z0-9]{1,15}$`,
				"Must be 1 to 16 alphanumeric characters. First character must be a letter.",
			),
			Required:  constraints.PropertyNotExists("SnapshotIdentifier"),
			Conflicts: constraints.PropertyExists("SnapshotIdentifier"),
		},

		"MasterUserPassword": Schema{
			Type: ValueString,
			ValidateFunc: RegexpValidate(
				`^[^\/"@]{8,41}$`,
				`This password can contain any printable ASCII character except "/", """, or "@". Must contain from 8 to 41 characters.`,
			),
			Required:  constraints.PropertyNotExists("SnapshotIdentifier"),
			Conflicts: constraints.PropertyExists("SnapshotIdentifier"),
		},

		"Port": Schema{
			Type:    ValueNumber,
			Default: 3306,
开发者ID:jagregory,项目名称:cfval,代码行数:31,代码来源:db_cluster.go

示例10:

package cloud_front

import (
	"github.com/jagregory/cfval/constraints"
	. "github.com/jagregory/cfval/schema"
)

// see: http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-cloudfront-origin.html
var origin = NestedResource{
	Description: "CloudFront DistributionConfig Origin",
	Properties: Properties{
		"CustomOriginConfig": Schema{
			Type:      customOriginConfig,
			Conflicts: constraints.PropertyExists("S3OriginConfig"),
			Required:  constraints.PropertyNotExists("S3OriginConfig"),
		},

		"DomainName": Schema{
			Type:     ValueString,
			Required: constraints.Always,
		},

		"Id": Schema{
			Type:     ValueString,
			Required: constraints.Always,
		},

		"OriginPath": Schema{
			Type:         ValueString,
			ValidateFunc: RegexpValidate(`^\/.*?[^\/]$`, "The value must start with a slash mark (/) and cannot end with a slash mark."),
		},
开发者ID:jagregory,项目名称:cfval,代码行数:31,代码来源:origin.go

示例11:

	"github.com/jagregory/cfval/constraints"
	. "github.com/jagregory/cfval/schema"
)

// see: http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-cloudfront-distributionconfig-customerrorresponse.html
var customErrorResponse = NestedResource{
	Description: "CloudFront DistributionConfig CustomErrorResponse",
	Properties: Properties{
		"ErrorCachingMinTTL": Schema{
			Type: ValueNumber,
		},

		"ErrorCode": Schema{
			Type:         ValueNumber,
			Required:     constraints.Always,
			ValidateFunc: NumberOptions(400, 403, 404, 405, 414, 500, 501, 502, 503, 504),
		},

		"ResponseCode": Schema{
			Type:         ValueNumber,
			Required:     constraints.PropertyExists("ResponsePagePath"),
			ValidateFunc: NumberOptions(200, 400, 403, 404, 405, 414, 500, 501, 502, 503, 504),
		},

		"ResponsePagePath": Schema{
			Type:     ValueString,
			Required: constraints.PropertyExists("ResponseCode"),
		},
	},
}
开发者ID:jagregory,项目名称:cfval,代码行数:30,代码来源:custom_error_response.go

示例12:

			ValidateFunc: azModeValidate,
			Default:      "single-az",
		},

		"CacheNodeType": Schema{
			Type:     cacheNodeType,
			Required: constraints.Always,
		},

		"CacheParameterGroupName": Schema{
			Type: ValueString,
		},

		"CacheSecurityGroupNames": Schema{
			Type:      Multiple(cacheSecurityGroupName),
			Conflicts: constraints.PropertyExists("VpcSecurityGroupIds"),
		},

		"CacheSubnetGroupName": Schema{
			Type: cacheSubnetGroupName,
		},

		"ClusterName": Schema{
			Type: ValueString,
		},

		"Engine": Schema{
			Type:     engine,
			Required: constraints.Always,
		},
开发者ID:jagregory,项目名称:cfval,代码行数:30,代码来源:cache_cluster.go

示例13:

package rds

import (
	"github.com/jagregory/cfval/constraints"
	. "github.com/jagregory/cfval/schema"
)

// see: http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-rds-optiongroup-optionconfigurations.html
var optionConfiguration = NestedResource{
	Description: "RDS OptionGroup OptionConfiguration",

	Properties: Properties{
		"DBSecurityGroupMemberships": Schema{
			Type:      Multiple(dbSecurityGroupName),
			Conflicts: constraints.PropertyExists("VPCSecurityGroupMemberships"),
		},

		"OptionName": Schema{
			Type:     ValueString,
			Required: constraints.Always,
		},

		"OptionSettings": Schema{
			Type: optionSettings,
		},

		"Port": Schema{
			Type: ValueNumber,
		},

		"VpcSecurityGroupMemberships": Schema{
开发者ID:jagregory,项目名称:cfval,代码行数:31,代码来源:option_configuration.go

示例14: TestNestedResourceConstraints

func TestNestedResourceConstraints(t *testing.T) {
	res := Resource{
		Properties: Properties{
			"Nested": Schema{
				Type: NestedResource{
					Properties: Properties{
						"One": Schema{
							Type: ValueString,
						},

						"Two": Schema{
							Type:     ValueString,
							Required: constraints.PropertyExists("One"),
						},
					},
				},
			},
		},
	}

	template := &parse.Template{}
	data := func(properties map[string]interface{}) ResourceContext {
		return NewContextShorthand(
			template,
			NewResourceDefinitions(map[string]Resource{
				"TestResource": res,
			}),
			ResourceWithDefinition{
				parse.NewTemplateResource("TestResource", properties),
				res,
			},
			Schema{},
			ValidationOptions{},
		)
	}

	twoMissing := map[string]interface{}{
		"Nested": map[string]interface{}{
			"One": "abc",
		},
	}
	if _, errs := res.Validate(data(twoMissing)); errs == nil {
		t.Error("Should fail with missing Two parameter")
	}

	oneInWrongPace := map[string]interface{}{
		"One":    "abc",
		"Nested": map[string]interface{}{},
	}
	if _, errs := res.Validate(data(oneInWrongPace)); errs == nil {
		t.Error("Should fail with missing Two parameter")
	}

	allFine := map[string]interface{}{
		"Nested": map[string]interface{}{
			"One": "abc",
			"Two": "abc",
		},
	}
	if _, errs := res.Validate(data(allFine)); errs != nil {
		t.Error("Should pass with One and Two", errs)
	}
}
开发者ID:jagregory,项目名称:cfval,代码行数:63,代码来源:nested_resource_test.go

示例15:

	Properties: Properties{
		"AssociatePublicIpAddress": Schema{
			Type: ValueBool,
		},

		"BlockDeviceMappings": Schema{
			Type: Multiple(autoScalingBlockDeviceMapping),
		},

		"ClassicLinkVPCId": Schema{
			Type: VpcID,
		},

		"ClassicLinkVPCSecurityGroups": Schema{
			Type:     Multiple(SecurityGroupID),
			Required: constraints.PropertyExists("ClassicLinkVPCId"),
		},

		"EbsOptimized": Schema{
			Type:    ValueBool,
			Default: false,
		},

		"IamInstanceProfile": Schema{
			Type:         ValueString,
			ValidateFunc: StringLengthValidate(1, 1600),
		},

		"ImageId": Schema{
			Type: ImageID,
		},
开发者ID:jagregory,项目名称:cfval,代码行数:31,代码来源:launch_configuration.go


注:本文中的github.com/jagregory/cfval/constraints.PropertyExists函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。