diff options
Diffstat (limited to 'os-plugins/OpenSLX/OSPlugin/Base.pm')
-rw-r--r-- | os-plugins/OpenSLX/OSPlugin/Base.pm | 40 |
1 files changed, 38 insertions, 2 deletions
diff --git a/os-plugins/OpenSLX/OSPlugin/Base.pm b/os-plugins/OpenSLX/OSPlugin/Base.pm index eee7ae4f..b4a3ad02 100644 --- a/os-plugins/OpenSLX/OSPlugin/Base.pm +++ b/os-plugins/OpenSLX/OSPlugin/Base.pm @@ -172,8 +172,6 @@ sub getAttrInfo Returns a hash-ref with the default attribute values for the given vendor-OS. - - =cut sub getDefaultAttrsForVendorOS @@ -184,6 +182,44 @@ sub getDefaultAttrsForVendorOS return $self->getAttrInfo(); } +=item checkValueForKey() + +Checks if the given value is allowed (and makes sense) for the given key. +If the value is ok, this method returns 1 - if not, it dies with an appropriate +message. + +Plugins may override this implementation to do additional checks that look +at the vendor-OS (stage1-)attributes. + +=cut + +sub checkValueForKey +{ + my $self = shift; + my $key = shift; + my $value = shift; + + # undefined values are always allowed + return 1 if !defined $value; + + # the default implementation checks the value against the regex of the + # attribute (if any) + my $attrInfo + = $self->getAttrInfo()->{$key} + || die _tr('attribute "%s" is unknown!', $key); + + my $regex = $attrInfo->{content_regex}; + return 1 if !$regex; + + return 1 if $value =~ m{$regex}; + + die _tr( + "value given for attribute %s is not allowed.\nAllowed values are: %s", + $key, $attrInfo->{content_descr} + ); +} + + =back =head2 Vendor-OS Interface |