Skip to content

Commit

Permalink
Project: Code Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
kenjones-cisco committed Oct 24, 2016
1 parent 4d1bde3 commit 99c1f08
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 19 deletions.
34 changes: 15 additions & 19 deletions assignment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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))
Expand All @@ -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))
Expand Down
1 change: 1 addition & 0 deletions policies.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 99c1f08

Please sign in to comment.