-
Notifications
You must be signed in to change notification settings - Fork 23
/
types.go
110 lines (101 loc) · 4.64 KB
/
types.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
106
107
108
109
110
// Copyright 2018 Bull S.A.S. Atos Technologies - Bull, Rue Jean Jaures, B.P.68, 78340, Les Clayes-sous-Bois, France.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package tosca
import (
"strings"
)
// IsBuiltinType checks if a given type name corresponds to a TOSCA builtin type.
//
// Known builtin types:
// - string
// - integer
// - float
// - boolean
// - timestamp
// - null
// - list
// - map
// - version
// - range
// - scalar-unit.size
// - scalar-unit.time
func IsBuiltinType(typeName string) bool {
// type representation for map and list could be map:<EntrySchema> or list:<EntrySchema> (ex: list:integer)
return strings.HasPrefix(typeName, "list") || strings.HasPrefix(typeName, "map") ||
typeName == "string" || typeName == "integer" || typeName == "float" || typeName == "boolean" ||
typeName == "timestamp" || typeName == "null" || typeName == "version" || typeName == "range" ||
typeName == "scalar-unit.size" || typeName == "scalar-unit.time"
}
// Type is the base type for all TOSCA types (like node types, relationship types, ...)
type Type struct {
DerivedFrom string `yaml:"derived_from,omitempty"`
Version string `yaml:"version,omitempty"`
Description string `yaml:"description,omitempty"`
Metadata map[string]string `yaml:"metadata,omitempty"`
}
// An NodeType is the representation of a TOSCA Node Type
//
// See http://docs.oasis-open.org/tosca/TOSCA-Simple-Profile-YAML/v1.2/TOSCA-Simple-Profile-YAML-v1.2.html#DEFN_ENTITY_NODE_TYPE
// for more details
type NodeType struct {
Type `yaml:",inline"`
Properties map[string]PropertyDefinition `yaml:"properties,omitempty"`
Attributes map[string]AttributeDefinition `yaml:"attributes,omitempty"`
Requirements []RequirementDefinitionMap `yaml:"requirements,omitempty,flow"`
Capabilities map[string]CapabilityDefinition `yaml:"capabilities,omitempty"`
Interfaces map[string]InterfaceDefinition `yaml:"interfaces,omitempty"`
Artifacts ArtifactDefMap `yaml:"artifacts,omitempty"`
}
// An RelationshipType is the representation of a TOSCA Relationship Type
//
// See http://docs.oasis-open.org/tosca/TOSCA-Simple-Profile-YAML/v1.2/TOSCA-Simple-Profile-YAML-v1.2.html#DEFN_ENTITY_RELATIONSHIP_TYPE
// for more details
type RelationshipType struct {
Type `yaml:",inline"`
Properties map[string]PropertyDefinition `yaml:"properties,omitempty"`
Attributes map[string]AttributeDefinition `yaml:"attributes,omitempty"`
Interfaces map[string]InterfaceDefinition `yaml:"interfaces,omitempty"`
Artifacts ArtifactDefMap `yaml:"artifacts,omitempty"`
ValidTargetTypes []string `yaml:"valid_target_types,omitempty"`
}
// An CapabilityType is the representation of a TOSCA Capability Type
//
// See http://docs.oasis-open.org/tosca/TOSCA-Simple-Profile-YAML/v1.2/TOSCA-Simple-Profile-YAML-v1.2.html#DEFN_ENTITY_CAPABILITY_TYPE
// for more details
type CapabilityType struct {
Type `yaml:",inline"`
Properties map[string]PropertyDefinition `yaml:"properties,omitempty"`
Attributes map[string]AttributeDefinition `yaml:"attributes,omitempty"`
ValidSourceTypes []string `yaml:"valid_source_types,omitempty,flow"`
}
// An ArtifactType is the representation of a TOSCA Artifact Type
//
// See http://docs.oasis-open.org/tosca/TOSCA-Simple-Profile-YAML/v1.2/TOSCA-Simple-Profile-YAML-v1.2.html#DEFN_ENTITY_ARTIFACT_TYPE
// for more details
type ArtifactType struct {
Type `yaml:",inline"`
MimeType string `yaml:"mime_type,omitempty"`
FileExt []string `yaml:"file_ext,omitempty"`
Properties map[string]PropertyDefinition `yaml:"properties,omitempty"`
}
// An DataType is the representation of a TOSCA Data Type
//
// See http://docs.oasis-open.org/tosca/TOSCA-Simple-Profile-YAML/v1.2/TOSCA-Simple-Profile-YAML-v1.2.html#DEFN_ENTITY_DATA_TYPE
// for more details
type DataType struct {
Type `yaml:",inline"`
Properties map[string]PropertyDefinition `yaml:"properties,omitempty"`
// Constraints not enforced in Yorc so we don't parse them
// Constraints []ConstraintClause
}