summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOliver Tappe2008-05-20 15:26:55 +0200
committerOliver Tappe2008-05-20 15:26:55 +0200
commitbeab72fc0ec3a6d857f4c64e3d08dcbf9c457c61 (patch)
treebef314bb7d5ac0e9a65748fbece3b7686523f48f
parent* more work at desktop plugin (GDM & KDM should now work on SUSE & Ubuntu) (diff)
downloadcore-beab72fc0ec3a6d857f4c64e3d08dcbf9c457c61.tar.gz
core-beab72fc0ec3a6d857f4c64e3d08dcbf9c457c61.tar.xz
core-beab72fc0ec3a6d857f4c64e3d08dcbf9c457c61.zip
* added support to slxconfig for checking the given attribute values against
their respective regex, an appropriate complaint is shown if the value doesn't match git-svn-id: http://svn.openslx.org/svn/openslx/openslx/trunk@1778 95ad53e4-c205-0410-b2fa-d234c58c8868
-rwxr-xr-xconfig-db/slxconfig7
-rw-r--r--os-plugins/OpenSLX/OSPlugin/Base.pm40
2 files changed, 45 insertions, 2 deletions
diff --git a/config-db/slxconfig b/config-db/slxconfig
index cd3b3ec2..c8c05093 100755
--- a/config-db/slxconfig
+++ b/config-db/slxconfig
@@ -39,6 +39,7 @@ use OpenSLX::AttributeRoster;
use OpenSLX::Basics;
use OpenSLX::ConfigDB;
use OpenSLX::ConfigFolder;
+use OpenSLX::OSPlugin::Roster;
use OpenSLX::Utils;
my %option;
@@ -247,6 +248,12 @@ sub parseKeyValueArgsWithAttrs
if (grep { $_ eq $key } @$allowedKeys) {
$dataHash{$key} = $value;
} elsif (grep { $_ eq $key } @$allowedAttrKeys) {
+ $key =~ m{^(.+)::.+?$};
+ my $pluginName = $1;
+ my $plugin
+ = OpenSLX::OSPlugin::Roster->getPlugin($pluginName)
+ || die _tr('unable to load plugin "%s"', $pluginName);
+ $plugin->checkValueForKey($key, $value);
$attrHash{$key} = $value;
} else {
die _tr("unknown key '%s' specified for %s\n", $key, $table);
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