From 2a614b1103699d60e7e2999030d64e2adc9a6955 Mon Sep 17 00:00:00 2001 From: Oliver Tappe Date: Thu, 22 May 2008 20:01:34 +0000 Subject: * attributes set via slxconfig are now being checked not only against the respective regex, but the corresponding plugin is being invoked to do a check of its own, too (where it has the chance to look at the vendor-OS attributes and determine the possible stage3-values from their state). * listing a vendor-OS in verbose mode now shows the vendor-OS attributes (stage1 & stage3), too * used Clone::clone instead of Storable::dclone since the latter is not capable of cloning compiled regexes git-svn-id: http://svn.openslx.org/svn/openslx/openslx/trunk@1783 95ad53e4-c205-0410-b2fa-d234c58c8868 --- config-db/OpenSLX/AttributeRoster.pm | 71 ++++++++++++++++++++++-------------- 1 file changed, 44 insertions(+), 27 deletions(-) (limited to 'config-db/OpenSLX') diff --git a/config-db/OpenSLX/AttributeRoster.pm b/config-db/OpenSLX/AttributeRoster.pm index 331ac70c..13c7640d 100644 --- a/config-db/OpenSLX/AttributeRoster.pm +++ b/config-db/OpenSLX/AttributeRoster.pm @@ -17,6 +17,7 @@ use strict; use warnings; use OpenSLX::Basics; +use OpenSLX::OSPlugin::Engine; use OpenSLX::OSPlugin::Roster; use OpenSLX::Utils; @@ -370,6 +371,8 @@ sub _init # and add all plugin attributes, too OpenSLX::OSPlugin::Roster->addAllStage3AttributesToHash(\%AttributeInfo); + + return 1; } =item C @@ -495,43 +498,57 @@ sub getClientAttrs keys %AttributeInfo } -=item C +=item C -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. +Checks if the given stage3 attribute values are allowed (and make sense). +If all values are ok, this method returns 1 - if not, it dies with an +appropriate message. =cut -sub checkValueForKey +sub checkValues { - my $class = shift; - my $key = shift; - my $value = shift; + my $class = shift; + my $stage3Attrs = shift || {}; + my $vendorOSName = shift or die ('need vendor-OS-name!'); $class->_init() if !%AttributeInfo; - # undefined values are always allowed - return 1 if !defined $value; - - # check the value against the regex of the attribute (if any) - my $attrInfo = $AttributeInfo{$key} - || die _tr('attribute "%s" is unknown!', $key); - my $regex = $attrInfo->{content_regex}; - if ($regex && $value !~ m{$regex}) { - die _tr( - "value given for attribute %s is not allowed.\nAllowed values are: %s", - $key, $attrInfo->{content_descr} - ); + my %attrsByPlugin; + foreach my $key (sort keys %{$stage3Attrs}) { + my $value = $stage3Attrs->{$key}; + if ($key =~ m{^(.+)::.+?$}) { + my $pluginName = $1; + $attrsByPlugin{$pluginName} ||= {}; + $attrsByPlugin{$pluginName}->{$key} = $value; + } + + # undefined values are always allowed + next if !defined $value; + + # check the value against the regex of the attribute (if any) + my $attrInfo = $AttributeInfo{$key} + || die _tr('attribute "%s" is unknown!', $key); + my $regex = $attrInfo->{content_regex}; + if ($regex && $value !~ $regex) { + die _tr( + "the value '%s' for attribute %s is not allowed.\nAllowed values are: %s", + $value, $key, $attrInfo->{content_descr} + ); + } } - # let plugin check by itself - if ($key =~ m{^(.+)::.+?$}) { - my $pluginName = $1; - my $plugin - = OpenSLX::OSPlugin::Roster->getPlugin($pluginName) - || die _tr('unable to load plugin "%s"', $pluginName); - $plugin->checkValueForKey($key, $value); + # now give each plugin a chance to check it's own attributes by itself + foreach my $pluginName (sort keys %attrsByPlugin) { + # create & start OSPlugin-engine for vendor-OS and current plugin + my $engine = OpenSLX::OSPlugin::Engine->new; + $engine->initialize($pluginName, $vendorOSName); + if (!$engine->{'plugin-path'}) { + warn _tr('unable to create engine for plugin "%s"!', $pluginName); + next; + } + $engine->checkStage3AttrValues($attrsByPlugin{$pluginName}); } } + 1; -- cgit v1.2.3-55-g7522