本文整理汇总了Golang中github.com/jagregory/cfval/reporting.NewFailure函数的典型用法代码示例。如果您正苦于以下问题:Golang NewFailure函数的具体用法?Golang NewFailure怎么用?Golang NewFailure使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewFailure函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: validateGetAttAttributeID
func validateGetAttAttributeID(builtin parse.IntrinsicFunction, resourceID, attributeID interface{}, ctx PropertyContext) reporting.Reports {
resource := ctx.Template().Resources[resourceID.(string)]
definition := ctx.Definitions().Lookup(resource.Type)
switch t := attributeID.(type) {
case string:
if attribute, ok := definition.Attributes[t]; ok {
targetType := attribute.Type
switch targetType.CoercibleTo(ctx.Property().Type) {
case CoercionNever:
return reporting.Reports{reporting.NewFailure(ctx, "GetAtt value of %s.%s is %s but is being assigned to a %s property", resourceID, t, targetType.Describe(), ctx.Property().Type.Describe())}
case CoercionBegrudgingly:
return reporting.Reports{reporting.NewWarning(ctx, "GetAtt value of %s.%s is %s but is being dangerously coerced to a %s property", resourceID, t, targetType.Describe(), ctx.Property().Type.Describe())}
}
return nil
}
case parse.IntrinsicFunction:
getAttAttributeNameType := Schema{Type: ValueString}
_, errs := ValidateIntrinsicFunctions(t, NewPropertyContext(ctx, getAttAttributeNameType), SupportedFunctions{
parse.FnRef: true,
})
return errs
}
return reporting.Reports{reporting.NewFailure(ctx, "%s is not an attribute of %s", attributeID, resource.Type)}
}
开发者ID:jagregory,项目名称:cfval,代码行数:27,代码来源:if_get_att.go
示例2: validateSelectArray
func validateSelectArray(builtin parse.IntrinsicFunction, array interface{}, ctx PropertyContext) reporting.Reports {
if array == nil {
return reporting.Reports{reporting.NewFailure(ctx, "Array cannot be null")}
}
switch t := array.(type) {
case []interface{}:
reports := make(reporting.Reports, 0, 10)
for i, item := range t {
if item == nil {
reports = append(reports, reporting.NewFailure(PropertyContextAdd(ctx, strconv.Itoa(i)), "Array item cannot be null"))
}
}
return reporting.Safe(reports)
case parse.IntrinsicFunction:
arrayType := Schema{Type: Multiple(ValueString)}
_, errs := ValidateIntrinsicFunctions(t, NewPropertyContext(ctx, arrayType), SupportedFunctions{
parse.FnRef: true,
parse.FnFindInMap: true,
parse.FnGetAtt: true,
parse.FnGetAZs: true,
parse.FnIf: true,
})
return errs
}
return reporting.Reports{reporting.NewFailure(ctx, "Invalid value for array %s", array)}
}
开发者ID:jagregory,项目名称:cfval,代码行数:28,代码来源:if_select.go
示例3: validateGetAtt
func validateGetAtt(builtin parse.IntrinsicFunction, ctx PropertyContext) reporting.Reports {
if errs := validateIntrinsicFunctionBasicCriteria(parse.FnGetAtt, builtin, ctx); errs != nil {
return errs
}
value := builtin.UnderlyingMap[string(parse.FnGetAtt)]
args, ok := value.([]interface{})
if !ok || args == nil {
return reporting.Reports{reporting.NewFailure(ctx, "Invalid type for \"Fn::GetAtt\" key: %T", value)}
}
if len(args) != 2 {
return reporting.Reports{reporting.NewFailure(ctx, "GetAtt has incorrect number of arguments (expected: 2, actual: %d)", len(args))}
}
reports := make(reporting.Reports, 0, 10)
resourceID := args[0]
attributeID := args[1]
if errs := validateGetAttResourceID(builtin, resourceID, ctx); errs != nil {
reports = append(reports, errs...)
} else if errs := validateGetAttAttributeID(builtin, resourceID, attributeID, ctx); errs != nil {
reports = append(reports, errs...)
}
return reporting.Safe(reports)
}
开发者ID:jagregory,项目名称:cfval,代码行数:28,代码来源:if_get_att.go
示例4: validateEquals
func validateEquals(builtin parse.IntrinsicFunction, ctx PropertyContext) reporting.Reports {
if errs := validateIntrinsicFunctionBasicCriteria(parse.FnEquals, builtin, ctx); errs != nil {
return errs
}
value := builtin.UnderlyingMap[string(parse.FnEquals)]
args, ok := value.([]interface{})
if !ok || args == nil {
return reporting.Reports{reporting.NewFailure(ctx, "Invalid type for \"Fn::Equals\" key: %T", value)}
}
if len(args) != 2 {
return reporting.Reports{reporting.NewFailure(ctx, "Incorrect number of arguments (expected: 2, actual: %d)", len(args))}
}
reports := make(reporting.Reports, 0, 10)
left := args[0]
if errs := validateEqualsItem(left, PropertyContextAdd(NewPropertyContext(ctx, Schema{Type: ValueString}), "Value-1")); errs != nil {
reports = append(reports, errs...)
}
right := args[1]
if errs := validateEqualsItem(right, PropertyContextAdd(NewPropertyContext(ctx, Schema{Type: ValueString}), "Value-2")); errs != nil {
reports = append(reports, errs...)
}
return reporting.Safe(reports)
}
开发者ID:jagregory,项目名称:cfval,代码行数:29,代码来源:if_equals.go
示例5: validateAndOr
func validateAndOr(key parse.IntrinsicFunctionSignature, builtin parse.IntrinsicFunction, ctx PropertyContext) reporting.Reports {
value, found := builtin.UnderlyingMap[string(key)]
if !found || value == nil {
return reporting.Reports{reporting.NewFailure(ctx, "Missing \"%s\" key", key)}
}
args, ok := value.([]interface{})
if !ok || args == nil {
return reporting.Reports{reporting.NewFailure(ctx, "Invalid type for \"%s\" key: %T", key, value)}
}
if len(builtin.UnderlyingMap) > 1 {
return reporting.Reports{reporting.NewFailure(ctx, "Unexpected extra keys: %s", keysExcept(builtin.UnderlyingMap, string(key)))}
}
if len(args) < 2 || len(args) > 10 {
return reporting.Reports{reporting.NewFailure(ctx, "Incorrect number of conditions (expected between 2 and 10, actual: %d)", len(args))}
}
reports := make(reporting.Reports, 0, 10)
for i, condition := range args {
if errs := validateAndOrItem(condition, PropertyContextAdd(ctx, strconv.Itoa(i))); errs != nil {
reports = append(reports, errs...)
}
}
return reporting.Safe(reports)
}
开发者ID:jagregory,项目名称:cfval,代码行数:29,代码来源:if_and_or.go
示例6: validateIf
// see: http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-conditions.html#d0e97711
func validateIf(builtin parse.IntrinsicFunction, ctx PropertyContext) reporting.Reports {
if errs := validateIntrinsicFunctionBasicCriteria(parse.FnIf, builtin, ctx); errs != nil {
return errs
}
value := builtin.UnderlyingMap[string(parse.FnIf)]
args, ok := value.([]interface{})
if !ok || args == nil {
return reporting.Reports{reporting.NewFailure(ctx, "Invalid type for \"Fn::If\" key: %T", value)}
}
if len(args) != 3 {
return reporting.Reports{reporting.NewFailure(ctx, "Incorrect number of arguments [condition_name, true_value, false_value]", len(args))}
}
reports := make(reporting.Reports, 0, 10)
conditionName := args[0]
trueValue := args[1]
falseValue := args[2]
if errs := validateIfConditionName(conditionName, PropertyContextAdd(ctx, "ConditionName")); errs != nil {
reports = append(reports, errs...)
}
if errs := validateIfValue(trueValue, PropertyContextAdd(ctx, "TrueValue")); errs != nil {
reports = append(reports, errs...)
}
if errs := validateIfValue(falseValue, PropertyContextAdd(ctx, "FalseValue")); errs != nil {
reports = append(reports, errs...)
}
return reporting.Safe(reports)
}
开发者ID:jagregory,项目名称:cfval,代码行数:36,代码来源:if_if.go
示例7: validateJoin
// see: http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-join.html
func validateJoin(builtin parse.IntrinsicFunction, ctx PropertyContext) reporting.Reports {
if errs := validateIntrinsicFunctionBasicCriteria(parse.FnJoin, builtin, ctx); errs != nil {
return errs
}
value := builtin.UnderlyingMap[string(parse.FnJoin)]
items, ok := value.([]interface{})
if !ok || items == nil {
return reporting.Reports{reporting.NewFailure(ctx, "Invalid \"Fn::Join\" key: %s", items)}
}
if len(items) != 2 {
return reporting.Reports{reporting.NewFailure(ctx, "Join has incorrect number of arguments (expected: 2, actual: %d)", len(items))}
}
reports := make(reporting.Reports, 0, 10)
delimiter := items[0]
values := items[1]
if errs := validateJoinDelimiter(builtin, delimiter, ctx); errs != nil {
reports = append(reports, errs...)
}
if errs := validateJoinList(builtin, values, ctx); errs != nil {
reports = append(reports, errs...)
}
return reporting.Safe(reports)
}
开发者ID:jagregory,项目名称:cfval,代码行数:31,代码来源:if_join.go
示例8: validateIndexNumericalValue
func validateIndexNumericalValue(index float64, array interface{}, ctx PropertyContext) reporting.Reports {
if index < 0 {
return reporting.Reports{reporting.NewFailure(ctx, "Index cannot less than zero")}
} else if arr, ok := array.([]interface{}); ok && int(index) >= len(arr) {
return reporting.Reports{reporting.NewFailure(ctx, "Index cannot greater than array length")}
}
return nil
}
开发者ID:jagregory,项目名称:cfval,代码行数:9,代码来源:if_select.go
示例9: validateIfConditionName
func validateIfConditionName(value interface{}, ctx PropertyContext) reporting.Reports {
if name, ok := value.(string); ok {
if _, found := ctx.Template().Conditions[name]; found {
return nil
}
return reporting.Reports{reporting.NewFailure(ctx, "%s is not defined in the Conditions of the template", name)}
}
return reporting.Reports{reporting.NewFailure(ctx, "Invalid condition %s", value)}
}
开发者ID:jagregory,项目名称:cfval,代码行数:11,代码来源:if_if.go
示例10: validateIntrinsicFunctionBasicCriteria
// validateIntrinsicFunctionBasicCriteria checks the essentials of an intrinsic
// function call:
//
// 1. Does it have a key matching the IF's name
// 2. Does that key have a value
// 3. No unexpected properties alongside the IF key
//
// Validation will fail if any of those criteria don't pass.
func validateIntrinsicFunctionBasicCriteria(key parse.IntrinsicFunctionSignature, builtin parse.IntrinsicFunction, ctx PropertyContext) reporting.Reports {
value, found := builtin.UnderlyingMap[string(key)]
if !found || value == nil {
return reporting.Reports{reporting.NewFailure(ctx, "Missing \"%s\" key", key)}
}
if len(builtin.UnderlyingMap) > 1 {
return reporting.Reports{reporting.NewFailure(ctx, "Unexpected extra keys: %s", keysExcept(builtin.UnderlyingMap, string(key)))}
}
return nil
}
开发者ID:jagregory,项目名称:cfval,代码行数:20,代码来源:if_basics.go
示例11: validateGetAttResourceID
func validateGetAttResourceID(builtin parse.IntrinsicFunction, resourceID interface{}, ctx PropertyContext) reporting.Reports {
switch t := resourceID.(type) {
case string:
if _, found := ctx.Template().Resources[t]; found {
return nil
}
return reporting.Reports{reporting.NewFailure(ctx, "GetAtt %s is not a resource", t)}
}
return reporting.Reports{reporting.NewFailure(ctx, "GetAtt %s is not a valid resource name", resourceID)}
}
开发者ID:jagregory,项目名称:cfval,代码行数:12,代码来源:if_get_att.go
示例12: NewUnrecognisedResource
func NewUnrecognisedResource(awsType string) Resource {
return Resource{
ValidateFunc: func(ctx ResourceContext) (reporting.ValidateResult, reporting.Reports) {
return reporting.ValidateOK, reporting.Reports{reporting.NewFailure(ctx, "Unrecognised resource %s", awsType)}
},
}
}
开发者ID:jagregory,项目名称:cfval,代码行数:7,代码来源:resource.go
示例13: validateJoinDelimiter
func validateJoinDelimiter(builtin parse.IntrinsicFunction, delimiter interface{}, ctx PropertyContext) reporting.Reports {
if _, ok := delimiter.(string); !ok {
return reporting.Reports{reporting.NewFailure(ctx, "\"%s\" is not a valid delimiter", delimiter)}
}
return nil
}
开发者ID:jagregory,项目名称:cfval,代码行数:7,代码来源:if_join.go
示例14: validateJoinList
func validateJoinList(builtin parse.IntrinsicFunction, values interface{}, ctx PropertyContext) reporting.Reports {
valuesCtx := PropertyContextAdd(ctx, "Values")
switch parts := values.(type) {
case []interface{}:
reports := make(reporting.Reports, 0, 10)
valueType := Schema{Type: ValueString}
for i, part := range parts {
if errs := validateJoinListValue(part, PropertyContextAdd(NewPropertyContext(valuesCtx, valueType), strconv.Itoa(i))); errs != nil {
reports = append(reports, errs...)
}
}
return reporting.Safe(reports)
case parse.IntrinsicFunction:
listType := Schema{Type: Multiple(ValueString)}
_, errs := ValidateIntrinsicFunctions(parts, NewPropertyContext(valuesCtx, listType), SupportedFunctions{
parse.FnBase64: true,
parse.FnFindInMap: true,
parse.FnGetAtt: true,
parse.FnGetAZs: true,
parse.FnIf: true,
parse.FnJoin: true,
parse.FnSelect: true,
parse.FnRef: true,
})
return errs
}
return reporting.Reports{reporting.NewFailure(ctx, "Join items are not valid: %s", values)}
}
开发者ID:jagregory,项目名称:cfval,代码行数:31,代码来源:if_join.go
示例15: Validate
func (p Properties) Validate(ctx ResourceContext) reporting.Reports {
failures := make(reporting.Reports, 0, len(p)*2)
visited := make(map[string]bool)
self := ctx.CurrentResource()
for key, schema := range p {
visited[key] = true
value, _ := self.PropertyValue(key)
keyCtx := ResourceContextAdd(ctx, key)
// Validate conflicting properties
if value != nil && schema.Conflicts != nil && schema.Conflicts.Pass(self) {
failures = append(failures, reporting.NewFailure(keyCtx, "Conflict: %s", schema.Conflicts.Describe(self)))
}
// Validate Required
if value == nil && schema.Required != nil && schema.Required.Pass(self) {
failures = append(failures, reporting.NewFailure(keyCtx, "%s is required because %s", key, schema.Required.Describe(self)))
}
// Validate Deprecated
if value != nil && schema.Deprecated != nil {
failures = append(failures, reporting.NewWarning(keyCtx, schema.Deprecated.Describe()))
continue
}
// assuming the above either failed and logged some failures, or passed and
// we can safely skip over a nil property
if value == nil {
continue
}
if _, errs := schema.Validate(value, keyCtx); errs != nil {
failures = append(failures, errs...)
}
}
// Reject any properties we weren't expecting
for _, key := range self.Properties() {
if !visited[key] {
failures = append(failures, reporting.NewFailure(ResourceContextAdd(ctx, key), "%s is not a property of %s", key, self.AwsType()))
}
}
return reporting.Safe(failures)
}
开发者ID:jagregory,项目名称:cfval,代码行数:47,代码来源:properties.go
示例16: validateCondition
// validateCondition validates the inline { "Condition": "X" } structure. It
// isn't technically a condition itself, acting more like a Ref.
func validateCondition(builtin parse.IntrinsicFunction, ctx PropertyContext) reporting.Reports {
if errs := validateIntrinsicFunctionBasicCriteria(parse.FnCondition, builtin, ctx); errs != nil {
return errs
}
value := builtin.UnderlyingMap[string(parse.FnCondition)]
condition, ok := value.(string)
if !ok || condition == "" {
return reporting.Reports{reporting.NewFailure(ctx, `Invalid type for "Condition" key: %T`, value)}
}
if _, found := ctx.Template().Conditions[condition]; !found {
return reporting.Reports{reporting.NewFailure(ctx, "%s is not defined in the Conditions of the template", condition)}
}
return nil
}
开发者ID:jagregory,项目名称:cfval,代码行数:19,代码来源:if_condition.go
示例17: SingleValueValidate
func SingleValueValidate(expected interface{}) ValidateFunc {
return func(value interface{}, ctx PropertyContext) (reporting.ValidateResult, reporting.Reports) {
if value != expected {
return reporting.ValidateOK, reporting.Reports{reporting.NewFailure(ctx, "Value must be %d but is %d", expected, value)}
}
return reporting.ValidateOK, nil
}
}
开发者ID:jagregory,项目名称:cfval,代码行数:9,代码来源:validations.go
示例18: automaticFailoverEnabledValidation
func automaticFailoverEnabledValidation(value interface{}, ctx PropertyContext) (reporting.ValidateResult, reporting.Reports) {
if version, found := ctx.CurrentResource().PropertyValueOrDefault("EngineVersion"); found {
if versionNumber, err := strconv.ParseFloat(version.(string), 64); err == nil {
if versionNumber < 2.8 {
return reporting.ValidateOK, reporting.Reports{reporting.NewFailure(ctx, "EngineVersion must be 2.8 or higher for Automatic Failover")}
}
}
}
if nodeType, found := ctx.CurrentResource().PropertyValueOrDefault("CacheNodeType"); found {
split := strings.Split(nodeType.(string), ".")
if split[1] == "t1" || split[1] == "t2" {
return reporting.ValidateOK, reporting.Reports{reporting.NewFailure(ctx, "CacheNodeType must not be T1 or T2 Automatic Failover")}
}
}
return reporting.ValidateOK, nil
}
开发者ID:jagregory,项目名称:cfval,代码行数:18,代码来源:replication_group.go
示例19: validateFindInMapMapName
func validateFindInMapMapName(builtin parse.IntrinsicFunction, mapName interface{}, ctx PropertyContext) reporting.Reports {
if mapName == nil {
return reporting.Reports{reporting.NewFailure(ctx, "Cannot be null")}
}
switch t := mapName.(type) {
case string:
// TODO: validate actual map exists
return nil
case parse.IntrinsicFunction:
_, errs := ValidateIntrinsicFunctions(t, ctx, SupportedFunctions{
parse.FnFindInMap: true,
parse.FnRef: true,
})
return errs
}
return reporting.Reports{reporting.NewFailure(ctx, "Invalid MapName: %v", mapName)}
}
开发者ID:jagregory,项目名称:cfval,代码行数:19,代码来源:if_find_in_map.go
示例20: NumberOptions
func NumberOptions(numbers ...float64) ValidateFunc {
return func(value interface{}, ctx PropertyContext) (reporting.ValidateResult, reporting.Reports) {
for _, n := range numbers {
if n == value.(float64) {
return reporting.ValidateOK, nil
}
}
return reporting.ValidateOK, reporting.Reports{reporting.NewFailure(ctx, "Number must be one of %v", numbers)}
}
}
开发者ID:jagregory,项目名称:cfval,代码行数:10,代码来源:validations.go
注:本文中的github.com/jagregory/cfval/reporting.NewFailure函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论