-
Notifications
You must be signed in to change notification settings - Fork 20
/
relationship-template.go
88 lines (71 loc) · 2.69 KB
/
relationship-template.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
package tosca_v2_0
import (
"github.com/tliron/puccini/tosca"
"github.com/tliron/puccini/tosca/normal"
)
//
// RelationshipTemplate
//
// [TOSCA-v2.0] @ ?
// [TOSCA-Simple-Profile-YAML-v1.3] @ 3.8.4
// [TOSCA-Simple-Profile-YAML-v1.2] @ 3.8.4
// [TOSCA-Simple-Profile-YAML-v1.1] @ 3.7.4
// [TOSCA-Simple-Profile-YAML-v1.0] @ 3.7.4
//
type RelationshipTemplate struct {
*Entity `name:"relationship template"`
Name string `namespace:""`
CopyRelationshipTemplateName *string `read:"copy"`
RelationshipTypeName *string `read:"type" require:""`
Metadata Metadata `read:"metadata,Metadata"` // introduced in TOSCA 1.1
Description *string `read:"description"`
Properties Values `read:"properties,Value"`
Attributes Values `read:"attributes,AttributeValue"`
Interfaces InterfaceAssignments `read:"interfaces,InterfaceAssignment"`
CopyRelationshipTemplate *RelationshipTemplate `lookup:"copy,CopyRelationshipTemplateName" json:"-" yaml:"-"`
RelationshipType *RelationshipType `lookup:"type,RelationshipTypeName" json:"-" yaml:"-"`
rendered bool
}
func NewRelationshipTemplate(context *tosca.Context) *RelationshipTemplate {
return &RelationshipTemplate{
Entity: NewEntity(context),
Properties: make(Values),
Attributes: make(Values),
Name: context.Name,
Interfaces: make(InterfaceAssignments),
}
}
// tosca.Reader signature
func ReadRelationshipTemplate(context *tosca.Context) tosca.EntityPtr {
self := NewRelationshipTemplate(context)
context.ValidateUnsupportedFields(context.ReadFields(self))
return self
}
// tosca.PreReadable interface
func (self *RelationshipTemplate) PreRead() {
CopyTemplate(self.Context)
}
// parser.Renderable interface
func (self *RelationshipTemplate) Render() {
logRender.Debugf("relationship template: %s", self.Name)
if self.rendered {
// Avoid rendering more than once (can happen if we were called from RelationshipAssignment.Render)
return
}
self.rendered = true
if self.RelationshipType == nil {
return
}
self.Properties.RenderProperties(self.RelationshipType.PropertyDefinitions, "property", self.Context.FieldChild("properties", nil))
self.Attributes.RenderAttributes(self.RelationshipType.AttributeDefinitions, self.Context.FieldChild("attributes", nil))
}
func (self *RelationshipTemplate) Normalize(normalRelationship *normal.Relationship) {
normalRelationship.Metadata = self.Metadata
if self.Description != nil {
normalRelationship.Description = *self.Description
}
}
//
// RelationshipTemplates
//
type RelationshipTemplates []*RelationshipTemplate