class documentation

class Validator:

View In Hierarchy

Validator class.

Method addAttributePolicy Add a new attribute policy for normal resources.
Method addFlexContainerAttributePolicy Add a single new policy dictionary for a type's attributes.
Method addFlexContainerSpecialization Add flexContainer specialization information to the internal dictionary.
Method clearAttributePolicies Clear the attribute policies.
Method clearFlexContainerAttributes Clear the flexContainer attributes.
Method clearFlexContainerSpecializations Clear the flexContainer specialization information.
Method convertIdentifierAttributeToScope Convert an attribute to the Absolute or SP-relative form if it is an identifier. This is a recursive function that is called for each attribute of a complex attribute (e.g. a list or a complex attribute).
Method convertIDsToScope Convert identifier attributes to the specified scope.
Method getAllAttributePolicies Return all attribute policies.
Method getAttributePoliciesByName Return the attribute policies for an attribute name.
Method getAttributePolicy Return the attributePolicy for a resource type.
Method getAttributeValueName Return the name of an attribute value. This is usually used for enumerations, where the value is a number and the name is a string.
Method getAttributeValueRepresentation Return the representation of an attribute value. This is usually used for the representation of an attribute where the value is not known yet.
Method getComplexTypeAttributePolicies Return the attribute policies for a complex type.
Method getEnumInterpretation Return the interpretation of an enumeration.
Method getFlexContainerAttributesFor Return the attribute policies for a flexContainer specialization.
Method getFlexContainerSpecialization Return the availale data for a flexContainer specialization.
Method getShortnameLongNameMapping Return the shortname to longname mappings.
Method hasFlexContainerContainerDefinition Test whether a flexContainer specialization with a containerDefinition exists.
Method initialize Initialize the validator.
Method isExtraResourceAttribute Check whether the resource attribute attr is neither a universal, common, or resource attribute, nor an internal attribute.
Method shutdown Shutdown the validator.
Method updateFlexContainerAttributes Add or update new specialization attribute definitions to the validator. The dict has a single entry (the type) that contains another dict of attribute policies for that type.
Method validateAttribute Validate a single attribute.
Method validateAttributes Validate a resources' attributes for types etc.
Method validateCNF Validate the contents of the contentInfo attribute.
Method validateCSICB Validate the format of a CSE-ID in csi or cb attributes.
Method validateGeoLinePolygon Validate a GeoJSON line or polygon. A line or polygon is a list of lists of two or three floats.
Method validateGeoLocation Validate a GeoJSON location. A location is a dictionary with a type and coordinates.
Method validateGeoMultiLinePolygon Validate a GeoJSON multi line or polygon. A line or polygon is a list of list of lists of two or three floats.
Method validateGeoPoint Validate a GeoJSON point. A point is a list of two or three floats.
Method validatePrimitiveContent Validate the primitive content.
Method validatePvs Validating special case for lists that are not allowed to be empty (pvs in ACP).
Method validateResourceUpdate Validate a resource update dictionary. Besides of the attributes it also validates the resource type.
Class Variable cnfRegex Compiled regular expression that matches a valid contentInfo string.
Class Variable importer Injected Importer instance.
Method _validateType Check a value for its type.
Class Variable _ncNameDisallowedChars Disallowed characters in NCName.
Class Variable _scheduleRegex "second minute hour day month weekday year"
Class Variable _tokenDisallowedChars Disallowed characters in token.
def addAttributePolicy(self, rtype: ResourceTypes | str, attr: str, attrPolicy: AttributePolicy):

Add a new attribute policy for normal resources.

def addFlexContainerAttributePolicy(self, policy: AttributePolicy) -> bool:

Add a single new policy dictionary for a type's attributes.

This is done by either creating a new entry, or adding the new policy to the existing policies and then updating the old entry in the global dictionary.

Parameters
policy:AttributePolicyAttributePolicy dictionary with a single attribute policy.
Returns
boolBoolean, indicating whether a policy was added successfully.
def addFlexContainerSpecialization(self, typeShortname: str, cnd: str, lname: str) -> bool:

Add flexContainer specialization information to the internal dictionary.

Parameters
typeShortname:strString, domain and short name of the flexContainer specialization.
cnd:strString, the containerDefinition of the flexContainer specialization.
lname:strString, the long name of the flexContainer specialization.
Returns
boolBoolean, indicating whether a specialization was added successfully.
def clearAttributePolicies(self):

Clear the attribute policies.

def clearFlexContainerAttributes(self):

Clear the flexContainer attributes.

def clearFlexContainerSpecializations(self):

Clear the flexContainer specialization information.

def convertIdentifierAttributeToScope(self, value: Any, typ: BasicType, policy: AttributePolicy, scope: IdentifierScope | None = IdentifierScope.SPRelative) -> Any:

