-
Notifications
You must be signed in to change notification settings - Fork 23
/
capabilities.go
72 lines (66 loc) · 3.23 KB
/
capabilities.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
// 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
const (
// EndpointCapability is the default TOSCA type that should be used or
// extended to define a network endpoint capability.
EndpointCapability = "tosca.capabilities.Endpoint"
// PublicEndpointCapability represents a public endpoint.
PublicEndpointCapability = "tosca.capabilities.Endpoint.Public"
)
// An CapabilityDefinition is the representation of a TOSCA Capability Definition
//
// See http://docs.oasis-open.org/tosca/TOSCA-Simple-Profile-YAML/v1.2/TOSCA-Simple-Profile-YAML-v1.2.html#DEFN_ELEMENT_CAPABILITY_DEFN for more details
// NOTE: Here is Alien specific difference with Tosca Specification about Properties/Attributes maps of ValueAssignment instead of maps of PropertyDefinition in Tosca spec
type CapabilityDefinition struct {
Type string `yaml:"type"`
Description string `yaml:"description,omitempty"`
Properties map[string]*ValueAssignment `yaml:"properties,omitempty"`
Attributes map[string]*ValueAssignment `yaml:"attributes,omitempty"`
ValidSourceTypes []string `yaml:"valid_source_types,omitempty,flow"`
Occurrences Range `yaml:"occurrences,omitempty"`
}
// An CapabilityAssignment is the representation of a TOSCA Capability Assignment
//
// See http://docs.oasis-open.org/tosca/TOSCA-Simple-Profile-YAML/v1.0/TOSCA-Simple-Profile-YAML-v1.0.html#DEFN_ELEMENT_CAPABILITY_ASSIGNMENT for more details
type CapabilityAssignment struct {
Properties map[string]*ValueAssignment `yaml:"properties,omitempty"`
Attributes map[string]*ValueAssignment `yaml:"attributes,omitempty"`
}
// UnmarshalYAML unmarshals a yaml into an CapabilityDefinition
func (c *CapabilityDefinition) UnmarshalYAML(unmarshal func(interface{}) error) error {
var s string
if err := unmarshal(&s); err == nil {
c.Type = s
return nil
}
var str struct {
Type string `yaml:"type"`
Description string `yaml:"description,omitempty"`
Properties map[string]*ValueAssignment `yaml:"properties,omitempty"`
Attributes map[string]*ValueAssignment `yaml:"attributes,omitempty"`
ValidSourceTypes []string `yaml:"valid_source_types,omitempty,flow"`
Occurrences Range `yaml:"occurrences,omitempty"`
}
if err := unmarshal(&str); err != nil {
return err
}
c.Type = str.Type
c.Description = str.Description
c.Properties = str.Properties
c.Attributes = str.Attributes
c.ValidSourceTypes = str.ValidSourceTypes
c.Occurrences = str.Occurrences
return nil
}