From 99c1f0809f54702c9c71bea4947af3e5edbcede2 Mon Sep 17 00:00:00 2001 From: kenjones Date: Mon, 24 Oct 2016 15:01:08 -0400 Subject: [PATCH] Project: Code Cleanup --- assignment.go | 34 +++++++++++++++------------------- policies.go | 1 + 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/assignment.go b/assignment.go index 92ad059..8cadba7 100644 --- a/assignment.go +++ b/assignment.go @@ -161,9 +161,7 @@ func (p *Assignment) Evaluate(std *ServiceTemplateDefinition, ctx string) interf var output string for _, val := range p.Args { switch reflect.TypeOf(val).Kind() { - case reflect.String: - output = fmt.Sprintf("%s%s", output, val) - case reflect.Int: + case reflect.String, reflect.Int: output = fmt.Sprintf("%s%s", output, val) case reflect.Map: if pa := newAssignmentFunc(val); pa != nil { @@ -181,18 +179,17 @@ func (p *Assignment) Evaluate(std *ServiceTemplateDefinition, ctx string) interf } case GetPropFunc: + nt, rnt := getNTByArgs(std, ctx, p.Args) + if nt == nil { + break + } + if len(p.Args) == 2 { - if nt := std.findNodeTemplate(p.Args[0].(string), ctx); nt != nil { - if pa, ok := nt.Properties[p.Args[1].(string)]; ok { - return pa.Evaluate(std, nt.Name) - } + if prop := nt.findProperty(p.Args[1].(string), ""); prop != nil { + return prop.evaluate(std, nt.Name, "") } } if len(p.Args) >= 3 { - nt, rnt := getNTByArgs(std, ctx, p.Args) - if nt == nil { - break - } if rnt != nil { if prop := rnt.findProperty(p.Args[2].(string), p.Args[1].(string)); prop != nil { return prop.evaluate(std, rnt.Name, get(3, p.Args)) @@ -207,18 +204,17 @@ func (p *Assignment) Evaluate(std *ServiceTemplateDefinition, ctx string) interf } case GetAttrFunc: + nt, rnt := getNTByArgs(std, ctx, p.Args) + if nt == nil { + break + } + if len(p.Args) == 2 { - if nt := std.findNodeTemplate(p.Args[0].(string), ctx); nt != nil { - if pa, ok := nt.Attributes[p.Args[1].(string)]; ok { - return pa.Evaluate(std, nt.Name) - } + if attr := nt.findAttribute(p.Args[1].(string), ""); attr != nil { + return attr.evaluate(std, nt.Name, "") } } if len(p.Args) >= 3 { - nt, rnt := getNTByArgs(std, ctx, p.Args) - if nt == nil { - break - } if rnt != nil { if attr := rnt.findAttribute(p.Args[2].(string), p.Args[1].(string)); attr != nil { return attr.evaluate(std, rnt.Name, get(3, p.Args)) diff --git a/policies.go b/policies.go index 9b167e8..4a757f1 100644 --- a/policies.go +++ b/policies.go @@ -71,6 +71,7 @@ type PolicyDefinition struct { Triggers map[string]TriggerDefinition `yaml:"triggers" json:"triggers"` } +// IsValidTarget checks if a specified target is valid for the Policy func (pd *PolicyDefinition) IsValidTarget(name string) bool { if len(pd.Targets) == 0 { return true