Convert an attribute to the Absolute or SP-relative form if it is an identifier. This is a recursive function that is called for each attribute of a complex attribute (e.g. a list or a complex attribute).

Parameters
value:AnyThe value to convert.
typ:BasicTypeThe type of the value.
policy:AttributePolicyThe attribute policy of the value.
scope:IdentifierScope | NoneThe scope of the conversion
Returns
AnyThe converted value.
def convertIDsToScope(self, k: str, v: JSON, typ: ResourceTypes, scope: IdentifierScope) -> Any:

Convert identifier attributes to the specified scope.

This method is called recursively for each attribute of a complex attribute (e.g. a list or a complex attribute).

Parameters
k:strAttribute name.
v:JSONAttribute value.
typ:ResourceTypesResource type of the attribute.
scope:IdentifierScopeScope to convert to.
Returns
AnyThe converted value.
def getAllAttributePolicies(self) -> ResourceAttributePolicyDict:

Return all attribute policies.

Returns
ResourceAttributePolicyDictDictionary with all attribute policies.
def getAttributePoliciesByName(self, attr: str) -> list[AttributePolicy] | None:

Return the attribute policies for an attribute name.

Parameters
attr:strAttribute name.
Returns
list[AttributePolicy] | NoneList of AttributePolicy or None.
def getAttributePolicy(self, rtype: ResourceTypes | str, attr: str, specific: bool = False) -> AttributePolicy:

Return the attributePolicy for a resource type.

Parameters
rtype:ResourceTypes | strResource type to check first.
attr:strAttribute name.
specific:boolBoolean, indicating whether to search for a specific type.
Returns
AttributePolicyAttributePolicy or None.
def getAttributeValueName(self, attr: str, value: int, rtype: ResourceTypes | None = None) -> str:

Return the name of an attribute value. This is usually used for enumerations, where the value is a number and the name is a string.

This method is mainly used for the interpretation of enumeration values in the UIs.

Parameters
attr:strAttribute name.
value:intAttribute value.
rtype:ResourceTypes | NoneUndocumented
Returns
strString, name of the attribute value.
def getAttributeValueRepresentation(self, attr: str, resourceType: ResourceTypes, withComments: bool | None = True) -> str:

Return the representation of an attribute value. This is usually used for the representation of an attribute where the value is not known yet.

Parameters
attr:strAttribute name.
resourceType:ResourceTypesType of the attribute's resource.
withComments:bool | NoneBoolean, indicating whether to include comments in the representation.
Returns
strString, representation of the attribute value. This might be a JSON representation of the value.
def getComplexTypeAttributePolicies(self, ctype: str) -> list[AttributePolicy] | None:

Return the attribute policies for a complex type.

Parameters
ctype:strComplex type name.
Returns
list[AttributePolicy] | NoneList of AttributePolicy or None.
def getEnumInterpretation(self, rtype: ResourceTypes, attr: str, value: int) -> str:

Return the interpretation of an enumeration.

Parameters
rtype:ResourceTypesResource type. May be None.
attr:strAttribute name.
value:intEnumeration value.
Returns
strString, interpretation of the enumeration, or the value itself if no interpretation is available.
def getFlexContainerAttributesFor(self, typeShortname: str) -> AttributePolicyDict:

Return the attribute policies for a flexContainer specialization.

Parameters
typeShortname:strString, domain and short name of the flexContainer specialization.
Returns
AttributePolicyDictDictictionary of additional attributes for a flexCOntainer type or None.
def getFlexContainerSpecialization(self, typeShortname: str) -> tuple[str, str]:

Return the availale data for a flexContainer specialization.

Parameters
typeShortname:strString, domain and short name of the flexContainer specialization.
Returns
tuple[str, str]Tuple with the flexContainer specialization data (or None if none exists). The tuple contains the containerDefinition and the long name.
def getShortnameLongNameMapping(self) -> dict[str, str]:

Return the shortname to longname mappings.

Returns
dict[str, str]Dictionary with the shortname to longname mappings.
def hasFlexContainerContainerDefinition(self, cnd: str) -> bool:

Test whether a flexContainer specialization with a containerDefinition exists.

Parameters
cnd:strString, containerDefinition
Returns
boolBoolean, indicating existens.
def initialize(self):

Initialize the validator.

def isExtraResourceAttribute(self, attr: str, resource: Resource) -> bool:

Check whether the resource attribute attr is neither a universal, common, or resource attribute, nor an internal attribute.

Parameters
attr:strShort name of the attribute to check.
resource:ResourceThe Resource to check.
Returns
boolhis method returns True when the attribute is a custom attribute.
def shutdown(self) -> bool:

Shutdown the validator.

Returns
boolAlways True.
def updateFlexContainerAttributes(self, additionalPolicies: FlexContainerAttributes) -> bool:

Add or update new specialization attribute definitions to the validator. The dict has a single entry (the type) that contains another dict of attribute policies for that type.

