Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Validate configuration attributes

  • Loading branch information...
commit 1b7362a7c4f8ef1a1b15035af8936f405c99716c 1 parent 6dc6c7d
@sosedoff authored
View
1  lib/lxc.rb
@@ -1,6 +1,7 @@
require 'lxc/version'
require 'lxc/errors'
require 'lxc/shell'
+require 'lxc/configuration_options'
require 'lxc/configuration'
require 'lxc/container'
View
5 lib/lxc/configuration.rb
@@ -1,5 +1,7 @@
module LXC
class Configuration
+ include LXC::ConfigurationOptions
+
attr_reader :content
# Initialize a new LXC::Configuration instance
@@ -61,6 +63,9 @@ def parse(data)
lines = data.split("\n").map(&:strip).select { |l| !l.empty? && l[0,1] != '#' }
lines.each do |l|
key,value = l.split('=').map(&:strip)
+ if !valid_option?(key)
+ raise ConfigurationError, "Invalid config attribute: #{key}."
+ end
key.gsub!(/^lxc\./, '').gsub!('.', '_')
hash[key] = [] if !hash.key?(key)
hash[key] << value
View
27 lib/lxc/configuration_options.rb
@@ -0,0 +1,27 @@
+module LXC
+ module ConfigurationOptions
+ VALID_OPTIONS = [
+ 'lxc.utsname',
+ 'lxc.network.type',
+ 'lxc.network.flags',
+ 'lxc.network.link',
+ 'lxc.network.name',
+ 'lxc.network.hwaddr',
+ 'lxc.network.ipv4',
+ 'lxc.network.ipv6',
+ 'lxc.pts',
+ 'lxc.tty',
+ 'lxc.mount',
+ 'lxc.mount.entry',
+ 'lxc.rootfs',
+ 'lxc.cgroup',
+ 'lxc.cap.drop'
+ ]
+
+ protected
+
+ def valid_option?(name)
+ VALID_OPTIONS.include?(name) || name =~ /^lxc.cgroup/
+ end
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.