From 34af261b7928ba7d62496d2d87fbe64b1badc930 Mon Sep 17 00:00:00 2001 From: Anton Aksola Date: Fri, 2 May 2014 12:51:20 +0300 Subject: Introduce group level configuration for auth For rancid-like behaviour one can now set username and password for node groups. These parameters are considered in the following order: 1) node parameters (from source) 2) group level parameters 3) global level parameters example configuration for group 'testlab' groups: testlab: username: testuser password: testpassword --- lib/oxidized/node.rb | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/oxidized/node.rb b/lib/oxidized/node.rb index 3ac1c90..fce4c21 100644 --- a/lib/oxidized/node.rb +++ b/lib/oxidized/node.rb @@ -99,9 +99,19 @@ module Oxidized end def resolve_auth opt + # Resolve configured username/password, give priority to group level configuration + # TODO: refactor to use revised behaviour of Asetus + cfg_username, cfg_password = + if CFG.groups.has_key?(@group) and ['username', 'password'].all? {|e| CFG.groups[@group].has_key?(e)} + [CFG.groups[@group].username, CFG.groups[@group].password] + elsif ['username', 'password'].all? {|e| CFG.has_key?(e)} + [CFG.username, CFG.password] + else + [nil, nil] + end auth = {} - auth[:username] = (opt[:username] or CFG.username) - auth[:password] = (opt[:passowrd] or CFG.password) + auth[:username] = (opt[:username] or cfg_username) + auth[:password] = (opt[:password] or cfg_password) auth end -- cgit v1.2.1