本文整理汇总了Golang中github.com/jagregory/cfval/reporting.NewFailure函数的典型用法代码示例。如果您正苦于以下问题:Golang NewFailure函数的具体用法?Golang NewFailure怎么用?Golang NewFailure使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewFailure函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)}
}
示例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)}
}
示例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)
}
示例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)
}
示例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)
}
示例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)
}
示例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)
}
示例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
}
示例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)}
}
示例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
}
示例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)}
}
示例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)}
},
}
}
示例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
}
示例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)}
}
示例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)
}