18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/entitlements/util/override.rb', line 18
def self.override_hash_from_plugin(plugin, group, ldap)
return unless plugin
unless plugin.key?("file")
raise ArgumentError, "plugin configuration hash must contain 'file' key"
end
file = if plugin["file"] !~ %r{/}
File.expand_path(File.join("../plugins", plugin["file"]), File.dirname(__FILE__))
elsif plugin["file"].start_with?("/")
plugin["file"]
else
File.expand_path(plugin["file"], File.dirname(Entitlements.config_file))
end
unless File.file?(file)
raise ArgumentError, "Could not locate plugin for #{plugin['file'].inspect} at #{file.inspect}"
end
unless plugin.key?("class")
raise ArgumentError, "plugin configuration hash must contain 'class' key"
end
require file
clazz = Kernel.const_get("Entitlements::Plugins::#{plugin['class']}")
unless clazz.respond_to?(:loaded?) && clazz.loaded?
raise ArgumentError, "Plugin Entitlements::Plugins::#{plugin['class']} should inherit Entitlements::Plugins"
end
unless clazz.respond_to?(:override_hash)
raise ArgumentError, "Plugin Entitlements::Plugins::#{plugin['class']} must implement override_hash method"
end
override_hash = clazz.override_hash(group, plugin, ldap)
return override_hash if override_hash.is_a?(Hash)
type = override_hash.class
raise ArgumentError, "Plugin Entitlements::Plugins::#{plugin['class']}.override_hash must return hash, not #{type}"
end
|