Class: ConcertoConfigServer
- Inherits:
-
Sinatra::Base
- Object
- Sinatra::Base
- ConcertoConfigServer
- Defined in:
- lib/concerto_client/application/app.rb
Constant Summary collapse
- CONNECTION_METHODS =
push these over to netconfig.rb? Our list of available physical-layer connection methods…
[ ConcertoConfig::WiredConnection, ConcertoConfig::WirelessConnection ]
- ADDRESSING_METHODS =
… and available layer-3 addressing methods.
[ ConcertoConfig::DHCPAddressing, ConcertoConfig::StaticAddressing ]
- LOCALHOSTS =
Hosts we allow to access configuration without authenticating.
[ IPAddress.parse("127.0.0.1"), IPAddress.parse("::1") ]
Instance Method Summary collapse
-
#do_assign(params, instance) ⇒ Object
Set the arguments on an instance of a given configuration class.
-
#extract_class_args(params, target_class) ⇒ Object
Extract arguments from a set of form data that are intended to go to a specific network configuration class.
-
#pick_class(name, list) ⇒ Object
Given the name of a class, pick a class out of a list of allowed classes.
Instance Method Details
#do_assign(params, instance) ⇒ Object
Set the arguments on an instance of a given configuration class. This uses the safe_assign method that should be present in all configuration classes to determine which values are allowed to be passed via form fields (i.e. which ones are subject to validation)
232 233 234 235 236 237 238 239 240 |
# File 'lib/concerto_client/application/app.rb', line 232 def do_assign(params, instance) safe = instance.safe_assign params.each do |param, value| if safe.include? param.intern instance.send((param + '=').intern, value) end end end |
#extract_class_args(params, target_class) ⇒ Object
Extract arguments from a set of form data that are intended to go to a specific network configuration class. These fields have names of the form ‘ClassName/field_name’; this function returns a hash in the form { ‘field_name’ => ‘value } containing the configuration arguments.
216 217 218 219 220 221 222 223 224 225 226 |
# File 'lib/concerto_client/application/app.rb', line 216 def extract_class_args(params, target_class) result = { } params.each do |key, value| klass, arg = key.split('/', 2) if klass == target_class result[arg] = value end end result end |
#pick_class(name, list) ⇒ Object
Given the name of a class, pick a class out of a list of allowed classes. This is used for parsing the form input for network configuration.
208 209 210 |
# File 'lib/concerto_client/application/app.rb', line 208 def pick_class(name, list) list.find { |klass| klass.basename == name } end |