-
Notifications
You must be signed in to change notification settings - Fork 20
/
property-mapping.go
105 lines (86 loc) · 2.64 KB
/
property-mapping.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package tosca_v2_0
import (
"reflect"
"github.com/tliron/puccini/tosca"
)
//
// PropertyMapping
//
// Attaches to SubstitutionMappings
//
// [TOSCA-v2.0] @ ?
// [TOSCA-Simple-Profile-YAML-v1.3] @ 3.8.8
// [TOSCA-Simple-Profile-YAML-v1.2] @ 3.8.8
//
type PropertyMapping struct {
*Entity `name:"property mapping"`
Name string
InputName *string
NodeTemplateName *string // deprecated in TOSCA 1.3
PropertyName *string // deprecated in TOSCA 1.3
InputDefinition *ParameterDefinition `traverse:"ignore" json:"-" yaml:"-"`
NodeTemplate *NodeTemplate `traverse:"ignore" json:"-" yaml:"-"`
Property *Value `traverse:"ignore" json:"-" yaml:"-"`
}
func NewPropertyMapping(context *tosca.Context) *PropertyMapping {
return &PropertyMapping{
Entity: NewEntity(context),
Name: context.Name,
}
}
// tosca.Reader signature
func ReadPropertyMapping(context *tosca.Context) tosca.EntityPtr {
self := NewPropertyMapping(context)
if strings := context.ReadStringList(); strings != nil {
switch len(*strings) {
case 1:
self.InputName = &(*strings)[0]
case 2:
// Deprecated in TOSCA 1.3
self.NodeTemplateName = &(*strings)[0]
self.PropertyName = &(*strings)[1]
default:
self.Context.ReportValueMalformed("property mapping", "must be list of 1 or 2 strings")
}
}
return self
}
// tosca.Mappable interface
func (self *PropertyMapping) GetKey() string {
return self.Name
}
func (self *PropertyMapping) Render(inputDefinitions ParameterDefinitions) {
logRender.Debug("property mapping")
if self.InputName != nil {
inputName := *self.InputName
var ok bool
if self.InputDefinition, ok = inputDefinitions[inputName]; !ok {
self.Context.ListChild(0, inputName).ReportUnknown("input")
}
} else if (self.NodeTemplateName != nil) && (self.PropertyName != nil) {
// Deprecated in TOSCA 1.3
nodeTemplateName := *self.NodeTemplateName
var nodeTemplateType *NodeTemplate
if nodeTemplate, ok := self.Context.Namespace.LookupForType(nodeTemplateName, reflect.TypeOf(nodeTemplateType)); ok {
self.NodeTemplate = nodeTemplate.(*NodeTemplate)
self.NodeTemplate.Render()
} else {
self.Context.ListChild(0, nodeTemplateName).ReportUnknown("node template")
return
}
name := *self.PropertyName
var ok bool
if self.Property, ok = self.NodeTemplate.Properties[name]; !ok {
self.Context.ListChild(1, name).ReportReferenceNotFound("property", self.NodeTemplate)
}
}
}
//
// PropertyMappings
//
type PropertyMappings map[string]*PropertyMapping
func (self PropertyMappings) Render(inputDefinitions ParameterDefinitions) {
for _, mapping := range self {
mapping.Render(inputDefinitions)
}
}