1 # Licensed under the Apache License, Version 2.0 (the "License"); you may
2 # not use this file except in compliance with the License. You may obtain
3 # a copy of the License at
5 # http://www.apache.org/licenses/LICENSE-2.0
7 # Unless required by applicable law or agreed to in writing, software
8 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10 # License for the specific language governing permissions and limitations
13 from toscaparser.dataentity import DataEntity
14 from toscaparser.elements.constraints import Schema
15 from toscaparser.functions import is_function
18 class Property(object):
19 '''TOSCA built-in Property type.'''
22 TYPE, REQUIRED, DESCRIPTION, DEFAULT, CONSTRAINTS
24 'type', 'required', 'description', 'default', 'constraints'
28 ENTRYTYPE, ENTRYPROPERTIES
33 def __init__(self, property_name, value, schema_dict, custom_def=None):
34 self.name = property_name
36 self.custom_def = custom_def
37 self.schema = Schema(property_name, schema_dict)
41 return self.schema.type
45 return self.schema.required
48 def description(self):
49 return self.schema.description
53 return self.schema.default
56 def constraints(self):
57 return self.schema.constraints
60 def entry_schema(self):
61 return self.schema.entry_schema
64 '''Validate if not a reference property.'''
65 if not is_function(self.value):
66 if self.type == Schema.STRING:
67 self.value = str(self.value)
68 self.value = DataEntity.validate_datatype(self.type, self.value,
71 self._validate_constraints()
73 def _validate_constraints(self):
75 for constraint in self.constraints:
76 constraint.validate(self.value)