def validateAttribute(self, attribute: str, value: Any, attributeType: BasicType | None = None, rtype: ResourceTypes | None = ResourceTypes.ALL) -> tuple[BasicType, Any]:

Validate a single attribute.

Parameters
attribute:strName of the attribute to perform the check.
value:AnyValue to validate for the attribute.
attributeType:BasicType | NoneIf attributeType is set then that type is taken to perform the check, otherwise the attribute type is determined.
rtype:ResourceTypes | NoneSome attributes' validations depend on the resource type.
Returns
tuple[BasicType, Any]A tuple with determined data type and the converted value.
Raises
BAD_REQUESTIf the validation fails.
def validateAttributes(self, resource: JSON, typeShortname: str, ty: ResourceTypes | None = ResourceTypes.UNKNOWN, attributes: AttributePolicyDict | None = None, create: bool | None = True, createdInternally: bool | None = False, isAnnounced: bool | None = False):

Validate a resources' attributes for types etc.

Parameters
resource:JSONdictionary to check
typeShortname:strThe resource's resource type name
ty:ResourceTypes | NoneThe resource type
attributes:AttributePolicyDict | NoneThe attribute policy dictionary for the resource type. If this is None then validate automatically
create:bool | NoneBoolean indicating whether this a CREATE request
createdInternally:bool | NoneBoolean indicating that a resource is created internally
isAnnounced:bool | NoneBoolean indicating that a resource is announced
Returns
Result object
def validateCNF(self, value: str):

Validate the contents of the contentInfo attribute.

Parameters
value:strThe value to validate.
def validateCSICB(self, val: str, name: str):

Validate the format of a CSE-ID in csi or cb attributes.

Parameters
val:strThe value to validate.
name:strThe name of the attribute.
def validateGeoLinePolygon(self, geo: dict, isPolygon: bool | None = False) -> bool:

Validate a GeoJSON line or polygon. A line or polygon is a list of lists of two or three floats.

Parameters
geo:dictGeoJSON string line or polygon.
isPolygon:bool | NoneBoolean, indicating whether the coordinates describe a polygon.
Returns
boolBoolean, indicating whether the line or polygon is valid.
def validateGeoLocation(self, loc: dict) -> dict:

Validate a GeoJSON location. A location is a dictionary with a type and coordinates.

Parameters
loc:dictGeoJSON location.
Returns
dictThe validated location dictionary.
Raises
BAD_REQUESTIf the location definition is invalid.
def validateGeoMultiLinePolygon(self, geo: dict, isPolygon: bool | None = False) -> bool:

Validate a GeoJSON multi line or polygon. A line or polygon is a list of list of lists of two or three floats.

Parameters
geo:dictGeoJSON string multi line or polygon.
isPolygon:bool | NoneBoolean, indicating whether the coordinates describe a polygon.
Returns
boolBoolean, indicating whether the line or polygon is valid.
def validateGeoPoint(self, geo: dict) -> bool:

Validate a GeoJSON point. A point is a list of two or three floats.

Parameters
geo:dictGeoJSON point.
Returns
boolBoolean, indicating whether the point is valid.
def validatePrimitiveContent(self, pc: JSON, elementName: str):

Validate the primitive content.

Parameters
pc:JSONThe primitive content to validate.
elementName:strUndocumented
def validatePvs(self, dct: JSON):

Validating special case for lists that are not allowed to be empty (pvs in ACP).

def validateResourceUpdate(self, resource: Resource, dct: JSON, doValidateAttributes: bool = False):

Validate a resource update dictionary. Besides of the attributes it also validates the resource type.

Parameters
resource:ResourceThe resource to validate the update request for.
dct:JSONThe JSON dictionary of the update request.
doValidateAttributes:boolBoolean indicating whether to validate the attributes.
Returns
None
cnfRegex =

Compiled regular expression that matches a valid contentInfo string.

importer: Importer =

Injected Importer instance.

def _validateType(self, dataType: BasicType, value: Any, convert: bool | None = False, policy: AttributePolicy | None = None) -> tuple[BasicType, Any]:

Check a value for its type.

Parameters
dataType:BasicTypeRequired data type for the value to check against.
value:AnyValue to validate.
convert:bool | NoneIf the convert parameter is True then it is assumed that the value could be a stringified value and the method will attempt to convert the value to its target type; otherwise this is an error.
policy:AttributePolicy | NoneUndocumented
Returns
Result. If the check is positive then a tuple is returned(the determined data type, the converted value).
Raises
BAD_REQUESTIf the validation fails.
_ncNameDisallowedChars: tuple[str, ...] =

Disallowed characters in NCName.

_scheduleRegex =

"second minute hour day month weekday year"

_tokenDisallowedChars: tuple[str, ...] =

Disallowed characters in token.